Test that zipmap from RDB is correctly converted
This commit is contained in:
parent
3805b34212
commit
a40390001d
12
src/rdb.c
12
src/rdb.c
@ -915,12 +915,13 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
|
|||||||
{
|
{
|
||||||
unsigned char *zl = ziplistNew();
|
unsigned char *zl = ziplistNew();
|
||||||
unsigned char *zi = zipmapRewind(o->ptr);
|
unsigned char *zi = zipmapRewind(o->ptr);
|
||||||
|
|
||||||
while (zi != NULL) {
|
|
||||||
unsigned char *fstr, *vstr;
|
unsigned char *fstr, *vstr;
|
||||||
unsigned int flen, vlen;
|
unsigned int flen, vlen;
|
||||||
|
unsigned int maxlen = 0;
|
||||||
|
|
||||||
zi = zipmapNext(zi, &fstr, &flen, &vstr, &vlen);
|
while ((zi = zipmapNext(zi, &fstr, &flen, &vstr, &vlen)) != NULL) {
|
||||||
|
if (flen > maxlen) maxlen = flen;
|
||||||
|
if (vlen > maxlen) maxlen = vlen;
|
||||||
zl = ziplistPush(zl, fstr, flen, ZIPLIST_TAIL);
|
zl = ziplistPush(zl, fstr, flen, ZIPLIST_TAIL);
|
||||||
zl = ziplistPush(zl, vstr, vlen, ZIPLIST_TAIL);
|
zl = ziplistPush(zl, vstr, vlen, ZIPLIST_TAIL);
|
||||||
}
|
}
|
||||||
@ -930,9 +931,12 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
|
|||||||
o->type = REDIS_HASH;
|
o->type = REDIS_HASH;
|
||||||
o->encoding = REDIS_ENCODING_ZIPLIST;
|
o->encoding = REDIS_ENCODING_ZIPLIST;
|
||||||
|
|
||||||
if (hashTypeLength(o) > server.hash_max_ziplist_entries)
|
if (hashTypeLength(o) > server.hash_max_ziplist_entries ||
|
||||||
|
maxlen > server.hash_max_ziplist_value)
|
||||||
|
{
|
||||||
hashTypeConvert(o, REDIS_ENCODING_HT);
|
hashTypeConvert(o, REDIS_ENCODING_HT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case REDIS_RDB_TYPE_LIST_ZIPLIST:
|
case REDIS_RDB_TYPE_LIST_ZIPLIST:
|
||||||
o->type = REDIS_LIST;
|
o->type = REDIS_LIST;
|
||||||
|
BIN
tests/assets/hash-zipmap.rdb
Normal file
BIN
tests/assets/hash-zipmap.rdb
Normal file
Binary file not shown.
34
tests/integration/convert-zipmap-hash-on-load.tcl
Normal file
34
tests/integration/convert-zipmap-hash-on-load.tcl
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
set server_path [tmpdir "server.convert-zipmap-hash-on-load"]
|
||||||
|
|
||||||
|
# Copy RDB with zipmap encoded hash to server path
|
||||||
|
exec cp tests/assets/hash-zipmap.rdb $server_path
|
||||||
|
|
||||||
|
start_server [list overrides [list "dir" $server_path "dbfilename" "hash-zipmap.rdb"]] {
|
||||||
|
test "RDB load zipmap hash: converts to ziplist" {
|
||||||
|
r select 0
|
||||||
|
|
||||||
|
assert_match "*ziplist*" [r debug object hash]
|
||||||
|
assert_equal 2 [r hlen hash]
|
||||||
|
assert_match {v1 v2} [r hmget hash f1 f2]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
start_server [list overrides [list "dir" $server_path "dbfilename" "hash-zipmap.rdb" "hash-max-ziplist-entries" 1]] {
|
||||||
|
test "RDB load zipmap hash: converts to hash table when hash-max-ziplist-entries is exceeded" {
|
||||||
|
r select 0
|
||||||
|
|
||||||
|
assert_match "*hashtable*" [r debug object hash]
|
||||||
|
assert_equal 2 [r hlen hash]
|
||||||
|
assert_match {v1 v2} [r hmget hash f1 f2]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
start_server [list overrides [list "dir" $server_path "dbfilename" "hash-zipmap.rdb" "hash-max-ziplist-value" 1]] {
|
||||||
|
test "RDB load zipmap hash: converts to hash table when hash-max-ziplist-value is exceeded" {
|
||||||
|
r select 0
|
||||||
|
|
||||||
|
assert_match "*hashtable*" [r debug object hash]
|
||||||
|
assert_equal 2 [r hlen hash]
|
||||||
|
assert_match {v1 v2} [r hmget hash f1 f2]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user