test(cluster-migration): Fix some bugs and add cluster migration fuzzy tests (#2572)

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
Co-authored-by: Vladislav Oleshko <vlad@dragonflydb.io>
This commit is contained in:
Shahar Mike 2024-02-12 13:47:34 +02:00 committed by GitHub
parent 6cd2f05a22
commit 6d11f86091
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 231 additions and 29 deletions

View file

@ -75,7 +75,8 @@ void RestoreStreamer::Start(io::Sink* dest) {
if (fiber_cancellation_.IsCancelled())
return;
cursor = pt->Traverse(cursor, absl::bind_front(&RestoreStreamer::WriteBucket, this));
cursor =
pt->Traverse(cursor, [this](PrimeTable::bucket_iterator it) { WriteBucket(it, true); });
++last_yield;
if (last_yield >= 100) {
@ -101,6 +102,10 @@ void RestoreStreamer::SendFinalize() {
NotifyWritten(true);
}
RestoreStreamer::~RestoreStreamer() {
CHECK(!snapshot_fb_.IsJoinable());
}
void RestoreStreamer::Cancel() {
fiber_cancellation_.Cancel();
snapshot_fb_.JoinIfNeeded();
@ -124,7 +129,7 @@ bool RestoreStreamer::ShouldWrite(SlotId slot_id) const {
return my_slots_.contains(slot_id);
}
void RestoreStreamer::WriteBucket(PrimeTable::bucket_iterator it) {
void RestoreStreamer::WriteBucket(PrimeTable::bucket_iterator it, bool allow_await) {
bool is_data_present = false;
if (it.GetVersion() < snapshot_version_) {
@ -149,7 +154,7 @@ void RestoreStreamer::WriteBucket(PrimeTable::bucket_iterator it) {
}
if (is_data_present)
NotifyWritten(true);
NotifyWritten(allow_await);
}
void RestoreStreamer::OnDbChange(DbIndex db_index, const DbSlice::ChangeReq& req) {
@ -159,12 +164,12 @@ void RestoreStreamer::OnDbChange(DbIndex db_index, const DbSlice::ChangeReq& req
PrimeTable* table = db_slice_->GetTables(0).first;
if (const PrimeTable::bucket_iterator* bit = req.update()) {
WriteBucket(*bit);
WriteBucket(*bit, false);
} else {
string_view key = get<string_view>(req.change);
table->CVCUponInsert(snapshot_version_, key, [this](PrimeTable::bucket_iterator it) {
DCHECK_LT(it.GetVersion(), snapshot_version_);
WriteBucket(it);
WriteBucket(it, false);
});
}
}