//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2017 ArangoDB GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Simon Grätzer //////////////////////////////////////////////////////////////////////////////// #include "RocksDBBackgroundThread.h" #include "Basics/ConditionLocker.h" #include "RestServer/DatabaseFeature.h" #include "RocksDBEngine/RocksDBCounterManager.h" #include "RocksDBEngine/RocksDBEngine.h" #include "RocksDBEngine/RocksDBReplicationManager.h" #include "Utils/CursorRepository.h" using namespace arangodb; RocksDBBackgroundThread::RocksDBBackgroundThread(RocksDBEngine* eng, double interval) : Thread("RocksDBThread"), _engine(eng), _interval(interval) {} RocksDBBackgroundThread::~RocksDBBackgroundThread() { shutdown(); } void RocksDBBackgroundThread::beginShutdown() { Thread::beginShutdown(); // wake up the thread that may be waiting in run() CONDITION_LOCKER(guard, _condition); guard.broadcast(); } void RocksDBBackgroundThread::run() { while (!isStopping()) { { CONDITION_LOCKER(guard, _condition); guard.wait(static_cast(_interval * 1000000.0)); } if (!isStopping()) { _engine->counterManager()->sync(false); } bool force = isStopping(); _engine->replicationManager()->garbageCollect(force); if (!isStopping()) { DatabaseFeature::DATABASE->enumerateDatabases( [force](TRI_vocbase_t* vocbase) { vocbase->cursorRepository()->garbageCollect(force); }); } } _engine->counterManager()->sync(true); // final write on shutdown }