chore: add db_slice lock to protect segments from preemptions (#3406)

DastTable::Traverse is error prone when the callback passed preempts because the segment might change. This is problematic and we need atomicity while traversing segments with preemption. The fix is to add Traverse in DbSlice and protect the traversal via ThreadLocalMutex.

* add ConditionFlag to DbSlice
* add Traverse in DbSlice and protect it with the ConditionFlag
* remove condition flag from snapshot
* remove condition flag from streamer

---------

Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
Kostas Kyrimis 2024-07-30 15:02:54 +03:00 committed by GitHub
parent f536f8afbd
commit aa02070e3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 65 additions and 71 deletions

View file

@ -317,7 +317,7 @@ bool EngineShard::DoDefrag() {
uint64_t attempts = 0;
do {
cur = prime_table->Traverse(cur, [&](PrimeIterator it) {
cur = slice.Traverse(prime_table, cur, [&](PrimeIterator it) {
// for each value check whether we should move it because it
// seats on underutilized page of memory, and if so, do it.
bool did = it->second.DefragIfNeeded(threshold);