1
0
Fork 0

write settings on shutdown

This commit is contained in:
jsteemann 2017-05-03 15:18:17 +02:00
parent b9e87d2619
commit c716fcacd3
4 changed files with 34 additions and 33 deletions

View File

@ -51,8 +51,6 @@ void RocksDBBackgroundThread::run() {
guard.wait(static_cast<uint64_t>(_interval * 1000000.0));
}
_engine->counterManager()->writeSettings();
if (!isStopping()) {
_engine->counterManager()->sync(false);
}
@ -67,5 +65,5 @@ void RocksDBBackgroundThread::run() {
});
}
}
_engine->counterManager()->writeSettings(); // final write on shutdown
_engine->counterManager()->sync(true); // final write on shutdown
}

View File

@ -165,10 +165,6 @@ void RocksDBCounterManager::removeCounter(uint64_t objectId) {
/// Thread-Safe force sync
Result RocksDBCounterManager::sync(bool force) {
#if 0
writeSettings();
#endif
if (force) {
while (true) {
bool expected = false;
@ -218,12 +214,34 @@ Result RocksDBCounterManager::sync(bool force) {
rocksdb::Status s = rtrx->Put(key.string(), value);
if (!s.ok()) {
rtrx->Rollback();
LOG_TOPIC(WARN, Logger::ENGINES) << "writing counters failed";
return rocksutils::convertStatus(s);
}
}
// now write global settings
b.clear();
b.openObject();
b.add("tick", VPackValue(std::to_string(TRI_CurrentTickServer())));
b.add("hlc", VPackValue(std::to_string(TRI_HybridLogicalClock())));
b.close();
VPackSlice slice = b.slice();
LOG_TOPIC(TRACE, Logger::ENGINES) << "writing settings: " << slice.toJson();
RocksDBKey key = RocksDBKey::SettingsValue();
rocksdb::Slice value(slice.startAs<char>(), slice.byteSize());
rocksdb::Status s = rtrx->Put(key.string(), value);
if (!s.ok()) {
LOG_TOPIC(WARN, Logger::ENGINES) << "writing settings failed";
rtrx->Rollback();
return rocksutils::convertStatus(s);
}
// we have to commit all counters in one batch
rocksdb::Status s = rtrx->Commit();
s = rtrx->Commit();
if (s.ok()) {
for (std::pair<uint64_t, CMValue> const& pair : copy) {
_syncedSeqNums[pair.first] = pair.second._sequenceNum;
@ -252,6 +270,13 @@ void RocksDBCounterManager::readSettings() {
basics::VelocyPackHelper::stringUInt64(slice.get("tick"));
LOG_TOPIC(TRACE, Logger::ENGINES) << "using last tick: " << lastTick;
TRI_UpdateTickServer(lastTick);
if (slice.hasKey("hlc")) {
uint64_t lastHlc =
basics::VelocyPackHelper::stringUInt64(slice.get("hlc"));
LOG_TOPIC(TRACE, Logger::ENGINES) << "using last hlc: " << lastHlc;
TRI_HybridLogicalClock(lastHlc);
}
} catch (...) {
LOG_TOPIC(WARN, Logger::ENGINES)
<< "unable to read initial settings: invalid data";
@ -260,27 +285,6 @@ void RocksDBCounterManager::readSettings() {
}
}
void RocksDBCounterManager::writeSettings() {
RocksDBKey key = RocksDBKey::SettingsValue();
VPackBuilder builder;
builder.openObject();
builder.add("tick", VPackValue(std::to_string(TRI_CurrentTickServer())));
builder.close();
VPackSlice slice = builder.slice();
LOG_TOPIC(TRACE, Logger::ENGINES) << "writing settings: " << slice.toJson();
rocksdb::Slice value(slice.startAs<char>(), slice.byteSize());
rocksdb::Status status =
_db->Put(rocksdb::WriteOptions(), key.string(), value);
if (!status.ok()) {
LOG_TOPIC(TRACE, Logger::ENGINES) << "writing settings failed";
}
}
/// Parse counter values from rocksdb
void RocksDBCounterManager::readCounterValues() {
WRITE_LOCKER(guard, _rwLock);
@ -311,10 +315,10 @@ struct WBReader : public rocksdb::WriteBatch::Handler {
uint64_t _maxTick = 0;
uint64_t _maxHLC = 0;
explicit WBReader() : currentSeqNum(0) {}
WBReader() : currentSeqNum(0) {}
virtual ~WBReader() {
// update ticks after parsing wal
TRI_UpdateTickServer(std::max(_maxTick, TRI_CurrentTickServer()));
TRI_UpdateTickServer(_maxTick);
TRI_HybridLogicalClock(_maxHLC);
}

View File

@ -88,7 +88,6 @@ class RocksDBCounterManager {
arangodb::Result sync(bool force);
void readSettings();
void writeSettings();
protected:
struct CMValue {

View File

@ -204,7 +204,7 @@ void RocksDBEngine::start() {
_options.comparator = _cmp.get();
// WAL_ttl_seconds needs to be bigger than the sync interval of the count
// manager. Should be several times bigger counter_sync_seconds
_options.WAL_ttl_seconds = 600; //(uint64_t)(counter_sync_seconds * 2.0);
_options.WAL_ttl_seconds = 10; //600; //(uint64_t)(counter_sync_seconds * 2.0);
double counter_sync_seconds = 2.5;
// TODO: prefix_extractior + memtable_insert_with_hint_prefix