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

git-hulk 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 3c927b2fc fix(storage): compare namespace of the other key in 
InternalKey::operator== (#3659)
3c927b2fc is described below

commit 3c927b2fcc2b872f3467b977fc2d242786e9157b
Author: weimeng <[email protected]>
AuthorDate: Thu Oct 8 15:52:24 2026 +0800

    fix(storage): compare namespace of the other key in InternalKey::operator== 
(#3659)
    
    Fix a copy-paste bug in `InternalKey::operator==` where the namespace
    comparison
    compared the object's own `namespace_` against itself
    (`this->namespace_`) instead
    of `that.namespace_`, making the check always pass.
    
    ## Root Cause
    
    In `src/storage/redis_metadata.cc`, line 100:
    
    ```cpp
    if (namespace_ != this->namespace_) return false;
    
    Co-authored-by: weimeng <[email protected]>
---
 src/storage/redis_metadata.cc  |  2 +-
 tests/cppunit/metadata_test.cc | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/storage/redis_metadata.cc b/src/storage/redis_metadata.cc
index 2aecfdab5..f0e0cb544 100644
--- a/src/storage/redis_metadata.cc
+++ b/src/storage/redis_metadata.cc
@@ -97,7 +97,7 @@ std::string InternalKey::Encode() const {
 }
 
 bool InternalKey::operator==(const InternalKey &that) const {
-  if (namespace_ != this->namespace_) return false;
+  if (namespace_ != that.namespace_) return false;
   if (key_ != that.key_) return false;
   if (sub_key_ != that.sub_key_) return false;
   return version_ == that.version_;
diff --git a/tests/cppunit/metadata_test.cc b/tests/cppunit/metadata_test.cc
index 146ac4739..53036ce6a 100644
--- a/tests/cppunit/metadata_test.cc
+++ b/tests/cppunit/metadata_test.cc
@@ -44,6 +44,25 @@ TEST(InternalKey, EncodeAndDecode) {
   EXPECT_EQ(ikey, ikey1);
 }
 
+TEST(InternalKey, EqualityAcrossNamespaces) {
+  Slice key = "test-key";
+  Slice sub_key = "test-sub-key";
+  uint64_t version = 42;
+
+  std::string ns_key_a = ComposeNamespaceKey("ns_a", key, false);
+  std::string ns_key_b = ComposeNamespaceKey("ns_b", key, false);
+
+  InternalKey a(ns_key_a, sub_key, version, false);
+  InternalKey b(ns_key_b, sub_key, version, false);
+
+  // Same key/sub_key/version but different namespace must not be equal
+  EXPECT_NE(a, b);
+
+  // Same namespace should still be equal
+  InternalKey a2(ns_key_a, sub_key, version, false);
+  EXPECT_EQ(a, a2);
+}
+
 TEST(Metadata, EncodeAndDecode) {
   std::string string_bytes;
   Metadata string_md(kRedisString);

Reply via email to