This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new e4bf4ff7 Fix RESTORE check for zset2 object type (#1709)
e4bf4ff7 is described below

commit e4bf4ff7ff00515b7a0636313a9f61fd47f13822
Author: Binbin <[email protected]>
AuthorDate: Tue Aug 29 22:38:50 2023 +0800

    Fix RESTORE check for zset2 object type (#1709)
---
 src/storage/rdb.cc                        |  8 ++++----
 src/storage/rdb.h                         |  2 ++
 tests/gocase/unit/restore/restore_test.go | 11 +++++++++++
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/storage/rdb.cc b/src/storage/rdb.cc
index 5c8530c3..23ddb0d0 100644
--- a/src/storage/rdb.cc
+++ b/src/storage/rdb.cc
@@ -59,9 +59,9 @@ Status RDB::VerifyPayloadChecksum() {
   }
   auto footer = input_.substr(input_.size() - 10);
   auto rdb_version = (footer[1] << 8) | footer[0];
-  // For now, the max redis rdb version is 10
+  // For now, the max redis rdb version is 11
   if (rdb_version > 11) {
-    return {Status::NotOK, fmt::format("invalid version: {}", rdb_version)};
+    return {Status::NotOK, fmt::format("invalid or unsupported rdb version: 
{}", rdb_version)};
   }
   uint64_t crc = crc64(0, reinterpret_cast<const unsigned char 
*>(input_.data()), input_.size() - 8);
   memrev64ifbe(&crc);
@@ -76,10 +76,10 @@ StatusOr<int> RDB::LoadObjectType() {
   auto type = input_[pos_++] & 0xFF;
   // 0-5 is the basic type of Redis objects and 9-21 is the encoding type of 
Redis objects.
   // Redis allow basic is 0-7 and 6/7 is for the module type which we don't 
support here.
-  if ((type >= 0 && type < 5) || (type >= 9 && type <= 21)) {
+  if ((type >= 0 && type <= 5) || (type >= 9 && type <= 21)) {
     return type;
   }
-  return {Status::NotOK, fmt::format("invalid object type: {}", type)};
+  return {Status::NotOK, fmt::format("invalid or unsupported object type: {}", 
type)};
 }
 
 StatusOr<uint64_t> RDB::loadObjectLen(bool *is_encoded) {
diff --git a/src/storage/rdb.h b/src/storage/rdb.h
index 2ba306b5..956df034 100644
--- a/src/storage/rdb.h
+++ b/src/storage/rdb.h
@@ -32,6 +32,7 @@ constexpr const int RDBTypeSet = 2;
 constexpr const int RDBTypeZSet = 3;
 constexpr const int RDBTypeHash = 4;
 constexpr const int RDBTypeZSet2 = 5;
+// NOTE: when adding new Redis object type, update LoadObjectType.
 
 // Redis object encoding
 constexpr const int RDBTypeHashZipMap = 9;
@@ -46,6 +47,7 @@ constexpr const int RDBTypeZSetListPack = 17;
 constexpr const int RDBTypeListQuickList2 = 18;
 constexpr const int RDBTypeStreamListPack2 = 19;
 constexpr const int RDBTypeSetListPack = 20;
+// NOTE: when adding new Redis object encoding type, update LoadObjectType.
 
 // Quick list node encoding
 constexpr const int QuickListNodeContainerPlain = 1;
diff --git a/tests/gocase/unit/restore/restore_test.go 
b/tests/gocase/unit/restore/restore_test.go
index 0fa8b11a..140d43e5 100644
--- a/tests/gocase/unit/restore/restore_test.go
+++ b/tests/gocase/unit/restore/restore_test.go
@@ -120,6 +120,17 @@ func TestRestore_ZSet(t *testing.T) {
                }, rdb.ZRangeWithScores(ctx, key, 0, -1).Val())
        })
 
+       t.Run("ZSet2 object encoding", func(t *testing.T) {
+               key := util.RandString(32, 64, util.Alpha)
+               value := 
"\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"
+               require.NoError(t, rdb.Restore(ctx, key, 0, value).Err())
+               require.EqualValues(t, []redis.Z{
+                       {Member: "a", Score: 1.1},
+                       {Member: "b", Score: 2.2},
+                       {Member: "c", Score: 3.3},
+               }, rdb.ZRangeWithScores(ctx, key, 0, -1).Val())
+       })
+
        t.Run("List pack encoding", func(t *testing.T) {
                key := util.RandString(32, 64, util.Alpha)
                value := 
"\x11''\x00\x00\x00\x06\x00\x81a\x02\x831.2\x04\x81b\x02\x861234.5\a\x81c\x02\xf4\xd8Y`\xe0\x02\x00\x00\x00\t\xff\n\x00\xce\xfdp\xbdHN\xdbG"

Reply via email to