-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rocksdb manual flush code changes #11849
Open
neethuhaneesha
wants to merge
1
commit into
apple:main
Choose a base branch
from
neethuhaneesha:manFlush-main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−23
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,8 @@ class SharedRocksDBState { | |
rocksdb::Options getOptions() const { return rocksdb::Options(this->dbOptions, this->cfOptions); } | ||
rocksdb::ReadOptions getReadOptions() { return this->readOptions; } | ||
rocksdb::FlushOptions getFlushOptions() { return this->flushOptions; } | ||
double getLastFlushTime() { return this->lastFlushTime_; } | ||
void setLastFlushTime(double lastFlushTime) { this->lastFlushTime_ = lastFlushTime; } | ||
|
||
private: | ||
const UID id; | ||
|
@@ -120,6 +122,7 @@ class SharedRocksDBState { | |
rocksdb::ColumnFamilyOptions cfOptions; | ||
rocksdb::ReadOptions readOptions; | ||
rocksdb::FlushOptions flushOptions; | ||
std::atomic<double> lastFlushTime_; | ||
}; | ||
|
||
SharedRocksDBState::SharedRocksDBState(UID id) | ||
|
@@ -374,12 +377,14 @@ class RocksDBErrorListener : public rocksdb::EventListener { | |
|
||
class RocksDBEventListener : public rocksdb::EventListener { | ||
public: | ||
RocksDBEventListener(std::shared_ptr<double> lastFlushTime) : lastFlushTime(lastFlushTime){}; | ||
RocksDBEventListener(std::shared_ptr<SharedRocksDBState> sharedState) : sharedState(sharedState){}; | ||
|
||
void OnFlushCompleted(rocksdb::DB* db, const rocksdb::FlushJobInfo& info) override { *lastFlushTime = now(); } | ||
void OnFlushCompleted(rocksdb::DB* db, const rocksdb::FlushJobInfo& info) override { | ||
sharedState->setLastFlushTime(now()); | ||
} | ||
|
||
private: | ||
std::shared_ptr<double> lastFlushTime; | ||
std::shared_ptr<SharedRocksDBState> sharedState; | ||
}; | ||
|
||
using DB = rocksdb::DB*; | ||
|
@@ -986,19 +991,30 @@ ACTOR Future<Void> flowLockLogger(UID id, const FlowLock* readLock, const FlowLo | |
} | ||
} | ||
|
||
ACTOR Future<Void> manualFlush(UID id, | ||
rocksdb::DB* db, | ||
std::shared_ptr<SharedRocksDBState> sharedState, | ||
std::shared_ptr<double> lastFlushTime, | ||
CF cf) { | ||
ACTOR Future<Void> manualFlush(UID id, rocksdb::DB* db, std::shared_ptr<SharedRocksDBState> sharedState, CF cf) { | ||
if (SERVER_KNOBS->ROCKSDB_MANUAL_FLUSH_TIME_INTERVAL) { | ||
state rocksdb::FlushOptions fOptions = sharedState->getFlushOptions(); | ||
state double waitTime = SERVER_KNOBS->ROCKSDB_MANUAL_FLUSH_TIME_INTERVAL; | ||
state double currTime = 0; | ||
state int timeElapsedAfterLastFlush = 0; | ||
loop { | ||
wait(delay(SERVER_KNOBS->ROCKSDB_MANUAL_FLUSH_TIME_INTERVAL)); | ||
wait(delay(waitTime)); | ||
|
||
if ((now() - *lastFlushTime) > SERVER_KNOBS->ROCKSDB_MANUAL_FLUSH_TIME_INTERVAL) { | ||
currTime = now(); | ||
timeElapsedAfterLastFlush = currTime - sharedState->getLastFlushTime(); | ||
if (timeElapsedAfterLastFlush >= SERVER_KNOBS->ROCKSDB_MANUAL_FLUSH_TIME_INTERVAL) { | ||
db->Flush(fOptions, cf); | ||
TraceEvent e("RocksDBManualFlush", id); | ||
waitTime = SERVER_KNOBS->ROCKSDB_MANUAL_FLUSH_TIME_INTERVAL; | ||
TraceEvent("RocksDBManualFlush", id).detail("TimeElapsedAfterLastFlush", timeElapsedAfterLastFlush); | ||
} else { | ||
waitTime = SERVER_KNOBS->ROCKSDB_MANUAL_FLUSH_TIME_INTERVAL - timeElapsedAfterLastFlush; | ||
} | ||
|
||
// The above code generates different waitTimes based on rocksdb background flushes which causes non | ||
// deterministic behavior. Setting constant waitTimes in simulation to avoid this. And enable the behavior | ||
// only in RocksdbNondeterministic(ROCKSDB_METRICS_IN_SIMULATION=true) test. | ||
if (g_network->isSimulated() && !SERVER_KNOBS->ROCKSDB_METRICS_IN_SIMULATION) { | ||
waitTime = SERVER_KNOBS->ROCKSDB_MANUAL_FLUSH_TIME_INTERVAL; | ||
Comment on lines
+1016
to
+1017
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this code is not related to metrics, can we rename |
||
} | ||
} | ||
} | ||
|
@@ -1289,11 +1305,9 @@ struct RocksDBKeyValueStore : IKeyValueStore { | |
const FlowLock* fetchLock, | ||
std::shared_ptr<RocksDBErrorListener> errorListener, | ||
std::shared_ptr<RocksDBEventListener> eventListener, | ||
std::shared_ptr<double> lastFlushTime, | ||
Counters& counters) | ||
: path(std::move(path)), metrics(metrics), readLock(readLock), fetchLock(fetchLock), | ||
errorListener(errorListener), eventListener(eventListener), lastFlushTime(lastFlushTime), | ||
counters(counters) {} | ||
errorListener(errorListener), eventListener(eventListener), counters(counters) {} | ||
|
||
double getTimeEstimate() const override { return SERVER_KNOBS->COMMIT_TIME_ESTIMATE; } | ||
}; | ||
|
@@ -1368,10 +1382,10 @@ struct RocksDBKeyValueStore : IKeyValueStore { | |
&a.counters, | ||
cf) && | ||
flowLockLogger(id, a.readLock, a.fetchLock) && refreshReadIteratorPool(readIterPool) && | ||
manualFlush(id, db, sharedState, a.lastFlushTime, cf); | ||
manualFlush(id, db, sharedState, cf); | ||
} else { | ||
a.metrics = flowLockLogger(id, a.readLock, a.fetchLock) && refreshReadIteratorPool(readIterPool) && | ||
manualFlush(id, db, sharedState, a.lastFlushTime, cf); | ||
manualFlush(id, db, sharedState, cf); | ||
} | ||
} else { | ||
onMainThread([&] { | ||
|
@@ -1384,7 +1398,7 @@ struct RocksDBKeyValueStore : IKeyValueStore { | |
&a.counters, | ||
cf) && | ||
flowLockLogger(id, a.readLock, a.fetchLock) && refreshReadIteratorPool(readIterPool) && | ||
manualFlush(id, db, sharedState, a.lastFlushTime, cf); | ||
manualFlush(id, db, sharedState, cf); | ||
return Future<bool>(true); | ||
}).blockUntilReady(); | ||
} | ||
|
@@ -1898,8 +1912,7 @@ struct RocksDBKeyValueStore : IKeyValueStore { | |
numReadWaiters(SERVER_KNOBS->ROCKSDB_READ_QUEUE_HARD_MAX - SERVER_KNOBS->ROCKSDB_READ_QUEUE_SOFT_MAX), | ||
numFetchWaiters(SERVER_KNOBS->ROCKSDB_FETCH_QUEUE_HARD_MAX - SERVER_KNOBS->ROCKSDB_FETCH_QUEUE_SOFT_MAX), | ||
errorListener(std::make_shared<RocksDBErrorListener>(id)), errorFuture(errorListener->getFuture()) { | ||
lastFlushTime = std::make_shared<double>(now()); | ||
eventListener = std::make_shared<RocksDBEventListener>(lastFlushTime); | ||
eventListener = std::make_shared<RocksDBEventListener>(sharedState); | ||
// In simluation, run the reader/writer threads as Coro threads (i.e. in the network thread. The storage engine | ||
// is still multi-threaded as background compaction threads are still present. Reads/writes to disk will also | ||
// block the network thread in a way that would be unacceptable in production but is a necessary evil here. When | ||
|
@@ -2093,7 +2106,7 @@ struct RocksDBKeyValueStore : IKeyValueStore { | |
return openFuture; | ||
} | ||
auto a = std::make_unique<Writer::OpenAction>( | ||
path, metrics, &readSemaphore, &fetchSemaphore, errorListener, eventListener, lastFlushTime, counters); | ||
path, metrics, &readSemaphore, &fetchSemaphore, errorListener, eventListener, counters); | ||
openFuture = a->done.getFuture(); | ||
writeThread->post(a.release()); | ||
return openFuture; | ||
|
@@ -2427,7 +2440,6 @@ struct RocksDBKeyValueStore : IKeyValueStore { | |
Reference<IThreadPool> readThreads; | ||
std::shared_ptr<RocksDBErrorListener> errorListener; | ||
std::shared_ptr<RocksDBEventListener> eventListener; | ||
std::shared_ptr<double> lastFlushTime; | ||
Future<Void> errorFuture; | ||
Promise<Void> closePromise; | ||
Future<Void> openFuture; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can be made const