pmem / kvdk

Key Value Development Kit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Key is accessible througth iterator after deletion

karczex opened this issue · comments

In the code below I create collection with one element using SSet(), and than I delete this element. When I call SGet()' on such element, the status is NotFound, and everything seems to be OK. However If I try to seek such element through iterator (both Seek()andSeekToFirst()`), I may get it with empty string as a value - so when I use iterator I cannot distinct deleted element from element with empty string as value.

TEST_F(EngineBasicTest, TestSeekToFirst) {

  const std::string collection = "col";
  std::string val;
  ASSERT_EQ(Engine::Open(db_path.c_str(), &engine, configs, stdout),
            Status::Ok);
   ASSERT_EQ(engine->SSet(collection, "foo" , "bar"), Status::Ok);
   ASSERT_EQ(engine->SGet(collection, "foo", &val), Status::Ok);
   ASSERT_EQ(engine->SDelete(collection, "foo"), Status::Ok);
   ASSERT_EQ(engine->SGet(collection, "foo", &val), Status::NotFound);
   auto iter = engine->NewSortedIterator(collection);
   ASSERT_NE(iter, nullptr);
   iter->SeekToFirst();
   if(iter->Valid()) {
	   std::cout << iter->Key() << std::endl;
	   std::cout << iter->Value() << std::endl;
   }
}

Test output:

localhost/kvdk:build# PMEM_IS_PMEM_FORCE=1 ./dbtest --gtest_filter="*SeekToFirst*"
Note: Google Test filter = *SeekToFirst*
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from EngineBasicTest
[ RUN      ] EngineBasicTest.TestSeekToFirst
[LOG] time 0 ms: Initializing PMEM size 17179869184 in file /mnt/pmem0/data/data
[LOG] time 1977 ms: Map pmem space done
[LOG] time 1979 ms: In restoring: iterated 0 records
foo

[       OK ] EngineBasicTest.TestSeekToFirst (2034 ms)
[----------] 1 test from EngineBasicTest (2034 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (2034 ms total)
[  PASSED  ] 1 test.

I may workaround this problem by calling additional SGet() after each SeekToFirst(), but it would be much more intuitive, less error prone and probably faster if such iterator would be invalid after removal of all elements in collection.

Thank you for file this bug. It is fixed with commit: 93a3bc7