fix: potential crash with multi-sharded pfmerge (#5008)

Fixes #5004

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2025-04-27 14:12:55 +03:00 committed by GitHub
parent d5c375235f
commit ff7d9b79c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 6 deletions

View file

@ -255,14 +255,14 @@ OpResult<int> PFMergeInternal(CmdArgList args, Transaction* tx, SinkReplyBuilder
if (result.ok()) {
hlls[sid] = std::move(result.value());
} else {
success = false;
success.store(false, memory_order_relaxed);
}
return result.status();
return OpStatus::OK;
};
tx->Execute(std::move(cb), false);
if (!success) {
if (!success.load(memory_order_relaxed)) {
tx->Conclude();
return OpStatus::INVALID_VALUE;
}

View file

@ -194,11 +194,12 @@ TEST_F(HllFamilyTest, MergeOverlapping) {
}
TEST_F(HllFamilyTest, MergeInvalid) {
GTEST_SKIP() << "TBD: MergeInvalid test fails with multi-shard runs, see #5004";
Run({"exists", "key1", "key4"});
ASSERT_EQ(GetDebugInfo().shards_count, 2); // ensure 2 shards
EXPECT_EQ(CheckedInt({"pfadd", "key1", "1", "2", "3"}), 1);
EXPECT_EQ(Run({"set", "key2", "..."}), "OK");
EXPECT_THAT(Run({"pfmerge", "key1", "key2"}), ErrArg(HllFamily::kInvalidHllErr));
EXPECT_EQ(Run({"set", "key4", "..."}), "OK");
EXPECT_THAT(Run({"pfmerge", "key1", "key4"}), ErrArg(HllFamily::kInvalidHllErr));
EXPECT_EQ(CheckedInt({"pfcount", "key1"}), 3);
}