pmem / kvdk

Key Value Development Kit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid iterator for key which contains only zeroes

karczex opened this issue · comments

It's possible to SSet() and SGet() element which contains only zeroes as key, but iterator for such element is invalid.

 /* Create a string that contains 8 bytes from uint64_t. */
  static inline std::string uint64_to_string(uint64_t &key) {
    return std::string(reinterpret_cast<const char *>(&key), 8);
  }

TEST_F(EngineBasicTest, TestSeekZeroedKey) {

  const std::string collection = "col";
  std::string val;
  ASSERT_EQ(Engine::Open(db_path.c_str(), &engine, configs, stdout),
            Status::Ok);

  uint64_t z = 0;
  auto zero_filled_str = uint64_to_string(z);

  ASSERT_EQ(engine->SSet(collection, zero_filled_str, zero_filled_str), Status::Ok);
  ASSERT_EQ(engine->SGet(collection, zero_filled_str, &val), Status::Ok);
  auto iter = engine->NewSortedIterator(collection);
  ASSERT_NE(iter, nullptr);
  iter->Seek(zero_filled_str);
  ASSERT_TRUE(iter->Valid());
}
root@3d4f55155e2e:/opt/workspace/kvdk/build# PMEM_IS_PMEM_FORCE=1 ./dbtest --gtest_filter=*TestSeekZeroedKey*
Note: Google Test filter = *TestSeekZeroedKey*
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from EngineBasicTest
[ RUN      ] EngineBasicTest.TestSeekZeroedKey
[LOG] time 0 ms: Initializing PMem size 17179869184 in file /mnt/pmem0/data/data
[LOG] time 2399 ms: Map pmem space done
[LOG] time 2402 ms: In restoring: iterated 0 records
/opt/workspace/kvdk/tests/tests.cpp:91: Failure
Value of: iter->Valid()
  Actual: false
Expected: true
[  FAILED  ] EngineBasicTest.TestSeekZeroedKey (2457 ms)
[----------] 1 test from EngineBasicTest (2457 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (2457 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] EngineBasicTest.TestSeekZeroedKey

 1 FAILED TEST

Thank you, bug fixed at #41