summaryrefslogtreecommitdiff
path: root/src/object.c
diff options
context:
space:
mode:
authorsundb <sundbcn@gmail.com>2021-09-09 23:18:53 +0800
committerGitHub <noreply@github.com>2021-09-09 18:18:53 +0300
commit3ca6972ecd3e9963f65b9cb1ff050ad60f03563e (patch)
tree9f82d9d622f5d161bc0d72c83f8f31555f5a652d /src/object.c
parent86b0de5c41c96225377b83090fbdbe0209c2d9b9 (diff)
downloadredis-3ca6972ecd3e9963f65b9cb1ff050ad60f03563e.tar.gz
Replace all usage of ziplist with listpack for t_zset (#9366)
Part two of implementing #8702 (zset), after #8887. ## Description of the feature Replaced all uses of ziplist with listpack in t_zset, and optimized some of the code to optimize performance. ## Rdb format changes New `RDB_TYPE_ZSET_LISTPACK` rdb type. ## Rdb loading improvements: 1) Pre-expansion of dict for validation of duplicate data for listpack and ziplist. 2) Simplifying the release of empty key objects when RDB loading. 3) Unify ziplist and listpack data verify methods for zset and hash, and move code to rdb.c. ## Interface changes 1) New `zset-max-listpack-entries` config is an alias for `zset-max-ziplist-entries` (same with `zset-max-listpack-value`). 2) OBJECT ENCODING will return listpack instead of ziplist. ## Listpack improvements: 1) Add `lpDeleteRange` and `lpDeleteRangeWithEntry` functions to delete a range of entries from listpack. 2) Improve the performance of `lpCompare`, converting from string to integer is faster than converting from integer to string. 3) Replace `snprintf` with `ll2string` to improve performance in converting numbers to strings in `lpGet()`. ## Zset improvements: 1) Improve the performance of `zzlFind` method, use `lpFind` instead of `lpCompare` in a loop. 2) Use `lpDeleteRangeWithEntry` instead of `lpDelete` twice to delete a element of zset. ## Tests 1) Add some unittests for `lpDeleteRange` and `lpDeleteRangeWithEntry` function. 2) Add zset RDB loading test. 3) Add benchmark test for `lpCompare` and `ziplsitCompare`. 4) Add empty listpack zset corrupt dump test.
Diffstat (limited to 'src/object.c')
-rw-r--r--src/object.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/object.c b/src/object.c
index ef1430088..0f869ea7e 100644
--- a/src/object.c
+++ b/src/object.c
@@ -272,10 +272,10 @@ robj *createZsetObject(void) {
return o;
}
-robj *createZsetZiplistObject(void) {
- unsigned char *zl = ziplistNew();
- robj *o = createObject(OBJ_ZSET,zl);
- o->encoding = OBJ_ENCODING_ZIPLIST;
+robj *createZsetListpackObject(void) {
+ unsigned char *lp = lpNew(0);
+ robj *o = createObject(OBJ_ZSET,lp);
+ o->encoding = OBJ_ENCODING_LISTPACK;
return o;
}
@@ -329,7 +329,7 @@ void freeZsetObject(robj *o) {
zslFree(zs->zsl);
zfree(zs);
break;
- case OBJ_ENCODING_ZIPLIST:
+ case OBJ_ENCODING_LISTPACK:
zfree(o->ptr);
break;
default:
@@ -473,8 +473,8 @@ void dismissZsetObject(robj *o, size_t size_hint) {
dict *d = zs->dict;
dismissMemory(d->ht_table[0], DICTHT_SIZE(d->ht_size_exp[0])*sizeof(dictEntry*));
dismissMemory(d->ht_table[1], DICTHT_SIZE(d->ht_size_exp[1])*sizeof(dictEntry*));
- } else if (o->encoding == OBJ_ENCODING_ZIPLIST) {
- dismissMemory(o->ptr, ziplistBlobLen((unsigned char*)o->ptr));
+ } else if (o->encoding == OBJ_ENCODING_LISTPACK) {
+ dismissMemory(o->ptr, lpBytes((unsigned char*)o->ptr));
} else {
serverPanic("Unknown zset encoding type");
}
@@ -1027,7 +1027,7 @@ size_t objectComputeSize(robj *key, robj *o, size_t sample_size, int dbid) {
serverPanic("Unknown set encoding");
}
} else if (o->type == OBJ_ZSET) {
- if (o->encoding == OBJ_ENCODING_ZIPLIST) {
+ if (o->encoding == OBJ_ENCODING_LISTPACK) {
asize = sizeof(*o)+zmalloc_size(o->ptr);
} else if (o->encoding == OBJ_ENCODING_SKIPLIST) {
d = ((zset*)o->ptr)->dict;