From 4a096ce97c18dc1b50433b8449a812ea4ff722de Mon Sep 17 00:00:00 2001 From: neethuhaneesha Date: Wed, 16 Nov 2022 15:08:39 -0800 Subject: [PATCH] Rocksdb suggest compact range checks --- fdbclient/ServerKnobs.cpp | 1 + fdbclient/include/fdbclient/ServerKnobs.h | 2 +- fdbserver/KeyValueStoreRocksDB.actor.cpp | 23 +++++++++++-------- .../KeyValueStoreShardedRocksDB.actor.cpp | 20 ++++++++-------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/fdbclient/ServerKnobs.cpp b/fdbclient/ServerKnobs.cpp index bc4da29ff1f..2ecdb496de9 100644 --- a/fdbclient/ServerKnobs.cpp +++ b/fdbclient/ServerKnobs.cpp @@ -436,6 +436,7 @@ void ServerKnobs::initialize(Randomize randomize, ClientKnobs* clientKnobs, IsSi init( ROCKSDB_SINGLEKEY_DELETES_BYTES_LIMIT, 200000 ); // 200KB init( ROCKSDB_ENABLE_CLEAR_RANGE_EAGER_READS, true ); if( randomize && BUGGIFY ) ROCKSDB_ENABLE_CLEAR_RANGE_EAGER_READS = deterministicRandom()->coinflip(); // ROCKSDB_STATS_LEVEL=1 indicates rocksdb::StatsLevel::kExceptHistogramOrTimers + // Refer StatsLevel: https://github.com/facebook/rocksdb/blob/main/include/rocksdb/statistics.h#L594 init( ROCKSDB_STATS_LEVEL, 1 ); if( randomize && BUGGIFY ) ROCKSDB_STATS_LEVEL = deterministicRandom()->randomInt(0, 6); // Can commit will delay ROCKSDB_CAN_COMMIT_DELAY_ON_OVERLOAD seconds for // ROCKSDB_CAN_COMMIT_DELAY_TIMES_ON_OVERLOAD times, if rocksdb overloaded. diff --git a/fdbclient/include/fdbclient/ServerKnobs.h b/fdbclient/include/fdbclient/ServerKnobs.h index dd0c0b7fb1b..cd98df2f375 100644 --- a/fdbclient/include/fdbclient/ServerKnobs.h +++ b/fdbclient/include/fdbclient/ServerKnobs.h @@ -307,7 +307,7 @@ class ServerKnobs : public KnobsImpl { // KeyValueStoreRocksDB bool ROCKSDB_SET_READ_TIMEOUT; bool ROCKSDB_LEVEL_COMPACTION_DYNAMIC_LEVEL_BYTES; - int ROCKSDB_SUGGEST_COMPACT_CLEAR_RANGE; + bool ROCKSDB_SUGGEST_COMPACT_CLEAR_RANGE; int ROCKSDB_READ_RANGE_ROW_LIMIT; int ROCKSDB_READER_THREAD_PRIORITY; int ROCKSDB_WRITER_THREAD_PRIORITY; diff --git a/fdbserver/KeyValueStoreRocksDB.actor.cpp b/fdbserver/KeyValueStoreRocksDB.actor.cpp index 3351315b355..a97e505476f 100644 --- a/fdbserver/KeyValueStoreRocksDB.actor.cpp +++ b/fdbserver/KeyValueStoreRocksDB.actor.cpp @@ -901,6 +901,7 @@ ACTOR Future rocksDBMetricLogger(UID id, }; // To control the rocksdb::StatsLevel, use ROCKSDB_STATS_LEVEL knob. + // Refer StatsLevel: https://github.com/facebook/rocksdb/blob/main/include/rocksdb/statistics.h#L594 state std::vector> histogramStats = { { "CompactionTime", rocksdb::COMPACTION_TIME }, // enabled if rocksdb::StatsLevel > kExceptTimers(2) { "CompactionCPUTime", rocksdb::COMPACTION_CPU_TIME }, // enabled if rocksdb::StatsLevel > kExceptTimers(2) @@ -970,6 +971,7 @@ ACTOR Future rocksDBMetricLogger(UID id, } // None of the histogramStats are enabled unless the ROCKSDB_STATS_LEVEL > kExceptHistogramOrTimers(1) + // Refer StatsLevel: https://github.com/facebook/rocksdb/blob/main/include/rocksdb/statistics.h#L594 if (SERVER_KNOBS->ROCKSDB_STATS_LEVEL > rocksdb::kExceptHistogramOrTimers) { for (auto& [name, histogram] : histogramStats) { rocksdb::HistogramData histogram_data; @@ -1253,15 +1255,18 @@ struct RocksDBKeyValueStore : IKeyValueStore { std::make_pair(ROCKSDB_COMMIT_QUEUEWAIT_HISTOGRAM.toString(), commitBeginTime - a.startTime)); } Standalone> deletes; - DeleteVisitor dv(deletes, deletes.arena()); - rocksdb::Status s = a.batchToCommit->Iterate(&dv); - if (!s.ok()) { - logRocksDBError(id, s, "CommitDeleteVisitor"); - a.done.sendError(statusToError(s)); - return; + if (SERVER_KNOBS->ROCKSDB_SUGGEST_COMPACT_CLEAR_RANGE) { + DeleteVisitor dv(deletes, deletes.arena()); + rocksdb::Status s = a.batchToCommit->Iterate(&dv); + if (!s.ok()) { + logRocksDBError(id, s, "CommitDeleteVisitor"); + a.done.sendError(statusToError(s)); + return; + } + // If there are any range deletes, we should have added them to be deleted. + ASSERT(!deletes.empty() || !a.batchToCommit->HasDeleteRange()); } - // If there are any range deletes, we should have added them to be deleted. - ASSERT(!deletes.empty() || !a.batchToCommit->HasDeleteRange()); + rocksdb::WriteOptions options; options.sync = !SERVER_KNOBS->ROCKSDB_UNSAFE_AUTO_FSYNC; if (SERVER_KNOBS->ROCKSDB_DISABLE_WAL_EXPERIMENTAL) { @@ -1275,7 +1280,7 @@ struct RocksDBKeyValueStore : IKeyValueStore { // Request for batchToCommit bytes. If this request cannot be satisfied, the call is blocked. rateLimiter->Request(a.batchToCommit->GetDataSize() /* bytes */, rocksdb::Env::IO_HIGH); } - s = db->Write(options, a.batchToCommit.get()); + rocksdb::Status s = db->Write(options, a.batchToCommit.get()); readIterPool->update(); double currTime = timer_monotonic(); sharedState->dbWriteLatency.addMeasurement(currTime - writeBeginTime); diff --git a/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp b/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp index 53edcc1d955..dfe056d1737 100644 --- a/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp +++ b/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp @@ -1886,21 +1886,23 @@ struct ShardedRocksDBKeyValueStore : IKeyValueStore { rocksdb::DB* db, std::vector>* deletes, bool sample) { - DeleteVisitor dv(deletes); - rocksdb::Status s = batch->Iterate(&dv); - if (!s.ok()) { - logRocksDBError(s, "CommitDeleteVisitor"); - return s; - } + if (SERVER_KNOBS->ROCKSDB_SUGGEST_COMPACT_CLEAR_RANGE) { + DeleteVisitor dv(deletes); + rocksdb::Status s = batch->Iterate(&dv); + if (!s.ok()) { + logRocksDBError(s, "CommitDeleteVisitor"); + return s; + } - // If there are any range deletes, we should have added them to be deleted. - ASSERT(!deletes->empty() || !batch->HasDeleteRange()); + // If there are any range deletes, we should have added them to be deleted. + ASSERT(!deletes->empty() || !batch->HasDeleteRange()); + } rocksdb::WriteOptions options; options.sync = !SERVER_KNOBS->ROCKSDB_UNSAFE_AUTO_FSYNC; double writeBeginTime = sample ? timer_monotonic() : 0; - s = db->Write(options, batch); + rocksdb::Status s = db->Write(options, batch); if (sample) { rocksDBMetrics->getWriteHistogram()->sampleSeconds(timer_monotonic() - writeBeginTime); }