diff options
author | sundb <sundbcn@gmail.com> | 2021-08-10 14:18:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-10 09:18:49 +0300 |
commit | 02fd76b97cbc5b8ad6f4c81c8538f02c76cbed46 (patch) | |
tree | 7b40fbf03f5003c9993451dfe5b8fd902570ac51 /src/object.c | |
parent | cbda492909cd2fff25263913cd2e1f00bc48a541 (diff) | |
download | redis-02fd76b97cbc5b8ad6f4c81c8538f02c76cbed46.tar.gz |
Replace all usage of ziplist with listpack for t_hash (#8887)
Part one of implementing #8702 (taking hashes first before other types)
## Description of the feature
1. Change ziplist encoded hash objects to listpack encoding.
2. Convert existing ziplists on RDB loading time. an O(n) operation.
## Rdb format changes
1. Add RDB_TYPE_HASH_LISTPACK rdb type.
2. Bump RDB_VERSION to 10
## Interface changes
1. New `hash-max-listpack-entries` config is an alias for `hash-max-ziplist-entries` (same with `hash-max-listpack-value`)
2. OBJECT ENCODING will return `listpack` instead of `ziplist`
## Listpack improvements:
1. Support direct insert, replace integer element (rather than convert back and forth from string)
3. Add more listpack capabilities to match the ziplist ones (like `lpFind`, `lpRandomPairs` and such)
4. Optimize element length fetching, avoid multiple calculations
5. Use inline to avoid function call overhead.
## Tests
1. Add a new test to the RDB load time conversion
2. Adding the listpack unit tests. (based on the one in ziplist.c)
3. Add a few "corrupt payload: fuzzer findings" tests, and slightly modify existing ones.
Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/object.c')
-rw-r--r-- | src/object.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/object.c b/src/object.c index b65430784..90fa28254 100644 --- a/src/object.c +++ b/src/object.c @@ -255,9 +255,9 @@ robj *createIntsetObject(void) { } robj *createHashObject(void) { - unsigned char *zl = ziplistNew(); + unsigned char *zl = lpNew(0); robj *o = createObject(OBJ_HASH, zl); - o->encoding = OBJ_ENCODING_ZIPLIST; + o->encoding = OBJ_ENCODING_LISTPACK; return o; } @@ -342,8 +342,8 @@ void freeHashObject(robj *o) { case OBJ_ENCODING_HT: dictRelease((dict*) o->ptr); break; - case OBJ_ENCODING_ZIPLIST: - zfree(o->ptr); + case OBJ_ENCODING_LISTPACK: + lpFree(o->ptr); break; default: serverPanic("Unknown hash encoding type"); @@ -929,6 +929,7 @@ char *strEncoding(int encoding) { case OBJ_ENCODING_HT: return "hashtable"; case OBJ_ENCODING_QUICKLIST: return "quicklist"; case OBJ_ENCODING_ZIPLIST: return "ziplist"; + case OBJ_ENCODING_LISTPACK: return "listpack"; case OBJ_ENCODING_INTSET: return "intset"; case OBJ_ENCODING_SKIPLIST: return "skiplist"; case OBJ_ENCODING_EMBSTR: return "embstr"; @@ -1038,7 +1039,7 @@ size_t objectComputeSize(robj *key, robj *o, size_t sample_size, int dbid) { serverPanic("Unknown sorted set encoding"); } } else if (o->type == OBJ_HASH) { - 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_HT) { d = o->ptr; |