Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): use listpack node encoding for list #3914

Merged
merged 6 commits into from
Oct 15, 2024
Merged

Conversation

adiholden
Copy link
Collaborator

Until now encoding of list was using ziplist encoding, which is supported by redis 6
This PR introduces encoding of list using listpack encoding by default (supported by redis 7), optionally change the encoding to ziplist encoding using flag.
This PR also fixes a bug: when serializing big entry of list it was serialized as plain node using lispack encoding therefore when loading the rdb we got error. By moving encoding all the list nodes to listpack encoding we fix this bug.

@adiholden adiholden requested review from romange and chakaz October 13, 2024 08:43
@@ -439,7 +444,8 @@ error_code RdbSerializer::SaveListObject(const PrimeValue& pv) {
DVLOG(3) << "QL node (encoding/container/sz): " << node->encoding << "/" << node->container
<< "/" << node->sz;

if (QL_NODE_IS_PLAIN(node)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I still need to fix the way we serialize plane node when list_rdb_encode_v2=false

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I talked to @chakaz about this and suggested to create an appropriate dump by redis 6 and add it to our rdb_test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adiholden asked me to look into adding a full redis 7 replication test, in addition to our existing redis 6 one
that should be a superset (well, almost) of what you asked for

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have replication tests with redis server which include list type, this is checking the rdb load logic in dfly
we can add there big values if needed

@romange
Copy link
Collaborator

romange commented Oct 13, 2024

have not checked the code but It is important that we still be able to load redis-6 rdb files and old DF snapshots with ziplist encoding unrelated to the flag.

chakaz
chakaz previously approved these changes Oct 13, 2024
@@ -439,7 +444,8 @@ error_code RdbSerializer::SaveListObject(const PrimeValue& pv) {
DVLOG(3) << "QL node (encoding/container/sz): " << node->encoding << "/" << node->container
<< "/" << node->sz;

if (QL_NODE_IS_PLAIN(node)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adiholden asked me to look into adding a full redis 7 replication test, in addition to our existing redis 6 one
that should be a superset (well, almost) of what you asked for

@@ -49,6 +49,7 @@ ABSL_FLAG(dfly::CompressionMode, compression_mode, dfly::CompressionMode::MULTI_
"set 2 for multi entry zstd compression on df snapshot and single entry on rdb snapshot,"
"set 3 for multi entry lz4 compression on df snapshot and single entry on rdb snapshot");
ABSL_FLAG(int, compression_level, 2, "The compression level to use on zstd/lz4 compression");
ABSL_FLAG(bool, list_rdb_encode_v2, true, "Use v2 rdb encoding of list object");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we run the list unit tests once with this true and once with false?
also, didn't you say you wanted the default to be false for this? (I could have misunderstood you, it's find to be true if you want it to be such)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also^2: I thought you wanted this flag to be toggleable at runtime (i.e. via CONFIG), is it not the case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we need to toggle it - our cloud service does not require redis-6 RDB compatibility.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see config_registry.RegisterMutable in server_family you can set the flag in runtime
I wanted the defualt to be true, I dont see a reason to convert listpack to ziplist encoding

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to run the unit test with flag false I need need first to fix the issue with encoding of big list entry with the ziplist encoding

**BASIC_ARGS,
"proactor_threads": 4,
"dbfilename": "test-redis-load-rdb",
"list_rdb_encode_v2": "false",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"list_rdb_encode_v2": "false",
"list_rdb_encode_v2": "false", # Needed for compatibility with Redis 6

@chakaz
Copy link
Collaborator

chakaz commented Oct 13, 2024

have not checked the code but It is important that we still be able to load redis-6 rdb files and old DF snapshots with ziplist encoding unrelated to the flag.

This is indeed what @adiholden did 🤓

@adiholden
Copy link
Collaborator Author

have not checked the code but It is important that we still be able to load redis-6 rdb files and old DF snapshots with ziplist encoding unrelated to the flag.

@romange This PR only changes the default way we encode lists

@romange
Copy link
Collaborator

romange commented Oct 13, 2024

Please verify that RDB files that are created by DF with large list entries can be loaded by Redis 7 when this flag is on.
(I assume due to the bug, Redis 6 won't be able to load the rdb with this flag off).

@adiholden
Copy link
Collaborator Author

Please verify that RDB files that are created by DF with large list entries can be loaded by Redis 7 when this flag is on. (I assume due to the bug, Redis 6 won't be able to load the rdb with this flag off).

Shahar run the test_redis_load_snapshot with redis 7 and with the flag list_rdb_encode_v2 set to true and the test passed.
Now the bug is fixed and redis 6 can load the rdb file with big list entry when the flag is set to false, the tests test_redis_load_snapshot covers this

if (container == QUICKLIST_NODE_CONTAINER_PLAIN) {
quicklistAppendPlainNode(ql, (uint8_t*)sv.data(), sv.size());
lp = (uint8_t*)zmalloc(sv.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that Roman is implying that this is a nasty bug :)

@@ -49,6 +49,7 @@ ABSL_FLAG(dfly::CompressionMode, compression_mode, dfly::CompressionMode::MULTI_
"set 2 for multi entry zstd compression on df snapshot and single entry on rdb snapshot,"
"set 3 for multi entry lz4 compression on df snapshot and single entry on rdb snapshot");
ABSL_FLAG(int, compression_level, 2, "The compression level to use on zstd/lz4 compression");
ABSL_FLAG(bool, list_rdb_encode_v2, true, "Use v2 rdb encoding of list object");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please improve help string of the flag. whats is v2 rdb encoding? when the flag is true what we are compatible with?

@@ -861,6 +861,7 @@ void ServerFamily::Init(util::AcceptServer* acceptor, std::vector<facade::Listen
config_registry.RegisterMutable("tls_ca_cert_dir");
config_registry.RegisterMutable("replica_priority");
config_registry.RegisterMutable("lua_undeclared_keys_shas");
config_registry.RegisterMutable("list_rdb_encode_v2");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need, imho

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have any prod issues with the new impl we will be able to recover

@@ -150,7 +150,14 @@ async def test_dbfilenames(


@pytest.mark.asyncio
@dfly_args({**BASIC_ARGS, "proactor_threads": 4, "dbfilename": "test-redis-load-rdb"})
@dfly_args(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not in rdb_test.cc ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a python test that checks that redis can load dragonfly snapshot. what do you want to put in rdb_test.cc?

Copy link
Collaborator

@romange romange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment on lines +27 to +28
ABSL_DECLARE_FLAG(bool, list_rdb_encode_v2);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer, you could also use SetTestFlag("list_rdb_encode_v2", "false"); and not declare this flag
if doesn't really matter in any way, so your call

if (container == QUICKLIST_NODE_CONTAINER_PLAIN) {
quicklistAppendPlainNode(ql, (uint8_t*)sv.data(), sv.size());
lp = (uint8_t*)zmalloc(sv.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that Roman is implying that this is a nasty bug :)

Signed-off-by: adi_holden <[email protected]>
Signed-off-by: adi_holden <[email protected]>
Signed-off-by: adi_holden <[email protected]>
Signed-off-by: adi_holden <[email protected]>
@adiholden adiholden force-pushed the list_v2_rdb_encoding branch from 29d8430 to 644cb14 Compare October 15, 2024 09:44
@adiholden adiholden merged commit a1830e1 into main Oct 15, 2024
12 checks passed
@adiholden adiholden deleted the list_v2_rdb_encoding branch October 15, 2024 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants