-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix: race when bumping items while loading a snapshot #4564
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2034,9 +2034,11 @@ error_code RdbLoader::Load(io::Source* src) { | |
|
||
auto cleanup = absl::Cleanup([&] { FinishLoad(start, &keys_loaded); }); | ||
|
||
shard_set->AwaitRunningOnShardQueue([](EngineShard* es) { | ||
namespaces->GetDefaultNamespace().GetCurrentDbSlice().SetLoadInProgress(true); | ||
}); | ||
// Increment local one if it exists | ||
if (EngineShard* es = EngineShard::tlocal(); es) { | ||
namespaces->GetDefaultNamespace().GetCurrentDbSlice().IncrLoadInProgress(); | ||
} | ||
|
||
while (!stop_early_.load(memory_order_relaxed)) { | ||
if (pause_) { | ||
ThisFiber::SleepFor(100ms); | ||
|
@@ -2226,12 +2228,13 @@ void RdbLoader::FinishLoad(absl::Time start_time, size_t* keys_loaded) { | |
FlushShardAsync(i); | ||
|
||
// Send sentinel callbacks to ensure that all previous messages have been processed. | ||
shard_set->Add(i, [bc]() mutable { | ||
namespaces->GetDefaultNamespace().GetCurrentDbSlice().SetLoadInProgress(false); | ||
bc->Dec(); | ||
}); | ||
shard_set->Add(i, [bc]() mutable { bc->Dec(); }); | ||
} | ||
bc->Wait(); // wait for sentinels to report. | ||
// Decrement local one if it exists | ||
if (EngineShard* es = EngineShard::tlocal(); es) { | ||
namespaces->GetDefaultNamespace().GetCurrentDbSlice().IncrLoadInProgress(); | ||
} | ||
|
||
absl::Duration dur = absl::Now() - start_time; | ||
load_time_ = double(absl::ToInt64Milliseconds(dur)) / 1000; | ||
|
@@ -2515,7 +2518,12 @@ void RdbLoader::FlushShardAsync(ShardId sid) { | |
return; | ||
|
||
auto cb = [indx = this->cur_db_index_, this, ib = std::move(out_buf)] { | ||
// Before we start loading, increment LoadInProgress. | ||
// This is required because FlushShardAsync dispatches to multiple shards, and those shards | ||
// might have not yet have their state (load in progress) incremented. | ||
namespaces->GetDefaultNamespace().GetCurrentDbSlice().IncrLoadInProgress(); | ||
this->LoadItemsBuffer(indx, ib); | ||
namespaces->GetDefaultNamespace().GetCurrentDbSlice().DecrLoadInProgress(); | ||
|
||
// Block, if tiered storage is active, but can't keep up | ||
while (EngineShard::tlocal()->ShouldThrottleForTiering()) { | ||
|
@@ -2554,6 +2562,8 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) { | |
DbContext db_cntx{&namespaces->GetDefaultNamespace(), db_ind, GetCurrentTimeMs()}; | ||
DbSlice& db_slice = db_cntx.GetDbSlice(es->shard_id()); | ||
|
||
DCHECK(!db_slice.IsCacheMode()); | ||
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. Maybe 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. no need |
||
|
||
auto error_msg = [](const auto* item, auto db_ind) { | ||
return absl::StrCat("Found empty key: ", item->key, " in DB ", db_ind, " rdb_type ", | ||
item->val.rdb_type); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -735,4 +735,19 @@ TEST_F(RdbTest, HugeKeyIssue4497) { | |
EXPECT_EQ(Run({"flushall"}), "OK"); | ||
} | ||
|
||
TEST_F(RdbTest, HugeKeyIssue4554) { | ||
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. This fails without my changes. IMO, I wanted to reproduce via a replication test, because only replication is used on the issue. However, it proved to be a little more difficult than expected for reasons hard for me to explain in a few lines. I am fairly positive that this PR will address all the problems but I would like to have a binary asap to sent and verify that we did see the same/similar case on the issue as here. |
||
SetTestFlag("cache_mode", "true"); | ||
// We need to stress one flow/shard such that the others finish early. Lock on hashtags allows | ||
// that. | ||
SetTestFlag("lock_on_hashtags", "true"); | ||
ResetService(); | ||
|
||
EXPECT_EQ( | ||
Run({"debug", "populate", "20", "{tmp}", "20", "rand", "type", "set", "elements", "10000"}), | ||
"OK"); | ||
EXPECT_EQ(Run({"save", "df", "hugekey"}), "OK"); | ||
EXPECT_EQ(Run({"dfly", "load", "hugekey-summary.dfs"}), "OK"); | ||
EXPECT_EQ(Run({"flushall"}), "OK"); | ||
} | ||
|
||
} // namespace dfly |
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.
please remove the CHECK at
db_slice.cc:783] Check failed: fetched_items_.empty()
and replace it with DFATAL
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.
oh I forgot this, you mentioned in it in the standup