Skip to content

Commit d35e16f

Browse files
committed
chore: remove old ZIPLIST encoding during snapshotting
ZIPLIST encoding is an legacy format for Redis 6 or older. We stop saving using ZIPLIST but we still support loading snapshots containing ziplist encodings. Fixes #4544 Signed-off-by: Roman Gershman <roman@dragonflydb.io>
1 parent 7842c87 commit d35e16f

File tree

3 files changed

+13
-50
lines changed

3 files changed

+13
-50
lines changed

src/server/rdb_load.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ void RdbLoaderBase::OpaqueObjLoader::HandleBlob(string_view blob) {
916916
} else if (rdb_type_ == RDB_TYPE_HASH_ZIPLIST || rdb_type_ == RDB_TYPE_HASH_LISTPACK) {
917917
unsigned char* lp = lpNew(blob.size());
918918
switch (rdb_type_) {
919-
case RDB_TYPE_HASH_ZIPLIST:
919+
case RDB_TYPE_HASH_ZIPLIST: // legacy format
920920
if (!ziplistPairsConvertAndValidateIntegrity((const uint8_t*)blob.data(), blob.size(),
921921
&lp)) {
922922
LOG(ERROR) << "Zset ziplist integrity check failed.";
@@ -951,7 +951,7 @@ void RdbLoaderBase::OpaqueObjLoader::HandleBlob(string_view blob) {
951951
pv_->InitRobj(OBJ_HASH, kEncodingListPack, lp);
952952
}
953953
return;
954-
} else if (rdb_type_ == RDB_TYPE_ZSET_ZIPLIST) {
954+
} else if (rdb_type_ == RDB_TYPE_ZSET_ZIPLIST) { // legacy format
955955
unsigned char* lp = lpNew(blob.size());
956956
if (!ziplistPairsConvertAndValidateIntegrity((uint8_t*)blob.data(), blob.size(), &lp)) {
957957
LOG(ERROR) << "Zset ziplist integrity check failed.";

src/server/rdb_save.cc

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern "C" {
1818
#include "redis/rdb.h"
1919
#include "redis/stream.h"
2020
#include "redis/util.h"
21-
#include "redis/ziplist.h"
2221
#include "redis/zmalloc.h"
2322
#include "redis/zset.h"
2423
}
@@ -49,15 +48,9 @@ ABSL_FLAG(dfly::CompressionMode, compression_mode, dfly::CompressionMode::MULTI_
4948
"set 2 for multi entry zstd compression on df snapshot and single entry on rdb snapshot,"
5049
"set 3 for multi entry lz4 compression on df snapshot and single entry on rdb snapshot");
5150

52-
ABSL_RETIRED_FLAG(
53-
bool, list_rdb_encode_v2, true,
54-
"V2 rdb encoding of list uses listpack encoding format, compatible with redis 7. V1 rdb "
55-
"enconding of list uses ziplist encoding compatible with redis 6");
56-
5751
// TODO: to retire this flag in v1.31
58-
ABSL_FLAG(bool, stream_rdb_encode_v2, true,
59-
"V2 uses format, compatible with redis 7.2 and Dragonfly v1.26+, while v1 format "
60-
"is compatible with redis 6");
52+
ABSL_RETIRED_FLAG(bool, stream_rdb_encode_v2, true,
53+
"Retired. Uses format, compatible with redis 7.2 and Dragonfly v1.26+");
6154

6255
namespace dfly {
6356

@@ -189,13 +182,13 @@ uint8_t RdbObjectType(const PrimeValue& pv) {
189182
break;
190183
case OBJ_ZSET:
191184
if (compact_enc == OBJ_ENCODING_LISTPACK)
192-
return RDB_TYPE_ZSET_ZIPLIST; // we save using the old ziplist encoding.
185+
return RDB_TYPE_ZSET_LISTPACK;
193186
else if (compact_enc == OBJ_ENCODING_SKIPLIST)
194187
return RDB_TYPE_ZSET_2;
195188
break;
196189
case OBJ_HASH:
197190
if (compact_enc == kEncodingListPack)
198-
return RDB_TYPE_HASH_ZIPLIST;
191+
return RDB_TYPE_HASH_LISTPACK;
199192
else if (compact_enc == kEncodingStrMap2) {
200193
if (((StringMap*)pv.RObjPtr())->ExpirationUsed())
201194
return RDB_TYPE_HASH_WITH_EXPIRY; // Incompatible with Redis
@@ -204,8 +197,7 @@ uint8_t RdbObjectType(const PrimeValue& pv) {
204197
}
205198
break;
206199
case OBJ_STREAM:
207-
return absl::GetFlag(FLAGS_stream_rdb_encode_v2) ? RDB_TYPE_STREAM_LISTPACKS_3
208-
: RDB_TYPE_STREAM_LISTPACKS;
200+
return RDB_TYPE_STREAM_LISTPACKS_3;
209201
case OBJ_MODULE:
210202
return RDB_TYPE_MODULE_2;
211203
case OBJ_JSON:
@@ -459,7 +451,8 @@ error_code RdbSerializer::SaveHSetObject(const PrimeValue& pv) {
459451
CHECK_EQ(kEncodingListPack, pv.Encoding());
460452

461453
uint8_t* lp = (uint8_t*)pv.RObjPtr();
462-
RETURN_ON_ERR(SaveListPackAsZiplist(lp));
454+
size_t lp_bytes = lpBytes(lp);
455+
RETURN_ON_ERR(SaveString((uint8_t*)lp, lp_bytes));
463456
}
464457

465458
return error_code{};
@@ -496,9 +489,11 @@ error_code RdbSerializer::SaveZSetObject(const PrimeValue& pv) {
496489
return true;
497490
});
498491
} else {
499-
CHECK_EQ(pv.Encoding(), unsigned(OBJ_ENCODING_LISTPACK)) << "Unknown zset encoding";
492+
CHECK_EQ(pv.Encoding(), unsigned(OBJ_ENCODING_LISTPACK));
500493
uint8_t* lp = (uint8_t*)robj_wrapper->inner_obj();
501-
RETURN_ON_ERR(SaveListPackAsZiplist(lp));
494+
size_t lp_bytes = lpBytes(lp);
495+
496+
RETURN_ON_ERR(SaveString((uint8_t*)lp, lp_bytes));
502497
}
503498

504499
return error_code{};
@@ -665,36 +660,6 @@ error_code RdbSerializer::SaveBinaryDouble(double val) {
665660
return WriteRaw(Bytes{buf, sizeof(buf)});
666661
}
667662

668-
error_code RdbSerializer::SaveListPackAsZiplist(uint8_t* lp) {
669-
uint8_t* lpfield = lpFirst(lp);
670-
int64_t entry_len;
671-
uint8_t* entry;
672-
uint8_t buf[32];
673-
uint8_t* zl = ziplistNew();
674-
675-
while (lpfield) {
676-
entry = lpGet(lpfield, &entry_len, buf);
677-
zl = ziplistPush(zl, entry, entry_len, ZIPLIST_TAIL);
678-
lpfield = lpNext(lp, lpfield);
679-
}
680-
size_t ziplen = ziplistBlobLen(zl);
681-
error_code ec = SaveString(string_view{reinterpret_cast<char*>(zl), ziplen});
682-
zfree(zl);
683-
684-
return ec;
685-
}
686-
687-
error_code RdbSerializer::SavePlainNodeAsZiplist(const quicklistNode* node) {
688-
uint8_t* zl = ziplistNew();
689-
zl = ziplistPush(zl, node->entry, node->sz, ZIPLIST_TAIL);
690-
691-
size_t ziplen = ziplistBlobLen(zl);
692-
error_code ec = SaveString(string_view{reinterpret_cast<char*>(zl), ziplen});
693-
zfree(zl);
694-
695-
return ec;
696-
}
697-
698663
error_code RdbSerializer::SaveStreamPEL(rax* pel, bool nacks) {
699664
/* Number of entries in the PEL. */
700665

src/server/rdb_save.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,8 @@ class RdbSerializer : public SerializerBase {
255255

256256
std::error_code SaveLongLongAsString(int64_t value);
257257
std::error_code SaveBinaryDouble(double val);
258-
std::error_code SaveListPackAsZiplist(uint8_t* lp);
259258
std::error_code SaveStreamPEL(rax* pel, bool nacks);
260259
std::error_code SaveStreamConsumers(bool save_active, streamCG* cg);
261-
std::error_code SavePlainNodeAsZiplist(const quicklistNode* node);
262260

263261
// Might preempt
264262
void FlushIfNeeded(FlushState flush_state);

0 commit comments

Comments
 (0)