Skip to content

Commit 7db0a73

Browse files
committed
chore: RdbSerializer::SaveListObject supports QList
Now, `./rdb_test --list_experimental_v2` passes. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
1 parent 75c961e commit 7db0a73

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/core/qlist.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,16 @@ class QList {
109109
// Requires calling subsequent Next() to initialize the iterator.
110110
Iterator GetIterator(long idx) const;
111111

112-
uint32_t noded_count() const {
112+
uint32_t node_count() const {
113113
return len_;
114114
}
115115

116116
Iterator Erase(Iterator it);
117117

118+
const quicklistNode* Head() const {
119+
return head_;
120+
}
121+
118122
private:
119123
bool AllowCompression() const {
120124
return compress_ != 0;

src/server/rdb_save.cc

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C" {
2929
#include "base/logging.h"
3030
#include "core/bloom.h"
3131
#include "core/json/json_object.h"
32+
#include "core/qlist.h"
3233
#include "core/size_tracking_channel.h"
3334
#include "core/sorted_map.h"
3435
#include "core/string_map.h"
@@ -168,12 +169,10 @@ uint8_t RdbObjectType(const PrimeValue& pv) {
168169
case OBJ_STRING:
169170
return RDB_TYPE_STRING;
170171
case OBJ_LIST:
171-
if (compact_enc == OBJ_ENCODING_QUICKLIST) {
172-
if (absl::GetFlag(FLAGS_list_rdb_encode_v2))
173-
return RDB_TYPE_LIST_QUICKLIST_2;
174-
return RDB_TYPE_LIST_QUICKLIST;
172+
if (compact_enc == OBJ_ENCODING_QUICKLIST || compact_enc == kEncodingQL2) {
173+
return absl::GetFlag(FLAGS_list_rdb_encode_v2) ? RDB_TYPE_LIST_QUICKLIST_2
174+
: RDB_TYPE_LIST_QUICKLIST;
175175
}
176-
177176
break;
178177
case OBJ_SET:
179178
if (compact_enc == kEncodingIntSet)
@@ -436,12 +435,21 @@ error_code RdbSerializer::SaveObject(const PrimeValue& pv) {
436435

437436
error_code RdbSerializer::SaveListObject(const PrimeValue& pv) {
438437
/* Save a list value */
439-
DCHECK_EQ(OBJ_ENCODING_QUICKLIST, pv.Encoding());
440-
const quicklist* ql = reinterpret_cast<const quicklist*>(pv.RObjPtr());
441-
quicklistNode* node = ql->head;
442-
DVLOG(2) << "Saving list of length " << ql->len;
443-
444-
RETURN_ON_ERR(SaveLen(ql->len));
438+
size_t len = 0;
439+
const quicklistNode* node = nullptr;
440+
441+
if (pv.Encoding() == OBJ_ENCODING_QUICKLIST) {
442+
const quicklist* ql = reinterpret_cast<const quicklist*>(pv.RObjPtr());
443+
node = ql->head;
444+
DVLOG(2) << "Saving list of length " << ql->len;
445+
len = ql->len;
446+
} else {
447+
DCHECK_EQ(pv.Encoding(), kEncodingQL2);
448+
QList* ql = reinterpret_cast<QList*>(pv.RObjPtr());
449+
node = ql->Head();
450+
len = ql->noded_count();
451+
}
452+
RETURN_ON_ERR(SaveLen(len));
445453

446454
while (node) {
447455
DVLOG(3) << "QL node (encoding/container/sz): " << node->encoding << "/" << node->container
@@ -759,7 +767,7 @@ error_code RdbSerializer::SaveListPackAsZiplist(uint8_t* lp) {
759767
return ec;
760768
}
761769

762-
error_code RdbSerializer::SavePlainNodeAsZiplist(quicklistNode* node) {
770+
error_code RdbSerializer::SavePlainNodeAsZiplist(const quicklistNode* node) {
763771
uint8_t* zl = ziplistNew();
764772
zl = ziplistPush(zl, node->entry, node->sz, ZIPLIST_TAIL);
765773

src/server/rdb_save.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class RdbSerializer : public SerializerBase {
255255
std::error_code SaveListPackAsZiplist(uint8_t* lp);
256256
std::error_code SaveStreamPEL(rax* pel, bool nacks);
257257
std::error_code SaveStreamConsumers(streamCG* cg);
258-
std::error_code SavePlainNodeAsZiplist(quicklistNode* node);
258+
std::error_code SavePlainNodeAsZiplist(const quicklistNode* node);
259259

260260
// Might preempt
261261
void FlushIfNeeded(FlushState flush_state);

0 commit comments

Comments
 (0)