Skip to content

Commit 3bb0337

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 3bb0337

File tree

3 files changed

+13
-37
lines changed

3 files changed

+13
-37
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 & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,9 @@ ABSL_FLAG(dfly::CompressionMode, compression_mode, dfly::CompressionMode::MULTI_
4949
"set 2 for multi entry zstd compression on df snapshot and single entry on rdb snapshot,"
5050
"set 3 for multi entry lz4 compression on df snapshot and single entry on rdb snapshot");
5151

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-
5752
// 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");
53+
ABSL_RETIRED_FLAG(bool, stream_rdb_encode_v2, true,
54+
"Retired. Uses format, compatible with redis 7.2 and Dragonfly v1.26+");
6155

6256
namespace dfly {
6357

@@ -189,13 +183,13 @@ uint8_t RdbObjectType(const PrimeValue& pv) {
189183
break;
190184
case OBJ_ZSET:
191185
if (compact_enc == OBJ_ENCODING_LISTPACK)
192-
return RDB_TYPE_ZSET_ZIPLIST; // we save using the old ziplist encoding.
186+
return RDB_TYPE_ZSET_LISTPACK;
193187
else if (compact_enc == OBJ_ENCODING_SKIPLIST)
194188
return RDB_TYPE_ZSET_2;
195189
break;
196190
case OBJ_HASH:
197191
if (compact_enc == kEncodingListPack)
198-
return RDB_TYPE_HASH_ZIPLIST;
192+
return RDB_TYPE_HASH_LISTPACK;
199193
else if (compact_enc == kEncodingStrMap2) {
200194
if (((StringMap*)pv.RObjPtr())->ExpirationUsed())
201195
return RDB_TYPE_HASH_WITH_EXPIRY; // Incompatible with Redis
@@ -204,8 +198,7 @@ uint8_t RdbObjectType(const PrimeValue& pv) {
204198
}
205199
break;
206200
case OBJ_STREAM:
207-
return absl::GetFlag(FLAGS_stream_rdb_encode_v2) ? RDB_TYPE_STREAM_LISTPACKS_3
208-
: RDB_TYPE_STREAM_LISTPACKS;
201+
return RDB_TYPE_STREAM_LISTPACKS_3;
209202
case OBJ_MODULE:
210203
return RDB_TYPE_MODULE_2;
211204
case OBJ_JSON:
@@ -459,7 +452,8 @@ error_code RdbSerializer::SaveHSetObject(const PrimeValue& pv) {
459452
CHECK_EQ(kEncodingListPack, pv.Encoding());
460453

461454
uint8_t* lp = (uint8_t*)pv.RObjPtr();
462-
RETURN_ON_ERR(SaveListPackAsZiplist(lp));
455+
size_t lp_bytes = lpBytes(lp);
456+
RETURN_ON_ERR(SaveString((uint8_t*)lp, lp_bytes));
463457
}
464458

465459
return error_code{};
@@ -496,9 +490,11 @@ error_code RdbSerializer::SaveZSetObject(const PrimeValue& pv) {
496490
return true;
497491
});
498492
} else {
499-
CHECK_EQ(pv.Encoding(), unsigned(OBJ_ENCODING_LISTPACK)) << "Unknown zset encoding";
493+
CHECK_EQ(pv.Encoding(), unsigned(OBJ_ENCODING_LISTPACK));
500494
uint8_t* lp = (uint8_t*)robj_wrapper->inner_obj();
501-
RETURN_ON_ERR(SaveListPackAsZiplist(lp));
495+
size_t lp_bytes = lpBytes(lp);
496+
497+
RETURN_ON_ERR(SaveString((uint8_t*)lp, lp_bytes));
502498
}
503499

504500
return error_code{};
@@ -665,25 +661,6 @@ error_code RdbSerializer::SaveBinaryDouble(double val) {
665661
return WriteRaw(Bytes{buf, sizeof(buf)});
666662
}
667663

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-
687664
error_code RdbSerializer::SavePlainNodeAsZiplist(const quicklistNode* node) {
688665
uint8_t* zl = ziplistNew();
689666
zl = ziplistPush(zl, node->entry, node->sz, ZIPLIST_TAIL);

src/server/rdb_save.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ 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);
261260
std::error_code SavePlainNodeAsZiplist(const quicklistNode* node);

0 commit comments

Comments
 (0)