8000 avoid deadlocking between synchroniser, compactor and data modificati… · arangodb/arangodb@fc1fed6 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc1fed6

Browse files
committed
avoid deadlocking between synchroniser, compactor and data modification threads (e.g. POST /_api/document)
1 parent 7c8bb3d commit fc1fed6

File tree

6 files changed

+57
-7
lines changed

6 files changed

+57
-7
lines changed

arangod/Voc 8000 Base/compactor.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,13 @@ static void CompactifySimCollection (TRI_sim_collection_t* sim) {
404404
size_t n;
405405
size_t i;
406406

407+
if (! TRI_TRY_READ_LOCK_DATAFILES_SIM_COLLECTION(sim)) {
408+
return;
409+
}
410+
407411
TRI_InitVector(&vector, TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_doc_datafile_info_t));
408412

409413
// copy datafile information
410-
TRI_READ_LOCK_DATAFILES_SIM_COLLECTION(sim);
411-
412414
n = sim->base.base._datafiles._length;
413415

414416
for (i = 0; i < n; ++i) {

arangod/VocBase/simple-collection.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ extern "C" {
5252
/// @{
5353
////////////////////////////////////////////////////////////////////////////////
5454

55+
////////////////////////////////////////////////////////////////////////////////
56+
/// @brief tries to read lock the journal files and the parameter file
57+
////////////////////////////////////////////////////////////////////////////////
58+
59+
#define TRI_TRY_READ_LOCK_DATAFILES_SIM_COLLECTION(a) \
60+
TRI_TryReadLockReadWriteLock(&(a)->_lock)
61+
5562
////////////////////////////////////////////////////////////////////////////////
5663
/// @brief read locks the journal files and the parameter file
5764
////////////////////////////////////////////////////////////////////////////////

arangod/VocBase/synchroniser.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static bool CheckJournalSimCollection (TRI_sim_collection_t* sim) {
138138
bool worked;
139139
size_t i;
140140
size_t n;
141-
141+
142142
worked = false;
143143
base = &sim->base.base;
144144

@@ -205,7 +205,7 @@ static bool CheckSyncCompactorSimCollection (TRI_sim_collection_t* sim) {
205205
double ti;
206206
size_t i;
207207
size_t n;
208-
208+
209209
worked = false;
210210
base = &sim->base.base;
211211

@@ -266,7 +266,7 @@ static bool CheckCompactorSimCollection (TRI_sim_collection_t* sim) {
266266
bool worked;
267267
size_t i;
268268
size_t n;
269-
269+
270270
worked = false;
271271
base = &sim->base.base;
272272

@@ -365,8 +365,10 @@ void TRI_SynchroniserVocBase (void* data) {
365365
bool result;
366366

367367
collection = collections._buffer[i];
368-
369-
TRI_READ_LOCK_STATUS_VOCBASE_COL(collection);
368+
369+
if (! TRI_TRY_READ_LOCK_DATAFILES_SIM_COLLECTION(collection)) {
370+
continue;
371+
}
370372

371373
if (collection->_status != TRI_VOC_COL_STATUS_LOADED) {
372374
TRI_READ_UNLOCK_STATUS_VOCBASE_COL(collection);

lib/BasicsC/locks-posix.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ void TRI_DestroyReadWriteLock (TRI_read_write_lock_t* lock) {
229229
/// @{
230230
////////////////////////////////////////////////////////////////////////////////
231231

232+
////////////////////////////////////////////////////////////////////////////////
233+
/// @brief tries to read lock read-write lock
234+
////////////////////////////////////////////////////////////////////////////////
235+
236+
bool TRI_TryReadLockReadWriteLock (TRI_read_write_lock_t* lock) {
237+
int rc;
238+
239+
rc = pthread_rwlock_tryrdlock(lock);
240+
241+
return (rc == 0);
242+
}
243+
232244
////////////////////////////////////////////////////////////////////////////////
233245
/// @brief read locks read-write lock
234246
////////////////////////////////////////////////////////////////////////////////

lib/BasicsC/locks-win32.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,27 @@ static void DecrementReaders (TRI_read_write_lock_t* lock) {
266266
/// @{
267267
////////////////////////////////////////////////////////////////////////////////
268268

269+
////////////////////////////////////////////////////////////////////////////////
270+
/// @brief tries to read lock a read-write lock
271+
////////////////////////////////////////////////////////////////////////////////
272+
273+
bool TRI_TryReadLockReadWriteLock (TRI_read_write_lock_t* lock) {
274+
WaitForSingleObject(lock->_writerEvent, 10); // 10 millis timeout
275+
276+
EnterCriticalSection(&lock->_lockReaders);
277+
IncrementReaders(lock);
278+
LeaveCriticalSection(&lock->_lockReaders);
279+
280+
if (WaitForSingleObject(lock->_writerEvent, 0) != WAIT_OBJECT_0) {
281+
EnterCriticalSection(&lock->_lockReaders);
282+
DecrementReaders(lock);
283+
LeaveCriticalSection(&lock->_lockReaders);
284+
return false;
285+
}
286+
287+
return true;
288+
}
289+
269290
////////////////////////////////////////////////////////////////////////////////
270291
/// @brief read locks read-write lock
271292
////////////////////////////////////////////////////////////////////////////////

lib/BasicsC/locks.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ void TRI_DestroyReadWriteLock (TRI_read_write_lock_t* lock);
228228
/// @{
229229
////////////////////////////////////////////////////////////////////////////////
230230

231+
////////////////////////////////////////////////////////////////////////////////
232+
/// @brief tries to read lock read-write lock
233+
////////////////////////////////////////////////////////////////////////////////
234+
235+
bool TRI_TryReadLockReadWriteLock (TRI_read_write_lock_t* lock);
236+
231237
////////////////////////////////////////////////////////////////////////////////
232238
/// @brief read locks read-write lock
233239
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)
0