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

Revert "Fix getMaxId won't get the right max id before GC" #4845

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions dbms/src/Storages/Page/V3/PageDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,31 +889,10 @@ PageId PageDirectory::getMaxId(NamespaceId ns_id) const
// iter is not at the beginning and mvcc_table_directory is not empty,
// so iter-- must be a valid iterator, and it's the largest page id which is smaller than the target page id.
iter--;

do
{
// Can't find any entries in current ns_id
if (iter->first.high != ns_id)
{
break;
}

// Find the last valid one
if (iter->second->getEntry(UINT64_MAX - 1) != std::nullopt)
{
return iter->first.low;
}

// Current entry is deleted and there are no entries before it.
if (iter == mvcc_table_directory.begin())
{
break;
}

iter--;
} while (true);

return 0;
if (iter->first.high == ns_id)
return iter->first.low;
else
return 0;
}
}

Expand Down
47 changes: 0 additions & 47 deletions dbms/src/Storages/Page/V3/tests/gtest_page_directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2054,53 +2054,6 @@ try
ASSERT_EQ(dir->getMaxId(medium), 320);
ASSERT_EQ(dir->getMaxId(large), 2);
}

{
PageEntriesEdit edit;
edit.del(buildV3Id(medium, 320));
dir->apply(std::move(edit));
ASSERT_EQ(dir->getMaxId(medium), 300);
}

{
PageEntriesEdit edit;
edit.del(buildV3Id(medium, 300));
dir->apply(std::move(edit));
ASSERT_EQ(dir->getMaxId(medium), 0);
}
}
CATCH

TEST_F(PageDirectoryTest, GetMaxIdAfterDelete)
try
{
PageEntryV3 entry1{.file_id = 1, .size = 1024, .tag = 0, .offset = 0x123, .checksum = 0x4567};
PageEntryV3 entry2{.file_id = 2, .size = 1024, .tag = 0, .offset = 0x123, .checksum = 0x4567};
{
PageEntriesEdit edit;
edit.put(1, entry1);
edit.put(2, entry2);
dir->apply(std::move(edit));
}

ASSERT_EQ(dir->getMaxId(TEST_NAMESPACE_ID), 2);

{
PageEntriesEdit edit;
edit.del(2);
dir->apply(std::move(edit));
}
ASSERT_EQ(dir->getMaxId(TEST_NAMESPACE_ID), 1);

{
PageEntriesEdit edit;
edit.del(1);
dir->apply(std::move(edit));
}
ASSERT_EQ(dir->getMaxId(TEST_NAMESPACE_ID), 0);

dir->gcInMemEntries();
ASSERT_EQ(dir->getMaxId(TEST_NAMESPACE_ID), 0);
}
CATCH

Expand Down