Skip to content

Commit a84f964

Browse files
committed
fix(hll_family): Fixed PFMERGE calculation
Fixed bug in hllMergeDense that writes to wrong register. Fixes #4750 Signed-off-by: mkaruza <[email protected]>
1 parent 624e111 commit a84f964

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/redis/hyperloglog.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,7 @@ int64_t pfcountSingle(struct HllBufferPtr hll_ptr) {
13701370
}
13711371

13721372
/* Merge dense-encoded HLL */
1373-
static void hllMergeDense(uint8_t* max, struct HllBufferPtr to) {
1374-
uint8_t* registers = max + HLL_HDR_SIZE;
1373+
static void hllMergeDense(uint8_t* registers, struct HllBufferPtr to) {
13751374
uint8_t val;
13761375
struct hllhdr* hll_hdr = (struct hllhdr*)to.hll;
13771376

src/server/hll_family_test.cc

+9-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,15 @@ TEST_F(HllFamilyTest, MergeToNew) {
166166
TEST_F(HllFamilyTest, MergeToExisting) {
167167
EXPECT_EQ(CheckedInt({"pfadd", "key1", "1", "2", "3"}), 1);
168168
EXPECT_EQ(CheckedInt({"pfadd", "key2", "4", "5"}), 1);
169-
EXPECT_EQ(Run({"pfmerge", "key2", "key1"}), "OK");
170-
EXPECT_EQ(CheckedInt({"pfcount", "key2"}), 5);
169+
EXPECT_EQ(Run({"pfmerge", "key3", "key2", "key1"}), "OK");
170+
EXPECT_EQ(CheckedInt({"pfcount", "key3"}), 5);
171+
EXPECT_EQ(Run({"pfmerge", "key3", "key3"}), "OK");
172+
EXPECT_EQ(CheckedInt({"pfcount", "key3"}), 5);
173+
EXPECT_EQ(Run({"pfmerge", "key3"}), "OK");
174+
EXPECT_EQ(CheckedInt({"pfcount", "key3"}), 5);
175+
EXPECT_EQ(CheckedInt({"pfadd", "key4", "4", "5", "6"}), 1);
176+
EXPECT_EQ(Run({"pfmerge", "key3", "key4"}), "OK");
177+
EXPECT_EQ(CheckedInt({"pfcount", "key3"}), 6);
171178
}
172179

173180
TEST_F(HllFamilyTest, MergeNonExisting) {

0 commit comments

Comments
 (0)