apache / kvrocks

Apache Kvrocks is a distributed key value NoSQL database that uses RocksDB as storage engine and is compatible with Redis protocol.
https://kvrocks.apache.org/
Apache License 2.0
3.56k stars 467 forks source link

Inconsistent behavior when using RESTORE with dumped negative integers #2546

Closed fstd2 closed 1 month ago

fstd2 commented 1 month ago

Search before asking

Version

2.9.0

Minimal reproduce step

127.0.0.1:6666> set k -1
OK
127.0.0.1:6666> get k
"-1"
127.0.0.1:6666> dump k
"\x00\xc0\xff\x06\x00\x9a~\x16\xa4p]\xa1V"
127.0.0.1:6666> restore k1 0 "\x00\xc0\xff\x06\x00\x9a~\x16\xa4p]\xa1V"
OK
127.0.0.1:6666> get k1
"255"
127.0.0.1:6666> get k
"-1"
127.0.0.1:6666> set k2 -2
OK
127.0.0.1:6666> get k2
"-2"
127.0.0.1:6666> dump k2
"\x00\xc0\xfe\x06\x00$FVjY\x0c\xb3\xa2"
127.0.0.1:6666> restore k22 0 "\x00\xc0\xfe\x06\x00$FVjY\x0c\xb3\xa2"
OK
127.0.0.1:6666> get k2
"-2"
127.0.0.1:6666> get k22
"254"

What did you expect to see?

The value remains negative after RESTORE.

What did you see instead?

when restoring dumped negative integers, the values are restored as positive numbers (255 for -1 and 254 for -2).

Anything Else?

Possibly a problem with the following code?

https://github.com/apache/kvrocks/blob/2a0c57ac7fc4499a210bc452884025a0010cb470/src/storage/rdb.cc#L158-L160

Are you willing to submit a PR?

git-hulk commented 1 month ago

@fstd2 Good catch. Would you like to fix this?

fstd2 commented 1 month ago

@git-hulk I'll try.

https://github.com/apache/kvrocks/pull/2547