1
0
Fork 0

object lock

This commit is contained in:
Jan Steemann 2013-07-01 17:55:09 +02:00
parent b718365504
commit cfd1551f51
2 changed files with 171 additions and 80 deletions

View File

@ -3879,16 +3879,25 @@ TRI_vector_pointer_t* TRI_IndexesDocumentCollection (TRI_document_collection_t*
bool TRI_DropIndexDocumentCollection (TRI_document_collection_t* document, bool TRI_DropIndexDocumentCollection (TRI_document_collection_t* document,
TRI_idx_iid_t iid) { TRI_idx_iid_t iid) {
TRI_index_t* found; TRI_index_t* found;
TRI_vocbase_t* vocbase;
TRI_primary_collection_t* primary; TRI_primary_collection_t* primary;
size_t i, n; size_t i, n;
if (iid == 0) { if (iid == 0) {
// invalid index id or primary index
return true; return true;
} }
found = NULL; found = NULL;
primary = &document->base; primary = &document->base;
vocbase = primary->base._vocbase;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// inside write-lock // inside write-lock
// ............................................................................. // .............................................................................
@ -3922,6 +3931,10 @@ bool TRI_DropIndexDocumentCollection (TRI_document_collection_t* document,
TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary); TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadUnlockReadWriteLock(&vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// outside write-lock // outside write-lock
// ............................................................................. // .............................................................................
@ -4182,6 +4195,10 @@ TRI_index_t* TRI_EnsureCapConstraintDocumentCollection (TRI_document_collection_
// inside write-lock // inside write-lock
// ............................................................................. // .............................................................................
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary); TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
idx = CreateCapConstraintDocumentCollection(document, count, size, 0, created); idx = CreateCapConstraintDocumentCollection(document, count, size, 0, created);
@ -4192,17 +4209,21 @@ TRI_index_t* TRI_EnsureCapConstraintDocumentCollection (TRI_document_collection_
// outside write-lock // outside write-lock
// ............................................................................. // .............................................................................
if (idx == NULL) { if (idx != NULL) {
return NULL; if (created) {
int res;
res = TRI_SaveIndex(primary, idx);
if (res != TRI_ERROR_NO_ERROR) {
idx = NULL;
}
}
} }
if (created) { #ifdef TRI_ENABLE_REPLICATION
int res; TRI_ReadUnlockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
res = TRI_SaveIndex(primary, idx);
return res == TRI_ERROR_NO_ERROR ? idx : NULL;
}
return idx; return idx;
} }
@ -4558,6 +4579,10 @@ TRI_index_t* TRI_EnsureGeoIndex1DocumentCollection (TRI_document_collection_t* d
primary = &document->base; primary = &document->base;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// inside write-lock // inside write-lock
// ............................................................................. // .............................................................................
@ -4572,17 +4597,21 @@ TRI_index_t* TRI_EnsureGeoIndex1DocumentCollection (TRI_document_collection_t* d
// outside write-lock // outside write-lock
// ............................................................................. // .............................................................................
if (idx == NULL) { if (idx != NULL) {
return NULL; if (created) {
int res;
res = TRI_SaveIndex(primary, idx);
if (res != TRI_ERROR_NO_ERROR) {
idx = NULL;
}
}
} }
if (created) { #ifdef TRI_ENABLE_REPLICATION
int res; TRI_ReadUnlockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
res = TRI_SaveIndex(primary, idx);
return res == TRI_ERROR_NO_ERROR ? idx : NULL;
}
return idx; return idx;
} }
@ -4602,6 +4631,10 @@ TRI_index_t* TRI_EnsureGeoIndex2DocumentCollection (TRI_document_collection_t* d
primary = &document->base; primary = &document->base;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// inside write-lock // inside write-lock
// ............................................................................. // .............................................................................
@ -4616,17 +4649,21 @@ TRI_index_t* TRI_EnsureGeoIndex2DocumentCollection (TRI_document_collection_t* d
// outside write-lock // outside write-lock
// ............................................................................. // .............................................................................
if (idx == NULL) { if (idx != NULL) {
return NULL; if (created) {
int res;
res = TRI_SaveIndex(primary, idx);
if (res != TRI_ERROR_NO_ERROR) {
idx = NULL;
}
}
} }
if (created) { #ifdef TRI_ENABLE_REPLICATION
int res; TRI_ReadUnlockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
res = TRI_SaveIndex(primary, idx);
return res == TRI_ERROR_NO_ERROR ? idx : NULL;
}
return idx; return idx;
} }
@ -4817,6 +4854,10 @@ TRI_index_t* TRI_EnsureHashIndexDocumentCollection (TRI_document_collection_t* d
primary = &document->base; primary = &document->base;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// inside write-lock // inside write-lock
// ............................................................................. // .............................................................................
@ -4832,17 +4873,21 @@ TRI_index_t* TRI_EnsureHashIndexDocumentCollection (TRI_document_collection_t* d
// outside write-lock // outside write-lock
// ............................................................................. // .............................................................................
if (idx == NULL) { if (idx != NULL) {
return NULL; if (created) {
int res;
res = TRI_SaveIndex(primary, idx);
if (res != TRI_ERROR_NO_ERROR) {
idx = NULL;
}
}
} }
if (created) { #ifdef TRI_ENABLE_REPLICATION
int res; TRI_ReadUnlockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
res = TRI_SaveIndex(primary, idx);
return res == TRI_ERROR_NO_ERROR ? idx : NULL;
}
return idx; return idx;
} }
@ -5025,6 +5070,10 @@ TRI_index_t* TRI_EnsureSkiplistIndexDocumentCollection (TRI_document_collection_
primary = &document->base; primary = &document->base;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// inside write-lock the collection // inside write-lock the collection
// ............................................................................. // .............................................................................
@ -5039,17 +5088,21 @@ TRI_index_t* TRI_EnsureSkiplistIndexDocumentCollection (TRI_document_collection_
// outside write-lock // outside write-lock
// ............................................................................. // .............................................................................
if (idx == NULL) { if (idx != NULL) {
return NULL; if (created) {
int res;
res = TRI_SaveIndex(primary, idx);
if (res != TRI_ERROR_NO_ERROR) {
idx = NULL;
}
}
} }
if (created) { #ifdef TRI_ENABLE_REPLICATION
int res; TRI_ReadUnlockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
res = TRI_SaveIndex(primary, idx);
return res == TRI_ERROR_NO_ERROR ? idx : NULL;
}
return idx; return idx;
} }
@ -5286,6 +5339,10 @@ TRI_index_t* TRI_EnsureFulltextIndexDocumentCollection (TRI_document_collection_
primary = &document->base; primary = &document->base;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// inside write-lock the collection // inside write-lock the collection
// ............................................................................. // .............................................................................
@ -5300,17 +5357,21 @@ TRI_index_t* TRI_EnsureFulltextIndexDocumentCollection (TRI_document_collection_
// outside write-lock // outside write-lock
// ............................................................................. // .............................................................................
if (idx == NULL) { if (idx != NULL) {
return NULL; if (created) {
int res;
res = TRI_SaveIndex(primary, idx);
if (res != TRI_ERROR_NO_ERROR) {
idx = NULL;
}
}
} }
if (created) { #ifdef TRI_ENABLE_REPLICATION
int res; TRI_ReadUnlockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
res = TRI_SaveIndex(primary, idx);
return res == TRI_ERROR_NO_ERROR ? idx : NULL;
}
return idx; return idx;
} }
@ -5530,6 +5591,10 @@ TRI_index_t* TRI_EnsurePriorityQueueIndexDocumentCollection(TRI_document_collect
primary = &document->base; primary = &document->base;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// inside write-lock // inside write-lock
// ............................................................................. // .............................................................................
@ -5545,17 +5610,21 @@ TRI_index_t* TRI_EnsurePriorityQueueIndexDocumentCollection(TRI_document_collect
// outside write-lock // outside write-lock
// ............................................................................. // .............................................................................
if (idx == NULL) { if (idx != NULL) {
return NULL; if (created) {
int res;
res = TRI_SaveIndex(primary, idx);
if (res != TRI_ERROR_NO_ERROR) {
idx = NULL;
}
}
} }
if (created) { #ifdef TRI_ENABLE_REPLICATION
int res; TRI_ReadUnlockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
res = TRI_SaveIndex(primary, idx);
return res == TRI_ERROR_NO_ERROR ? idx : NULL;
}
return idx; return idx;
} }
@ -5805,6 +5874,10 @@ TRI_index_t* TRI_EnsureBitarrayIndexDocumentCollection (TRI_document_collection_
*errorCode = TRI_ERROR_NO_ERROR; *errorCode = TRI_ERROR_NO_ERROR;
*errorStr = NULL; *errorStr = NULL;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// inside write-lock the collection // inside write-lock the collection
// ............................................................................. // .............................................................................
@ -5824,29 +5897,29 @@ TRI_index_t* TRI_EnsureBitarrayIndexDocumentCollection (TRI_document_collection_
// The index is 'new' so save it // The index is 'new' so save it
// ............................................................................. // .............................................................................
if (idx == NULL) { if (idx != NULL) {
return NULL; if (created) {
} int res;
if (created) { res = TRI_SaveIndex(primary, idx);
int res;
res = TRI_SaveIndex(primary, idx); // ...........................................................................
// If index could not be saved, report the error and return NULL
// TODO: get TRI_SaveIndex to report the error
// ...........................................................................
// ........................................................................... if (res != TRI_ERROR_NO_ERROR) {
// If index could not be saved, report the error and return NULL idx = NULL;
// TODO: get TRI_SaveIndex to report the error *errorCode = res;
// ........................................................................... *errorStr = TRI_DuplicateString("Bitarray index could not be saved.");
}
if (res == TRI_ERROR_NO_ERROR) {
return idx;
} }
*errorCode = res;
*errorStr = TRI_DuplicateString("Bitarray index could not be saved.");
return NULL;
} }
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadUnlockReadWriteLock(&primary->base._vocbase->_objectLock);
#endif
// ............................................................................. // .............................................................................
// Index already exists so simply return it // Index already exists so simply return it
// ............................................................................. // .............................................................................

View File

@ -1147,8 +1147,16 @@ static int LoadCollectionVocBase (TRI_vocbase_t* vocbase,
if (TRI_IS_DOCUMENT_COLLECTION(type)) { if (TRI_IS_DOCUMENT_COLLECTION(type)) {
TRI_document_collection_t* document; TRI_document_collection_t* document;
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadLockReadWriteLock(&vocbase->_objectLock);
#endif
document = TRI_OpenDocumentCollection(vocbase, collection->_path); document = TRI_OpenDocumentCollection(vocbase, collection->_path);
#ifdef TRI_ENABLE_REPLICATION
TRI_ReadUnlockReadWriteLock(&vocbase->_objectLock);
#endif
if (document == NULL) { if (document == NULL) {
collection->_status = TRI_VOC_COL_STATUS_CORRUPTED; collection->_status = TRI_VOC_COL_STATUS_CORRUPTED;
@ -1736,6 +1744,8 @@ TRI_vector_pointer_t TRI_CollectionsVocBase (TRI_vocbase_t* vocbase) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief returns all known (document) collections with their parameters /// @brief returns all known (document) collections with their parameters
/// while the collections are iterated over, there will be a global lock so
/// that there will be consistent view of collections & their properties
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_ParametersCollectionsVocBase (TRI_vocbase_t* vocbase, TRI_json_t* TRI_ParametersCollectionsVocBase (TRI_vocbase_t* vocbase,
@ -1753,6 +1763,10 @@ TRI_json_t* TRI_ParametersCollectionsVocBase (TRI_vocbase_t* vocbase,
TRI_InitVectorPointer(&collections, TRI_CORE_MEM_ZONE); TRI_InitVectorPointer(&collections, TRI_CORE_MEM_ZONE);
#ifdef TRI_ENABLE_REPLICATION
TRI_WriteLockReadWriteLock(&vocbase->_objectLock);
#endif
// copy collection pointers into vector so we can work with the copy without // copy collection pointers into vector so we can work with the copy without
// the global lock // the global lock
TRI_READ_LOCK_COLLECTIONS_VOCBASE(vocbase); TRI_READ_LOCK_COLLECTIONS_VOCBASE(vocbase);
@ -1798,6 +1812,10 @@ TRI_json_t* TRI_ParametersCollectionsVocBase (TRI_vocbase_t* vocbase,
TRI_READ_UNLOCK_STATUS_VOCBASE_COL(collection); TRI_READ_UNLOCK_STATUS_VOCBASE_COL(collection);
} }
#ifdef TRI_ENABLE_REPLICATION
TRI_WriteUnlockReadWriteLock(&vocbase->_objectLock);
#endif
TRI_DestroyVectorPointer(&collections); TRI_DestroyVectorPointer(&collections);
return json; return json;