summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-04-14 15:55:21 +0200
committerantirez <antirez@gmail.com>2014-04-16 15:26:27 +0200
commit91e05e1618a2db22b93d125d4f2b43daa6fe99d1 (patch)
treeed7dd8380ccdcf6aac89ae38e6885f419c98ef31
parent68a4bf70e0beb3cf1ea0ef470be36b1ef1a829f0 (diff)
downloadredis-91e05e1618a2db22b93d125d4f2b43daa6fe99d1.tar.gz
Added assertion in hllSparseAdd() when promotion to dense occurs.
If we converted to dense, a register must be updated in the dense representation.
-rw-r--r--src/hyperloglog.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/hyperloglog.c b/src/hyperloglog.c
index fe1321513..b7c4b6cfe 100644
--- a/src/hyperloglog.c
+++ b/src/hyperloglog.c
@@ -865,7 +865,17 @@ updated:
promote: /* Promote to dense representation. */
if (hllSparseToDense(o) == REDIS_ERR) return -1; /* Corrupted HLL. */
hdr = o->ptr;
- return hllDenseAdd(hdr->registers, ele, elesize);
+
+ /* We need to call hllDenseAdd() to perform the operation after the
+ * conversion. However the result must be 1, since if we need to
+ * convert from sparse to dense a register requires to be updated.
+ *
+ * Note that this in turn means that PFADD will make sure the command
+ * is propagated to slaves / AOF, so if there is a sparse -> dense
+ * convertion, it will be performed in all the slaves as well. */
+ int dense_retval = hllDenseAdd(hdr->registers, ele, elesize);
+ redisAssert(dense_retval == 1);
+ return dense_retval;
}
/* Compute SUM(2^-reg) in the sparse representation.