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:09:47 +0200
commitfc33779283b4b0e13ad970e56f500b0f3d0e8dfd (patch)
treeb4c2a9d20da1c27f0f6c3b8f702a3f3baa07440a
parent67e15a0ff728e7fc04e61f428d4faf285739841d (diff)
downloadredis-fc33779283b4b0e13ad970e56f500b0f3d0e8dfd.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.