From 4e7f56a53245d13f5f476506b00f45c1f9d9a0da Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 22 Oct 2018 16:44:21 +0200 Subject: [PATCH] attempt to fix truncation (#7002) --- arangod/RocksDBEngine/RocksDBCollection.cpp | 1 + .../RocksDBEngine/RocksDBRecoveryManager.cpp | 37 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/arangod/RocksDBEngine/RocksDBCollection.cpp b/arangod/RocksDBEngine/RocksDBCollection.cpp index 335f325a46..d480ca16af 100644 --- a/arangod/RocksDBEngine/RocksDBCollection.cpp +++ b/arangod/RocksDBEngine/RocksDBCollection.cpp @@ -691,6 +691,7 @@ Result RocksDBCollection::truncate(transaction::Methods* trx, RocksDBSettingsManager::CounterAdjustment update(seq, /*numInserts*/0, /*numRemoves*/numDocs, /*revision*/0); engine->settingsManager()->updateCounter(_objectId, update); + if (numDocs > 64 * 1024) { // also compact the ranges in order to speed up all further accesses compact(); diff --git a/arangod/RocksDBEngine/RocksDBRecoveryManager.cpp b/arangod/RocksDBEngine/RocksDBRecoveryManager.cpp index ac940bc309..323f96d1b8 100644 --- a/arangod/RocksDBEngine/RocksDBRecoveryManager.cpp +++ b/arangod/RocksDBEngine/RocksDBRecoveryManager.cpp @@ -282,6 +282,34 @@ class WBReader final : public rocksdb::WriteBatch::Handler { (*it).second = keyValue; } } + + bool truncateIndexes(uint64_t objectId) { + RocksDBEngine* engine = + static_cast(EngineSelectorFeature::ENGINE); + RocksDBEngine::CollectionPair pair = engine->mapObjectToCollection(objectId); + if (pair.first == 0 || pair.second == 0) { + return false; + } + + DatabaseFeature* df = DatabaseFeature::DATABASE; + TRI_vocbase_t* vb = df->useDatabase(pair.first); + if (vb == nullptr) { + return false; + } + TRI_DEFER(vb->release()); + + auto coll = vb->lookupCollection(pair.second); + + if (coll == nullptr) { + return false; + } + + for (auto const& idx : coll->getIndexes()) { + idx->afterTruncate(); + } + + return true; + } RocksDBCuckooIndexEstimator* findEstimator(uint64_t objectId) { RocksDBEngine* engine = @@ -505,10 +533,11 @@ class WBReader final : public rocksdb::WriteBatch::Handler { ops->removed = 0; ops->added = 0; ops->mustTruncate = true; - auto est = findEstimator(objectId); - if (est != nullptr && est->commitSeq() < currentSeqNum) { - // We track estimates for this index - est->bufferTruncate(currentSeqNum + 1); + + if (!truncateIndexes(objectId)) { + // unable to truncate indexes of the collection. + // may be due to collection having been deleted etc. + LOG_TOPIC(DEBUG, Logger::ENGINES) << "unable to truncate indexes for objectId " << objectId; } }