diff --git a/dbms/src/Storages/Page/V3/BlobStore.h b/dbms/src/Storages/Page/V3/BlobStore.h index b5cf5a677f1..e527eb0f3bf 100644 --- a/dbms/src/Storages/Page/V3/BlobStore.h +++ b/dbms/src/Storages/Page/V3/BlobStore.h @@ -34,7 +34,7 @@ extern const int LOGICAL_ERROR; namespace PS::V3 { -using PageIdAndVersionedEntries = std::vector>; +using PageIdAndVersionedEntries = std::vector>; class BlobStore : private Allocator { diff --git a/dbms/src/Storages/Page/V3/PageDirectory.cpp b/dbms/src/Storages/Page/V3/PageDirectory.cpp index ba6f04b6d38..06b26156529 100644 --- a/dbms/src/Storages/Page/V3/PageDirectory.cpp +++ b/dbms/src/Storages/Page/V3/PageDirectory.cpp @@ -66,7 +66,7 @@ namespace PS::V3 * VersionedPageEntries methods * ********************************/ -void VersionedPageEntries::createNewEntry(const PageVersionType & ver, const PageEntryV3 & entry) +void VersionedPageEntries::createNewEntry(const PageVersion & ver, const PageEntryV3 & entry) { auto page_lock = acquireLock(); if (type == EditRecordType::VAR_DELETE) @@ -78,7 +78,7 @@ void VersionedPageEntries::createNewEntry(const PageVersionType & ver, const Pag if (type == EditRecordType::VAR_ENTRY) { - auto last_iter = MapUtils::findLess(entries, PageVersionType(ver.sequence + 1, 0)); + auto last_iter = MapUtils::findLess(entries, PageVersion(ver.sequence + 1, 0)); if (last_iter == entries.end()) { entries.emplace(ver, EntryOrDelete::newNormalEntry(entry)); @@ -119,7 +119,7 @@ void VersionedPageEntries::createNewEntry(const PageVersionType & ver, const Pag // Create a new external version with version=`ver`. // If create success, then return a shared_ptr as a holder for page_id. The holder // will be release when this external version is totally removed. -std::shared_ptr VersionedPageEntries::createNewExternal(const PageVersionType & ver) +std::shared_ptr VersionedPageEntries::createNewExternal(const PageVersion & ver) { auto page_lock = acquireLock(); if (type == EditRecordType::VAR_DELETE) @@ -127,7 +127,7 @@ std::shared_ptr VersionedPageEntries::createNewExternal(const type = EditRecordType::VAR_EXTERNAL; is_deleted = false; create_ver = ver; - delete_ver = PageVersionType(0); + delete_ver = PageVersion(0); being_ref_count = 1; // return the new created holder to caller to set the page_id external_holder = std::make_shared(0, 0); @@ -143,7 +143,7 @@ std::shared_ptr VersionedPageEntries::createNewExternal(const { is_deleted = false; create_ver = ver; - delete_ver = PageVersionType(0); + delete_ver = PageVersion(0); being_ref_count = 1; // return the new created holder to caller to set the page_id external_holder = std::make_shared(0, 0); @@ -172,7 +172,7 @@ std::shared_ptr VersionedPageEntries::createNewExternal(const } // Create a new delete version with version=`ver`. -void VersionedPageEntries::createDelete(const PageVersionType & ver) +void VersionedPageEntries::createDelete(const PageVersion & ver) { auto page_lock = acquireLock(); if (type == EditRecordType::VAR_ENTRY) @@ -207,7 +207,7 @@ void VersionedPageEntries::createDelete(const PageVersionType & ver) // Create a new reference version with version=`ver` and `ori_page_id_`. // If create success, then return true, otherwise return false. -bool VersionedPageEntries::createNewRef(const PageVersionType & ver, PageIdV3Internal ori_page_id_) +bool VersionedPageEntries::createNewRef(const PageVersion & ver, PageIdV3Internal ori_page_id_) { auto page_lock = acquireLock(); if (type == EditRecordType::VAR_DELETE) @@ -229,7 +229,7 @@ bool VersionedPageEntries::createNewRef(const PageVersionType & ver, PageIdV3Int ori_page_id = ori_page_id_; create_ver = ver; is_deleted = false; - delete_ver = PageVersionType(0); + delete_ver = PageVersion(0); return true; } else if (ori_page_id == ori_page_id_) @@ -292,14 +292,14 @@ std::shared_ptr VersionedPageEntries::fromRestored(const PageE } } -std::tuple +std::tuple VersionedPageEntries::resolveToPageId(UInt64 seq, bool check_prev, PageEntryV3 * entry) { auto page_lock = acquireLock(); if (type == EditRecordType::VAR_ENTRY) { // entries are sorted by , find the first one less than - if (auto iter = MapUtils::findLess(entries, PageVersionType(seq + 1)); + if (auto iter = MapUtils::findLess(entries, PageVersion(seq + 1)); iter != entries.end()) { // If we applied write batches like this: [ver=1]{put 10}, [ver=2]{ref 11->10, del 10} @@ -309,7 +309,7 @@ VersionedPageEntries::resolveToPageId(UInt64 seq, bool check_prev, PageEntryV3 * { if (iter == entries.begin()) { - return {RESOLVE_FAIL, buildV3Id(0, 0), PageVersionType(0)}; + return {RESOLVE_FAIL, buildV3Id(0, 0), PageVersion(0)}; } --iter; // fallover the check the prev item @@ -319,7 +319,7 @@ VersionedPageEntries::resolveToPageId(UInt64 seq, bool check_prev, PageEntryV3 * { if (entry != nullptr) *entry = iter->second.entry; - return {RESOLVE_TO_NORMAL, buildV3Id(0, 0), PageVersionType(0)}; + return {RESOLVE_TO_NORMAL, buildV3Id(0, 0), PageVersion(0)}; } // fallover to FAIL } } @@ -329,7 +329,7 @@ VersionedPageEntries::resolveToPageId(UInt64 seq, bool check_prev, PageEntryV3 * bool ok = check_prev ? true : (!is_deleted || seq < delete_ver.sequence); if (create_ver.sequence <= seq && ok) { - return {RESOLVE_TO_NORMAL, buildV3Id(0, 0), PageVersionType(0)}; + return {RESOLVE_TO_NORMAL, buildV3Id(0, 0), PageVersion(0)}; } } else if (type == EditRecordType::VAR_REF) @@ -344,7 +344,7 @@ VersionedPageEntries::resolveToPageId(UInt64 seq, bool check_prev, PageEntryV3 * LOG_FMT_WARNING(&Poco::Logger::get("VersionedPageEntries"), "Can't reslove the EditRecordType {}", type); } - return {RESOLVE_FAIL, buildV3Id(0, 0), PageVersionType(0)}; + return {RESOLVE_FAIL, buildV3Id(0, 0), PageVersion(0)}; } std::optional VersionedPageEntries::getEntry(UInt64 seq) const @@ -353,7 +353,7 @@ std::optional VersionedPageEntries::getEntry(UInt64 seq) const if (type == EditRecordType::VAR_ENTRY) { // entries are sorted by , find the first one less than - if (auto iter = MapUtils::findLess(entries, PageVersionType(seq + 1)); + if (auto iter = MapUtils::findLess(entries, PageVersion(seq + 1)); iter != entries.end()) { // not deleted @@ -393,7 +393,7 @@ bool VersionedPageEntries::isVisible(UInt64 seq) const else if (type == EditRecordType::VAR_ENTRY) { // entries are sorted by , find the first one less than - if (auto iter = MapUtils::findLess(entries, PageVersionType(seq + 1)); + if (auto iter = MapUtils::findLess(entries, PageVersion(seq + 1)); iter != entries.end()) { // not deleted @@ -416,12 +416,12 @@ bool VersionedPageEntries::isVisible(UInt64 seq) const ErrorCodes::LOGICAL_ERROR); } -Int64 VersionedPageEntries::incrRefCount(const PageVersionType & ver) +Int64 VersionedPageEntries::incrRefCount(const PageVersion & ver) { auto page_lock = acquireLock(); if (type == EditRecordType::VAR_ENTRY) { - if (auto iter = MapUtils::findMutLess(entries, PageVersionType(ver.sequence + 1)); + if (auto iter = MapUtils::findMutLess(entries, PageVersion(ver.sequence + 1)); iter != entries.end()) { if (iter->second.isEntry()) @@ -476,7 +476,7 @@ PageSize VersionedPageEntries::getEntriesByBlobIds( bool VersionedPageEntries::cleanOutdatedEntries( UInt64 lowest_seq, - std::map> * normal_entries_to_deref, + std::map> * normal_entries_to_deref, PageEntriesV3 & entries_removed, const PageLock & /*page_lock*/) { @@ -515,7 +515,7 @@ bool VersionedPageEntries::cleanOutdatedEntries( return true; } - auto iter = MapUtils::findLess(entries, PageVersionType(lowest_seq + 1)); + auto iter = MapUtils::findLess(entries, PageVersion(lowest_seq + 1)); // If we can't find any seq lower than `lowest_seq` then // all version in this list don't need gc. if (iter == entries.begin() || iter == entries.end()) @@ -563,7 +563,7 @@ bool VersionedPageEntries::cleanOutdatedEntries( return entries.empty() || (entries.size() == 1 && entries.begin()->second.isDelete()); } -bool VersionedPageEntries::derefAndClean(UInt64 lowest_seq, PageIdV3Internal page_id, const PageVersionType & deref_ver, const Int64 deref_count, PageEntriesV3 & entries_removed) +bool VersionedPageEntries::derefAndClean(UInt64 lowest_seq, PageIdV3Internal page_id, const PageVersion & deref_ver, const Int64 deref_count, PageEntriesV3 & entries_removed) { auto page_lock = acquireLock(); if (type == EditRecordType::VAR_EXTERNAL) @@ -579,7 +579,7 @@ bool VersionedPageEntries::derefAndClean(UInt64 lowest_seq, PageIdV3Internal pag { // Decrease the ref-counter. The entry may be moved to a newer entry with same sequence but higher epoch, // so we need to find the one less than and decrease the ref-counter of it. - auto iter = MapUtils::findMutLess(entries, PageVersionType(deref_ver.sequence + 1, 0)); + auto iter = MapUtils::findMutLess(entries, PageVersion(deref_ver.sequence + 1, 0)); if (iter == entries.end()) { throw Exception(fmt::format("Can not find entry for decreasing ref count [page_id={}] [ver={}] [deref_count={}]", page_id, deref_ver, deref_count)); @@ -639,7 +639,7 @@ void VersionedPageEntries::collapseTo(const UInt64 seq, const PageIdV3Internal p if (type == EditRecordType::VAR_ENTRY) { // dump the latest entry if it is not a "delete" - auto last_iter = MapUtils::findLess(entries, PageVersionType(seq + 1)); + auto last_iter = MapUtils::findLess(entries, PageVersion(seq + 1)); if (last_iter == entries.end()) return; @@ -750,7 +750,7 @@ PageIDAndEntryV3 PageDirectory::get(PageIdV3Internal page_id, const PageDirector PageEntryV3 entry_got; PageIdV3Internal id_to_resolve = page_id; - PageVersionType ver_to_resolve(snap->sequence, 0); + PageVersion ver_to_resolve(snap->sequence, 0); bool ok = true; while (ok) { @@ -803,8 +803,8 @@ std::pair PageDirectory::get(const PageIdV3Internal PageEntryV3 entry_got; PageIds page_not_found = {}; - const PageVersionType init_ver_to_resolve(snap->sequence, 0); - auto get_one = [&entry_got, init_ver_to_resolve, throw_on_not_exist, this](PageIdV3Internal page_id, PageVersionType ver_to_resolve, size_t idx) { + const PageVersion init_ver_to_resolve(snap->sequence, 0); + auto get_one = [&entry_got, init_ver_to_resolve, throw_on_not_exist, this](PageIdV3Internal page_id, PageVersion ver_to_resolve, size_t idx) { PageIdV3Internal id_to_resolve = page_id; bool ok = true; while (ok) @@ -866,7 +866,7 @@ std::pair PageDirectory::get(const PageIdV3Internal PageIdV3Internal PageDirectory::getNormalPageId(PageIdV3Internal page_id, const PageDirectorySnapshotPtr & snap, bool throw_on_not_exist) const { PageIdV3Internal id_to_resolve = page_id; - PageVersionType ver_to_resolve(snap->sequence, 0); + PageVersion ver_to_resolve(snap->sequence, 0); bool keep_resolve = true; while (keep_resolve) { @@ -985,17 +985,17 @@ void PageDirectory::applyRefEditRecord( MVCCMapType & mvcc_table_directory, const VersionedPageEntriesPtr & version_list, const PageEntriesEdit::EditRecord & rec, - const PageVersionType & version) + const PageVersion & version) { // applying ref 3->2, existing ref 2->1, normal entry 1, then we should collapse // the ref to be 3->1, increase the refcounting of normale entry 1 - auto [resolve_success, resolved_id, resolved_ver] = [&mvcc_table_directory](PageIdV3Internal id_to_resolve, PageVersionType ver_to_resolve) - -> std::tuple { + auto [resolve_success, resolved_id, resolved_ver] = [&mvcc_table_directory](PageIdV3Internal id_to_resolve, PageVersion ver_to_resolve) + -> std::tuple { while (true) { auto resolve_ver_iter = mvcc_table_directory.find(id_to_resolve); if (resolve_ver_iter == mvcc_table_directory.end()) - return {false, buildV3Id(0, 0), PageVersionType(0)}; + return {false, buildV3Id(0, 0), PageVersion(0)}; const VersionedPageEntriesPtr & resolve_version_list = resolve_ver_iter->second; // If we already hold the lock from `id_to_resolve`, then we should not request it again. @@ -1061,7 +1061,7 @@ void PageDirectory::apply(PageEntriesEdit && edit, const WriteLimiterPtr & write // TODO: It is totally serialized, make it a pipeline std::unique_lock write_lock(table_rw_mutex); UInt64 last_sequence = sequence.load(); - PageVersionType new_version(last_sequence + 1, 0); + PageVersion new_version(last_sequence + 1, 0); // stage 1, persisted the changes to WAL with version [seq=last_seq + 1, epoch=0] wal->apply(edit, new_version, write_limiter); @@ -1295,7 +1295,7 @@ PageEntriesV3 PageDirectory::gcInMemEntries() // The page_id that we need to decrease ref count // { id_0: , id_1: <...>, ... } - std::map> normal_entries_to_deref; + std::map> normal_entries_to_deref; // Iterate all page_id and try to clean up useless var entries while (true) { diff --git a/dbms/src/Storages/Page/V3/PageDirectory.h b/dbms/src/Storages/Page/V3/PageDirectory.h index 6dcf4d77bfb..635cf04bfe6 100644 --- a/dbms/src/Storages/Page/V3/PageDirectory.h +++ b/dbms/src/Storages/Page/V3/PageDirectory.h @@ -149,13 +149,13 @@ class VersionedPageEntries return std::lock_guard(m); } - void createNewEntry(const PageVersionType & ver, const PageEntryV3 & entry); + void createNewEntry(const PageVersion & ver, const PageEntryV3 & entry); - bool createNewRef(const PageVersionType & ver, PageIdV3Internal ori_page_id); + bool createNewRef(const PageVersion & ver, PageIdV3Internal ori_page_id); - std::shared_ptr createNewExternal(const PageVersionType & ver); + std::shared_ptr createNewExternal(const PageVersion & ver); - void createDelete(const PageVersionType & ver); + void createDelete(const PageVersion & ver); std::shared_ptr fromRestored(const PageEntriesEdit::EditRecord & rec); @@ -165,10 +165,10 @@ class VersionedPageEntries RESOLVE_TO_REF, RESOLVE_TO_NORMAL, }; - std::tuple + std::tuple resolveToPageId(UInt64 seq, bool check_prev, PageEntryV3 * entry); - Int64 incrRefCount(const PageVersionType & ver); + Int64 incrRefCount(const PageVersion & ver); std::optional getEntry(UInt64 seq) const; @@ -222,13 +222,13 @@ class VersionedPageEntries */ bool cleanOutdatedEntries( UInt64 lowest_seq, - std::map> * normal_entries_to_deref, + std::map> * normal_entries_to_deref, PageEntriesV3 & entries_removed, const PageLock & page_lock); bool derefAndClean( UInt64 lowest_seq, PageIdV3Internal page_id, - const PageVersionType & deref_ver, + const PageVersion & deref_ver, Int64 deref_count, PageEntriesV3 & entries_removed); @@ -270,11 +270,11 @@ class VersionedPageEntries // Has been deleted, valid when type == VAR_REF/VAR_EXTERNAL bool is_deleted; // Entries sorted by version, valid when type == VAR_ENTRY - std::multimap entries; + std::multimap entries; // The created version, valid when type == VAR_REF/VAR_EXTERNAL - PageVersionType create_ver; + PageVersion create_ver; // The deleted version, valid when type == VAR_REF/VAR_EXTERNAL && is_deleted = true - PageVersionType delete_ver; + PageVersion delete_ver; // Original page id, valid when type == VAR_REF PageIdV3Internal ori_page_id; // Being ref counter, valid when type == VAR_EXTERNAL @@ -387,7 +387,7 @@ class PageDirectory MVCCMapType & mvcc_table_directory, const VersionedPageEntriesPtr & version_list, const PageEntriesEdit::EditRecord & rec, - const PageVersionType & version); + const PageVersion & version); static inline PageDirectorySnapshotPtr toConcreteSnapshot(const DB::PageStorageSnapshotPtr & ptr) diff --git a/dbms/src/Storages/Page/V3/PageDirectoryFactory.h b/dbms/src/Storages/Page/V3/PageDirectoryFactory.h index 97d68f43253..11337e4a6cc 100644 --- a/dbms/src/Storages/Page/V3/PageDirectoryFactory.h +++ b/dbms/src/Storages/Page/V3/PageDirectoryFactory.h @@ -37,7 +37,7 @@ using WALStoreReaderPtr = std::shared_ptr; class PageDirectoryFactory { public: - PageVersionType max_applied_ver; + PageVersion max_applied_ver; PageIdV3Internal max_applied_page_id; PageDirectoryFactory & setBlobStore(BlobStore & blob_store) diff --git a/dbms/src/Storages/Page/V3/PageEntriesEdit.h b/dbms/src/Storages/Page/V3/PageEntriesEdit.h index 7783a504507..b75b16da4a4 100644 --- a/dbms/src/Storages/Page/V3/PageEntriesEdit.h +++ b/dbms/src/Storages/Page/V3/PageEntriesEdit.h @@ -27,45 +27,45 @@ namespace DB::PS::V3 // `PageDirectory::apply` with create a version={directory.sequence, epoch=0}. // After data compaction and page entries need to be updated, will create // some entries with a version={old_sequence, epoch=old_epoch+1}. -struct PageVersionType +struct PageVersion { UInt64 sequence; // The write sequence UInt64 epoch; // The GC epoch - explicit PageVersionType(UInt64 seq) + explicit PageVersion(UInt64 seq) : sequence(seq) , epoch(0) {} - PageVersionType(UInt64 seq, UInt64 epoch_) + PageVersion(UInt64 seq, UInt64 epoch_) : sequence(seq) , epoch(epoch_) {} - PageVersionType() - : PageVersionType(0) + PageVersion() + : PageVersion(0) {} - bool operator<(const PageVersionType & rhs) const + bool operator<(const PageVersion & rhs) const { if (sequence == rhs.sequence) return epoch < rhs.epoch; return sequence < rhs.sequence; } - bool operator==(const PageVersionType & rhs) const + bool operator==(const PageVersion & rhs) const { return (sequence == rhs.sequence) && (epoch == rhs.epoch); } - bool operator<=(const PageVersionType & rhs) const + bool operator<=(const PageVersion & rhs) const { if (sequence == rhs.sequence) return epoch <= rhs.epoch; return sequence <= rhs.sequence; } }; -using VersionedEntry = std::pair; +using VersionedEntry = std::pair; using VersionedEntries = std::vector; enum class EditRecordType @@ -139,7 +139,7 @@ class PageEntriesEdit records.emplace_back(record); } - void upsertPage(PageIdV3Internal page_id, const PageVersionType & ver, const PageEntryV3 & entry) + void upsertPage(PageIdV3Internal page_id, const PageVersion & ver, const PageEntryV3 & entry) { EditRecord record{}; record.type = EditRecordType::UPSERT; @@ -166,7 +166,7 @@ class PageEntriesEdit records.emplace_back(record); } - void varRef(PageIdV3Internal ref_id, const PageVersionType & ver, PageIdV3Internal ori_page_id) + void varRef(PageIdV3Internal ref_id, const PageVersion & ver, PageIdV3Internal ori_page_id) { EditRecord record{}; record.type = EditRecordType::VAR_REF; @@ -176,7 +176,7 @@ class PageEntriesEdit records.emplace_back(record); } - void varExternal(PageIdV3Internal page_id, const PageVersionType & create_ver, Int64 being_ref_count) + void varExternal(PageIdV3Internal page_id, const PageVersion & create_ver, Int64 being_ref_count) { EditRecord record{}; record.type = EditRecordType::VAR_EXTERNAL; @@ -186,7 +186,7 @@ class PageEntriesEdit records.emplace_back(record); } - void varEntry(PageIdV3Internal page_id, const PageVersionType & ver, const PageEntryV3 & entry, Int64 being_ref_count) + void varEntry(PageIdV3Internal page_id, const PageVersion & ver, const PageEntryV3 & entry, Int64 being_ref_count) { EditRecord record{}; record.type = EditRecordType::VAR_ENTRY; @@ -197,7 +197,7 @@ class PageEntriesEdit records.emplace_back(record); } - void varDel(PageIdV3Internal page_id, const PageVersionType & delete_ver) + void varDel(PageIdV3Internal page_id, const PageVersion & delete_ver) { EditRecord record{}; record.type = EditRecordType::VAR_DELETE; @@ -217,7 +217,7 @@ class PageEntriesEdit EditRecordType type; PageIdV3Internal page_id; PageIdV3Internal ori_page_id; - PageVersionType version; + PageVersion version; PageEntryV3 entry; Int64 being_ref_count; @@ -260,7 +260,7 @@ class PageEntriesEdit { putExternal(buildV3Id(TEST_NAMESPACE_ID, page_id)); } - void upsertPage(PageId page_id, const PageVersionType & ver, const PageEntryV3 & entry) + void upsertPage(PageId page_id, const PageVersion & ver, const PageEntryV3 & entry) { upsertPage(buildV3Id(TEST_NAMESPACE_ID, page_id), ver, entry); } @@ -272,19 +272,19 @@ class PageEntriesEdit { ref(buildV3Id(TEST_NAMESPACE_ID, ref_id), buildV3Id(TEST_NAMESPACE_ID, page_id)); } - void varRef(PageId ref_id, const PageVersionType & ver, PageId ori_page_id) + void varRef(PageId ref_id, const PageVersion & ver, PageId ori_page_id) { varRef(buildV3Id(TEST_NAMESPACE_ID, ref_id), ver, buildV3Id(TEST_NAMESPACE_ID, ori_page_id)); } - void varExternal(PageId page_id, const PageVersionType & create_ver, Int64 being_ref_count) + void varExternal(PageId page_id, const PageVersion & create_ver, Int64 being_ref_count) { varExternal(buildV3Id(TEST_NAMESPACE_ID, page_id), create_ver, being_ref_count); } - void varEntry(PageId page_id, const PageVersionType & ver, const PageEntryV3 & entry, Int64 being_ref_count) + void varEntry(PageId page_id, const PageVersion & ver, const PageEntryV3 & entry, Int64 being_ref_count) { varEntry(buildV3Id(TEST_NAMESPACE_ID, page_id), ver, entry, being_ref_count); } - void varDel(PageId page_id, const PageVersionType & delete_ver) + void varDel(PageId page_id, const PageVersion & delete_ver) { varDel(buildV3Id(TEST_NAMESPACE_ID, page_id), delete_ver); } @@ -316,7 +316,7 @@ class PageEntriesEdit /// See https://fmt.dev/latest/api.html#formatting-user-defined-types template <> -struct fmt::formatter +struct fmt::formatter { static constexpr auto parse(format_parse_context & ctx) { @@ -331,7 +331,7 @@ struct fmt::formatter } template - auto format(const DB::PS::V3::PageVersionType & ver, FormatContext & ctx) + auto format(const DB::PS::V3::PageVersion & ver, FormatContext & ctx) { return format_to(ctx.out(), "<{},{}>", ver.sequence, ver.epoch); } diff --git a/dbms/src/Storages/Page/V3/WAL/serialize.cpp b/dbms/src/Storages/Page/V3/WAL/serialize.cpp index 26854f9a640..f8e26617499 100644 --- a/dbms/src/Storages/Page/V3/WAL/serialize.cpp +++ b/dbms/src/Storages/Page/V3/WAL/serialize.cpp @@ -23,13 +23,13 @@ namespace DB::PS::V3::ser { -inline void serializeVersionTo(const PageVersionType & version, WriteBuffer & buf) +inline void serializeVersionTo(const PageVersion & version, WriteBuffer & buf) { writeIntBinary(version.sequence, buf); writeIntBinary(version.epoch, buf); } -inline void deserializeVersionFrom(ReadBuffer & buf, PageVersionType & version) +inline void deserializeVersionFrom(ReadBuffer & buf, PageVersion & version) { readIntBinary(version.sequence, buf); readIntBinary(version.epoch, buf); @@ -174,7 +174,7 @@ void deserializeDelFrom([[maybe_unused]] const EditRecordType record_type, ReadB PageIdV3Internal page_id; readIntBinary(page_id, buf); - PageVersionType version; + PageVersion version; deserializeVersionFrom(buf, version); PageEntriesEdit::EditRecord rec; diff --git a/dbms/src/Storages/Page/V3/WALStore.cpp b/dbms/src/Storages/Page/V3/WALStore.cpp index 6759e80f416..1f1eaf3bc33 100644 --- a/dbms/src/Storages/Page/V3/WALStore.cpp +++ b/dbms/src/Storages/Page/V3/WALStore.cpp @@ -69,7 +69,7 @@ WALStore::WALStore( { } -void WALStore::apply(PageEntriesEdit & edit, const PageVersionType & version, const WriteLimiterPtr & write_limiter) +void WALStore::apply(PageEntriesEdit & edit, const PageVersion & version, const WriteLimiterPtr & write_limiter) { for (auto & r : edit.getMutRecords()) { diff --git a/dbms/src/Storages/Page/V3/WALStore.h b/dbms/src/Storages/Page/V3/WALStore.h index 8984c10e5e8..039903a8608 100644 --- a/dbms/src/Storages/Page/V3/WALStore.h +++ b/dbms/src/Storages/Page/V3/WALStore.h @@ -99,7 +99,7 @@ class WALStore PSDiskDelegatorPtr & delegator, WALStore::Config config); - void apply(PageEntriesEdit & edit, const PageVersionType & version, const WriteLimiterPtr & write_limiter = nullptr); + void apply(PageEntriesEdit & edit, const PageVersion & version, const WriteLimiterPtr & write_limiter = nullptr); void apply(const PageEntriesEdit & edit, const WriteLimiterPtr & write_limiter = nullptr); struct FilesSnapshot diff --git a/dbms/src/Storages/Page/V3/tests/gtest_page_directory.cpp b/dbms/src/Storages/Page/V3/tests/gtest_page_directory.cpp index e84df010348..4511cc8ddd7 100644 --- a/dbms/src/Storages/Page/V3/tests/gtest_page_directory.cpp +++ b/dbms/src/Storages/Page/V3/tests/gtest_page_directory.cpp @@ -625,16 +625,16 @@ CATCH #define INSERT_BLOBID_ENTRY(BLOBID, VERSION) \ PageEntryV3 entry_v##VERSION{.file_id = (BLOBID), .size = (VERSION), .tag = 0, .offset = 0x123, .checksum = 0x4567}; \ - entries.createNewEntry(PageVersionType(VERSION), entry_v##VERSION); + entries.createNewEntry(PageVersion(VERSION), entry_v##VERSION); #define INSERT_ENTRY(VERSION) INSERT_BLOBID_ENTRY(1, VERSION) #define INSERT_GC_ENTRY(VERSION, EPOCH) \ PageEntryV3 entry_gc_v##VERSION##_##EPOCH{.file_id = 2, .size = 100 * (VERSION) + (EPOCH), .tag = 0, .offset = 0x234, .checksum = 0x5678}; \ - entries.createNewEntry(PageVersionType((VERSION), (EPOCH)), entry_gc_v##VERSION##_##EPOCH); + entries.createNewEntry(PageVersion((VERSION), (EPOCH)), entry_gc_v##VERSION##_##EPOCH); class VersionedEntriesTest : public ::testing::Test { public: - using DerefCounter = std::map>; + using DerefCounter = std::map>; std::tuple runClean(UInt64 seq) { DerefCounter deref_counter; @@ -643,7 +643,7 @@ class VersionedEntriesTest : public ::testing::Test return {all_removed, removed_entries, deref_counter}; } - std::tuple runDeref(UInt64 seq, PageVersionType ver, Int64 decrease_num) + std::tuple runDeref(UInt64 seq, PageVersion ver, Int64 decrease_num) { PageEntriesV3 removed_entries; bool all_removed = entries.derefAndClean(seq, buildV3Id(TEST_NAMESPACE_ID, page_id), ver, decrease_num, removed_entries); @@ -694,7 +694,7 @@ TEST_F(VersionedEntriesTest, InsertGet) // Insert delete. Can not get entry with seq >= delete_version. // But it won't affect reading with old seq. - entries.createDelete(PageVersionType(15)); + entries.createDelete(PageVersion(15)); ASSERT_FALSE(entries.getEntry(1).has_value()); ASSERT_SAME_ENTRY(*entries.getEntry(2), entry_gc_v2_1); ASSERT_SAME_ENTRY(*entries.getEntry(3), entry_gc_v2_1); @@ -744,7 +744,7 @@ try ASSERT_TRUE(entries.isVisible(6)); // insert delete - entries.createDelete(PageVersionType(6)); + entries.createDelete(PageVersion(6)); ASSERT_FALSE(entries.isVisible(1)); ASSERT_TRUE(entries.isVisible(2)); @@ -778,14 +778,14 @@ try ASSERT_FALSE(entries.isVisible(10000)); // insert some entries - entries.createNewExternal(PageVersionType(2)); + entries.createNewExternal(PageVersion(2)); ASSERT_FALSE(entries.isVisible(1)); ASSERT_TRUE(entries.isVisible(2)); ASSERT_TRUE(entries.isVisible(10000)); // insert delete - entries.createDelete(PageVersionType(6)); + entries.createDelete(PageVersion(6)); ASSERT_FALSE(entries.isVisible(1)); ASSERT_TRUE(entries.isVisible(2)); @@ -796,7 +796,7 @@ try ASSERT_FALSE(entries.isVisible(10000)); // insert entry after delete - entries.createNewExternal(PageVersionType(7)); + entries.createNewExternal(PageVersion(7)); // after re-create external page, the visible for 1~5 has changed ASSERT_FALSE(entries.isVisible(6)); @@ -815,14 +815,14 @@ try ASSERT_FALSE(entries.isVisible(10000)); // insert some entries - entries.createNewRef(PageVersionType(2), buildV3Id(TEST_NAMESPACE_ID, 2)); + entries.createNewRef(PageVersion(2), buildV3Id(TEST_NAMESPACE_ID, 2)); ASSERT_FALSE(entries.isVisible(1)); ASSERT_TRUE(entries.isVisible(2)); ASSERT_TRUE(entries.isVisible(10000)); // insert delete - entries.createDelete(PageVersionType(6)); + entries.createDelete(PageVersion(6)); ASSERT_FALSE(entries.isVisible(1)); ASSERT_TRUE(entries.isVisible(2)); @@ -833,7 +833,7 @@ try ASSERT_FALSE(entries.isVisible(10000)); // insert entry after delete - entries.createNewRef(PageVersionType(7), buildV3Id(TEST_NAMESPACE_ID, 2)); + entries.createNewRef(PageVersion(7), buildV3Id(TEST_NAMESPACE_ID, 2)); // after re-create ref page, the visible for 1~5 has changed ASSERT_FALSE(entries.isVisible(6)); @@ -852,7 +852,7 @@ try INSERT_GC_ENTRY(5, 2); INSERT_ENTRY(10); INSERT_ENTRY(11); - entries.createDelete(PageVersionType(15)); + entries.createDelete(PageVersion(15)); // noting to be removed auto [all_removed, removed_entries, deref_counter] = runClean(1); @@ -905,15 +905,15 @@ CATCH TEST_F(VersionedEntriesTest, DeleteMultiTime) try { - entries.createDelete(PageVersionType(1)); + entries.createDelete(PageVersion(1)); INSERT_ENTRY(2); INSERT_GC_ENTRY(2, 1); - entries.createDelete(PageVersionType(15)); - entries.createDelete(PageVersionType(17)); - entries.createDelete(PageVersionType(16)); + entries.createDelete(PageVersion(15)); + entries.createDelete(PageVersion(17)); + entries.createDelete(PageVersion(16)); bool all_removed; - std::map> deref_counter; + std::map> deref_counter; PageEntriesV3 removed_entries; // <2,0> get removed. @@ -938,13 +938,13 @@ TEST_F(VersionedEntriesTest, DontCleanWhenBeingRef) try { bool all_removed; - std::map> deref_counter; + std::map> deref_counter; PageEntriesV3 removed_entries; INSERT_ENTRY(2); - entries.incrRefCount(PageVersionType(2)); - entries.incrRefCount(PageVersionType(2)); - entries.createDelete(PageVersionType(5)); + entries.incrRefCount(PageVersion(2)); + entries.incrRefCount(PageVersion(2)); + entries.createDelete(PageVersion(5)); // <2, 0> is not available after seq=5, but not get removed ASSERT_SAME_ENTRY(entry_v2, *entries.getEntry(4)); @@ -958,13 +958,13 @@ try ASSERT_EQ(deref_counter.size(), 0); // decrease 1 ref counting - std::tie(all_removed, removed_entries) = runDeref(5, PageVersionType(2), 1); + std::tie(all_removed, removed_entries) = runDeref(5, PageVersion(2), 1); ASSERT_EQ(removed_entries.size(), 0); ASSERT_FALSE(all_removed); // should not remove this chain ASSERT_FALSE(entries.getEntry(5)); // clear all - std::tie(all_removed, removed_entries) = runDeref(5, PageVersionType(2), 1); + std::tie(all_removed, removed_entries) = runDeref(5, PageVersion(2), 1); ASSERT_EQ(removed_entries.size(), 1); ASSERT_SAME_ENTRY(removed_entries[0], entry_v2); ASSERT_TRUE(all_removed); // should remove this chain @@ -976,13 +976,13 @@ TEST_F(VersionedEntriesTest, DontCleanWhenBeingRef2) try { bool all_removed; - std::map> deref_counter; + std::map> deref_counter; PageEntriesV3 removed_entries; INSERT_ENTRY(2); - entries.incrRefCount(PageVersionType(2)); - entries.incrRefCount(PageVersionType(2)); - entries.createDelete(PageVersionType(5)); + entries.incrRefCount(PageVersion(2)); + entries.incrRefCount(PageVersion(2)); + entries.createDelete(PageVersion(5)); // <2, 0> is not available after seq=5, but not get removed ASSERT_SAME_ENTRY(entry_v2, *entries.getEntry(4)); @@ -996,7 +996,7 @@ try ASSERT_EQ(deref_counter.size(), 0); // clear all - std::tie(all_removed, removed_entries) = runDeref(5, PageVersionType(2), 2); + std::tie(all_removed, removed_entries) = runDeref(5, PageVersion(2), 2); ASSERT_EQ(removed_entries.size(), 1); ASSERT_SAME_ENTRY(removed_entries[0], entry_v2); ASSERT_TRUE(all_removed); // should remove this chain @@ -1008,12 +1008,12 @@ TEST_F(VersionedEntriesTest, CleanDuplicatedWhenBeingRefAndAppliedUpsert) try { bool all_removed; - std::map> deref_counter; + std::map> deref_counter; PageEntriesV3 removed_entries; INSERT_ENTRY(2); - entries.incrRefCount(PageVersionType(2)); - entries.incrRefCount(PageVersionType(2)); + entries.incrRefCount(PageVersion(2)); + entries.incrRefCount(PageVersion(2)); INSERT_GC_ENTRY(2, 1); INSERT_GC_ENTRY(2, 2); @@ -1030,7 +1030,7 @@ try ASSERT_EQ(deref_counter.size(), 0); // clear all - std::tie(all_removed, removed_entries) = runDeref(5, PageVersionType(2), 2); + std::tie(all_removed, removed_entries) = runDeref(5, PageVersion(2), 2); ASSERT_EQ(removed_entries.size(), 0); ASSERT_FALSE(all_removed); // should not remove this chain ASSERT_SAME_ENTRY(entry_gc_v2_2, *entries.getEntry(4)); @@ -1041,15 +1041,15 @@ TEST_F(VersionedEntriesTest, CleanDuplicatedWhenBeingRefAndAppliedUpsert2) try { bool all_removed; - std::map> deref_counter; + std::map> deref_counter; PageEntriesV3 removed_entries; INSERT_ENTRY(2); - entries.incrRefCount(PageVersionType(2)); - entries.incrRefCount(PageVersionType(2)); + entries.incrRefCount(PageVersion(2)); + entries.incrRefCount(PageVersion(2)); INSERT_GC_ENTRY(2, 1); INSERT_GC_ENTRY(2, 2); - entries.createDelete(PageVersionType(5)); + entries.createDelete(PageVersion(5)); // <2, 2> is not available after seq=5, but not get removed ASSERT_SAME_ENTRY(entry_gc_v2_2, *entries.getEntry(4)); @@ -1065,7 +1065,7 @@ try ASSERT_EQ(deref_counter.size(), 0); // clear all - std::tie(all_removed, removed_entries) = runDeref(5, PageVersionType(2), 2); + std::tie(all_removed, removed_entries) = runDeref(5, PageVersion(2), 2); ASSERT_EQ(removed_entries.size(), 1); ASSERT_SAME_ENTRY(removed_entries[0], entry_gc_v2_2); ASSERT_TRUE(all_removed); // should remove this chain @@ -1077,7 +1077,7 @@ TEST_F(VersionedEntriesTest, ReadAfterGcApplied) try { bool all_removed; - std::map> deref_counter; + std::map> deref_counter; PageEntriesV3 removed_entries; INSERT_ENTRY(2); diff --git a/dbms/src/Storages/Page/V3/tests/gtest_wal_store.cpp b/dbms/src/Storages/Page/V3/tests/gtest_wal_store.cpp index fadc0fb3bae..89c4e54f7e7 100644 --- a/dbms/src/Storages/Page/V3/tests/gtest_wal_store.cpp +++ b/dbms/src/Storages/Page/V3/tests/gtest_wal_store.cpp @@ -36,7 +36,7 @@ TEST(WALSeriTest, AllPuts) { PageEntryV3 entry_p1{.file_id = 1, .size = 1, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p2{.file_id = 1, .size = 2, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver20(/*seq=*/20); + PageVersion ver20(/*seq=*/20); PageEntriesEdit edit; edit.put(1, entry_p1); edit.put(2, entry_p2); @@ -58,7 +58,7 @@ try { PageEntryV3 entry_p3{.file_id = 1, .size = 3, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p5{.file_id = 1, .size = 5, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver21(/*seq=*/21); + PageVersion ver21(/*seq=*/21); PageEntriesEdit edit; edit.put(3, entry_p3); edit.ref(4, 3); @@ -107,8 +107,8 @@ TEST(WALSeriTest, Upserts) PageEntryV3 entry_p1_2{.file_id = 2, .size = 1, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p3_2{.file_id = 2, .size = 3, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p5_2{.file_id = 2, .size = 5, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver20_1(/*seq=*/20, /*epoch*/ 1); - PageVersionType ver21_1(/*seq=*/21, /*epoch*/ 1); + PageVersion ver20_1(/*seq=*/20, /*epoch*/ 1); + PageVersion ver21_1(/*seq=*/21, /*epoch*/ 1); PageEntriesEdit edit; edit.upsertPage(1, ver20_1, entry_p1_2); edit.upsertPage(3, ver21_1, entry_p3_2); @@ -135,9 +135,9 @@ TEST(WALSeriTest, Upserts) TEST(WALSeriTest, RefExternalAndEntry) { - PageVersionType ver1_0(/*seq=*/1, /*epoch*/ 0); - PageVersionType ver2_0(/*seq=*/2, /*epoch*/ 0); - PageVersionType ver3_0(/*seq=*/3, /*epoch*/ 0); + PageVersion ver1_0(/*seq=*/1, /*epoch*/ 0); + PageVersion ver2_0(/*seq=*/2, /*epoch*/ 0); + PageVersion ver3_0(/*seq=*/3, /*epoch*/ 0); { PageEntriesEdit edit; edit.varExternal(1, ver1_0, 2); @@ -407,7 +407,7 @@ try // Stage 2. Apply with only puts PageEntryV3 entry_p1{.file_id = 1, .size = 1, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p2{.file_id = 1, .size = 2, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver20(/*seq=*/20); + PageVersion ver20(/*seq=*/20); { PageEntriesEdit edit; edit.put(1, entry_p1); @@ -437,7 +437,7 @@ try // Stage 3. Apply with puts and refs PageEntryV3 entry_p3{.file_id = 1, .size = 3, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p5{.file_id = 1, .size = 5, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver21(/*seq=*/21); + PageVersion ver21(/*seq=*/21); { PageEntriesEdit edit; edit.put(3, entry_p3); @@ -471,8 +471,8 @@ try PageEntryV3 entry_p1_2{.file_id = 2, .size = 1, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p3_2{.file_id = 2, .size = 3, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p5_2{.file_id = 2, .size = 5, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver20_1(/*seq=*/20, /*epoch*/ 1); - PageVersionType ver21_1(/*seq=*/21, /*epoch*/ 1); + PageVersion ver20_1(/*seq=*/20, /*epoch*/ 1); + PageVersion ver21_1(/*seq=*/21, /*epoch*/ 1); { PageEntriesEdit edit; edit.upsertPage(1, ver20_1, entry_p1_2); @@ -516,7 +516,7 @@ try // Stage 1. Apply with only puts PageEntryV3 entry_p1{.file_id = 1, .size = 1, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p2{.file_id = 1, .size = 2, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver20(/*seq=*/20); + PageVersion ver20(/*seq=*/20); { PageEntriesEdit edit; edit.put(1, entry_p1); @@ -528,7 +528,7 @@ try // Stage 2. Apply with puts and refs PageEntryV3 entry_p3{.file_id = 1, .size = 3, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p5{.file_id = 1, .size = 5, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver21(/*seq=*/21); + PageVersion ver21(/*seq=*/21); { PageEntriesEdit edit; edit.put(3, entry_p3); @@ -543,8 +543,8 @@ try PageEntryV3 entry_p1_2{.file_id = 2, .size = 1, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p3_2{.file_id = 2, .size = 3, .tag = 0, .offset = 0x123, .checksum = 0x4567}; PageEntryV3 entry_p5_2{.file_id = 2, .size = 5, .tag = 0, .offset = 0x123, .checksum = 0x4567}; - PageVersionType ver20_1(/*seq=*/20, /*epoch*/ 1); - PageVersionType ver21_1(/*seq=*/21, /*epoch*/ 1); + PageVersion ver20_1(/*seq=*/20, /*epoch*/ 1); + PageVersion ver21_1(/*seq=*/21, /*epoch*/ 1); { PageEntriesEdit edit; edit.upsertPage(1, ver20_1, entry_p1_2); @@ -611,7 +611,7 @@ try PageId page_id = 0; std::vector size_each_edit; size_each_edit.reserve(num_edits_test); - PageVersionType ver(/*seq*/ 32); + PageVersion ver(/*seq*/ 32); for (size_t i = 0; i < num_edits_test; ++i) { PageEntryV3 entry{.file_id = 2, .size = 1, .tag = 0, .offset = 0x123, .checksum = 0x4567}; @@ -665,7 +665,7 @@ try // just fill in some random entry for (size_t i = 0; i < 70; ++i) { - snap_edit.varEntry(d_10000(rd), PageVersionType(345, 22), entry, 1); + snap_edit.varEntry(d_10000(rd), PageVersion(345, 22), entry, 1); } std::tie(wal, reader) = WALStore::create(getCurrentTestName(), enc_provider, delegator, config); bool done = wal->saveSnapshot(std::move(file_snap), std::move(snap_edit)); diff --git a/dbms/src/Storages/Page/V3/tests/page_storage_ctl.cpp b/dbms/src/Storages/Page/V3/tests/page_storage_ctl.cpp index 4f3cefa0ad7..7ea8da6892a 100644 --- a/dbms/src/Storages/Page/V3/tests/page_storage_ctl.cpp +++ b/dbms/src/Storages/Page/V3/tests/page_storage_ctl.cpp @@ -399,7 +399,7 @@ class PageStorageControl size_t index = 0; std::cout << fmt::format("Begin to check all of datas CRC. enable_fo_check={}", static_cast(enable_fo_check)) << std::endl; - std::list> error_versioned_pages; + std::list> error_versioned_pages; for (const auto & [internal_id, versioned_entries] : mvcc_table_directory) { if (index == total_pages / 10 * cut_index) @@ -474,4 +474,4 @@ int main(int argc, char ** argv) const auto & options = ControlOptions::parse(argc, argv); PageStorageControl(options).run(); return 0; -} \ No newline at end of file +}