1
0
Fork 0

optimization for recovery of collections that are going to be dropped anyway

This commit is contained in:
Jan Steemann 2014-09-18 18:20:56 +02:00
parent 2fe6d8f554
commit 1fff0ecac2
8 changed files with 49 additions and 17 deletions

View File

@ -555,8 +555,8 @@ int ContinuousSyncer::changeCollection (TRI_json_t const* json) {
TRI_json_t const* collectionJson = TRI_LookupArrayJson(json, "collection");
bool waitForSync = JsonHelper::getBooleanValue(collectionJson, "waitForSync", false);
bool doCompact = JsonHelper::getBooleanValue(collectionJson, "doCompact", true);
int maximalSize = JsonHelper::getNumericValue<int>(collectionJson, "maximalSize", TRI_JOURNAL_DEFAULT_MAXIMAL_SIZE);
bool doCompact = JsonHelper::getBooleanValue(collectionJson, "doCompact", true);
int maximalSize = JsonHelper::getNumericValue<int>(collectionJson, "maximalSize", TRI_JOURNAL_DEFAULT_MAXIMAL_SIZE);
TRI_voc_cid_t cid = getCid(json);
TRI_vocbase_col_t* col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
@ -575,7 +575,8 @@ int ContinuousSyncer::changeCollection (TRI_json_t const* json) {
parameters._maximalSize = maximalSize;
parameters._waitForSync = waitForSync;
return TRI_UpdateCollectionInfo(_vocbase, guard.collection()->_collection, &parameters);
bool doSync = _vocbase->_settings.forceSyncProperties;
return TRI_UpdateCollectionInfo(_vocbase, guard.collection()->_collection, &parameters, doSync);
}
catch (triagens::arango::Exception const& ex) {
return ex.code();

View File

@ -2211,7 +2211,8 @@ static v8::Handle<v8::Value> JS_PropertiesVocbaseCol (v8::Arguments const& argv)
newParameter._waitForSync = waitForSync;
// try to write new parameter to file
int res = TRI_UpdateCollectionInfo(base->_vocbase, base, &newParameter);
bool doSync = base->_vocbase->_settings.forceSyncProperties;
int res = TRI_UpdateCollectionInfo(base->_vocbase, base, &newParameter, doSync);
if (res != TRI_ERROR_NO_ERROR) {
ReleaseCollection(collection);

View File

@ -1374,7 +1374,8 @@ int TRI_SaveCollectionInfo (char const* path,
int TRI_UpdateCollectionInfo (TRI_vocbase_t* vocbase,
TRI_collection_t* collection,
TRI_col_info_t const* parameter) {
TRI_col_info_t const* parameter,
bool doSync) {
TRI_LOCK_JOURNAL_ENTRIES_DOC_COLLECTION((TRI_document_collection_t*) collection);
@ -1395,7 +1396,7 @@ int TRI_UpdateCollectionInfo (TRI_vocbase_t* vocbase,
TRI_UNLOCK_JOURNAL_ENTRIES_DOC_COLLECTION((TRI_document_collection_t*) collection);
return TRI_SaveCollectionInfo(collection->_directory, &collection->_info, vocbase->_settings.forceSyncProperties);
return TRI_SaveCollectionInfo(collection->_directory, &collection->_info, doSync);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -340,7 +340,8 @@ int TRI_SaveCollectionInfo (char const*,
int TRI_UpdateCollectionInfo (TRI_vocbase_t*,
TRI_collection_t*,
TRI_col_info_t const*);
TRI_col_info_t const*,
bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief renames a collection

View File

@ -2188,7 +2188,8 @@ TRI_document_collection_t* TRI_CreateDocumentCollection (TRI_vocbase_t* vocbase,
document->_keyGenerator = keyGenerator;
// save the parameter block (within create, no need to lock)
int res = TRI_SaveCollectionInfo(collection->_directory, parameters, vocbase->_settings.forceSyncProperties);
bool doSync = vocbase->_settings.forceSyncProperties;
int res = TRI_SaveCollectionInfo(collection->_directory, parameters, doSync);
if (res != TRI_ERROR_NO_ERROR) {
// TODO: shouldn't we destroy &document->_allIndexes, free document->_headersPtr etc.?

View File

@ -2008,7 +2008,8 @@ int TRI_DropCollectionVocBase (TRI_vocbase_t* vocbase,
TRI_ASSERT(collection != nullptr);
if (! collection->_canDrop && ! triagens::wal::LogfileManager::instance()->isInRecovery()) {
if (! collection->_canDrop &&
! triagens::wal::LogfileManager::instance()->isInRecovery()) {
return TRI_set_errno(TRI_ERROR_FORBIDDEN);
}
@ -2111,8 +2112,11 @@ int TRI_DropCollectionVocBase (TRI_vocbase_t* vocbase,
else if (collection->_status == TRI_VOC_COL_STATUS_LOADED || collection->_status == TRI_VOC_COL_STATUS_UNLOADING) {
collection->_collection->_info._deleted = true;
bool doSync = (vocbase->_settings.forceSyncProperties &&
! triagens::wal::LogfileManager::instance()->isInRecovery());
int res = TRI_UpdateCollectionInfo(vocbase, collection->_collection, nullptr);
int res = TRI_UpdateCollectionInfo(vocbase, collection->_collection, nullptr, doSync);
if (res != TRI_ERROR_NO_ERROR) {
TRI_WRITE_UNLOCK_STATUS_VOCBASE_COL(collection);

View File

@ -637,14 +637,16 @@ bool RecoverState::InitialScanMarker (TRI_df_marker_t const* marker,
// -----------------------------------------------------------------------------
// drop markers
// -----------------------------------------------------------------------------
*/
case TRI_WAL_MARKER_DROP_COLLECTION: {
collection_drop_marker_t const* m = reinterpret_cast<collection_drop_marker_t const*>(marker);
// note that the collection was dropped and doesn't need to be recovered
state->droppedCollections.insert(m->_collectionId);
state->droppedIds.insert(m->_collectionId);
break;
}
/*
case TRI_WAL_MARKER_DROP_DATABASE: {
database_drop_marker_t const* m = reinterpret_cast<database_drop_marker_t const*>(marker);
// note that the database was dropped and doesn't need to be recovered
@ -1130,7 +1132,7 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker,
parameters._maximalSize = static_cast<TRI_voc_size_t>(value->_value._number);
}
int res = TRI_UpdateCollectionInfo(vocbase, document, &parameters);
int res = TRI_UpdateCollectionInfo(vocbase, document, &parameters, vocbase->_settings.forceSyncProperties);
if (res != TRI_ERROR_NO_ERROR) {
LOG_WARNING("cannot change collection properties for collection %llu in database %llu: %s",
@ -1212,7 +1214,7 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker,
char* filename = TRI_Concatenate2File(collectionDirectory.c_str(), indexName);
TRI_FreeString(TRI_CORE_MEM_ZONE, indexName);
bool ok = TRI_SaveJson(filename, json, true);
bool ok = TRI_SaveJson(filename, json, vocbase->_settings.forceSyncProperties);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
if (! ok) {
@ -1303,7 +1305,19 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker,
triagens::arango::TransactionBase trx(true);
WaitForDeletion(vocbase, collectionId, TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
collection = TRI_CreateCollectionVocBase(vocbase, &info, collectionId, false);
if (state->willBeDropped(collectionId)) {
// in case we detect that this collection is going to be deleted anyway, set
// the sync properties to false temporarily
bool oldSync = vocbase->_settings.forceSyncProperties;
vocbase->_settings.forceSyncProperties = false;
collection = TRI_CreateCollectionVocBase(vocbase, &info, collectionId, false);
vocbase->_settings.forceSyncProperties = oldSync;
}
else {
collection = TRI_CreateCollectionVocBase(vocbase, &info, collectionId, false);
}
TRI_FreeCollectionInfoOptions(&info);
@ -1491,7 +1505,7 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker,
////////////////////////////////////////////////////////////////////////////////
int RecoverState::replayLogfile (Logfile* logfile) {
LOG_TRACE("replaying logfile '%s'", logfile->filename().c_str());
LOG_INFO("replaying WAL logfile '%s'", logfile->filename().c_str());
if (! TRI_IterateDatafile(logfile->df(), &RecoverState::ReplayMarker, static_cast<void*>(this))) {
LOG_WARNING("WAL inspection failed when scanning logfile '%s'", logfile->filename().c_str());

View File

@ -93,6 +93,14 @@ namespace triagens {
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief checks if there will be a drop marker for the collection
////////////////////////////////////////////////////////////////////////////////
bool willBeDropped (TRI_voc_cid_t collectionId) const {
return (droppedIds.find(collectionId) != droppedIds.end());
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks if a database is dropped already
////////////////////////////////////////////////////////////////////////////////
@ -300,6 +308,7 @@ namespace triagens {
std::unordered_set<TRI_voc_tick_t> remoteTransactionDatabases;
std::unordered_set<TRI_voc_cid_t> droppedCollections;
std::unordered_set<TRI_voc_tick_t> droppedDatabases;
std::unordered_set<TRI_voc_cid_t> droppedIds;
TRI_voc_tick_t lastTick;
std::vector<Logfile*> logfilesToProcess;