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

Fix RESTORE check for zset2 object type #1709

Merged
merged 2 commits into from
Aug 29, 2023

Conversation

enjoy-binbin
Copy link
Member

Zset2 object type is 5, and we wrongly skipped it,
as a result we cannot recover normal zset data (zset
version 2 is doubles stored in binary):

127.0.0.1:6379> zadd key 1.1 a 2.2 b 3.3 c
(integer) 3
127.0.0.1:6379> object encoding key
"skiplist"
127.0.0.1:6379> dump key
"\x05\x03\x01cffffff\n@\x01b\x9a\x99\x99\x99\x99\x99\x01@\x01a\x9a\x99\x99\x99\x99\x99\xf1?\x0b\x00\x15\xae\xd7&\xda\x10\xe1\x03"

127.0.0.1:6666> restore zset 0 "\x05\x03\x01cffffff\n@\x01b\x9a\x99\x99\x99\x99\x99\x01@\x01a\x9a\x99\x99\x99\x99\x99\xf1?\x0b\x00\x15\xae\xd7&\xda\x10\xe1\x03"
(error) ERR invalid object type: 5

After the fix (although it seems we have some precision issues):

127.0.0.1:6379> restore zset 0 "\x05\x03\x01cffffff\n@\x01b\x9a\x99\x99\x99\x99\x99\x01@\x01a\x9a\x99\x99\x99\x99\x99\xf1?\x0b\x00\x15\xae\xd7&\xda\x10\xe1\x03"
OK
127.0.0.1:6379> zrange zset 0 -1 withscores
1) "a"
2) "1.1"
3) "b"
4) "2.2"
5) "c"
6) "3.3"

127.0.0.1:6666> restore zset 0 "\x05\x03\x01cffffff\n@\x01b\x9a\x99\x99\x99\x99\x99\x01@\x01a\x9a\x99\x99\x99\x99\x99\xf1?\x0b\x00\x15\xae\xd7&\xda\x10\xe1\x03"
OK
127.0.0.1:6666> zrange zset 0 -1 withscores
1) "a"
2) "1.1000000000000001"
3) "b"
4) "2.2000000000000002"
5) "c"
6) "3.2999999999999998"

In addition, i updated the error message to mention unsupported
word, this will feel more friendly.

Zset2 object type is 5, and we wrongly skipped it,
as a result we cannot recover normal zset data (zset
version 2 is doubles stored in binary):
```
127.0.0.1:6379> zadd key 1.1 a 2.2 b 3.3 c
(integer) 3
127.0.0.1:6379> object encoding key
"skiplist"
127.0.0.1:6379> dump key
"\x05\x03\x01cffffff\n@\x01b\x9a\x99\x99\x99\x99\x99\x01@\x01a\x9a\x99\x99\x99\x99\x99\xf1?\x0b\x00\x15\xae\xd7&\xda\x10\xe1\x03"

127.0.0.1:6666> restore zset 0 "\x05\x03\x01cffffff\n@\x01b\x9a\x99\x99\x99\x99\x99\x01@\x01a\x9a\x99\x99\x99\x99\x99\xf1?\x0b\x00\x15\xae\xd7&\xda\x10\xe1\x03"
(error) ERR invalid object type: 5
```

After the fix (although it seems we have some precision issues):
```
127.0.0.1:6379> restore zset 0 "\x05\x03\x01cffffff\n@\x01b\x9a\x99\x99\x99\x99\x99\x01@\x01a\x9a\x99\x99\x99\x99\x99\xf1?\x0b\x00\x15\xae\xd7&\xda\x10\xe1\x03"
OK
127.0.0.1:6379> zrange zset 0 -1 withscores
1) "a"
2) "1.1"
3) "b"
4) "2.2"
5) "c"
6) "3.3"

127.0.0.1:6666> restore zset 0 "\x05\x03\x01cffffff\n@\x01b\x9a\x99\x99\x99\x99\x99\x01@\x01a\x9a\x99\x99\x99\x99\x99\xf1?\x0b\x00\x15\xae\xd7&\xda\x10\xe1\x03"
OK
127.0.0.1:6666> zrange zset 0 -1 withscores
1) "a"
2) "1.1000000000000001"
3) "b"
4) "2.2000000000000002"
5) "c"
6) "3.2999999999999998"
```

In addition, i updated the error message to mention unsupported
word, this will feel more friendly.
Copy link
Member

@git-hulk git-hulk left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for @enjoy-binbin taking care of this.

@PragmaTwice PragmaTwice merged commit e4bf4ff into apache:unstable Aug 29, 2023
26 checks passed
@enjoy-binbin enjoy-binbin deleted the fix_restore_zset2 branch August 30, 2023 02:15
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.

4 participants