Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key is accessible througth iterator after deletion #28

Closed
karczex opened this issue Aug 25, 2021 · 1 comment
Closed

Key is accessible througth iterator after deletion #28

karczex opened this issue Aug 25, 2021 · 1 comment

Comments

@karczex
Copy link

karczex commented Aug 25, 2021

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.

peifengsi added a commit that referenced this issue Aug 26, 2021
Signed-off-by: peifeng.si <peifeng.si@intel.com>
@peifengsi
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants