Skip to content

Commit

Permalink
Rename PageVersionType -> PageVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed May 17, 2022
1 parent 055e4bb commit cb236c1
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 132 deletions.
2 changes: 1 addition & 1 deletion dbms/src/Storages/Page/V3/BlobStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern const int LOGICAL_ERROR;

namespace PS::V3
{
using PageIdAndVersionedEntries = std::vector<std::tuple<PageIdV3Internal, PageVersionType, PageEntryV3>>;
using PageIdAndVersionedEntries = std::vector<std::tuple<PageIdV3Internal, PageVersion, PageEntryV3>>;

class BlobStore : private Allocator<false>
{
Expand Down
66 changes: 33 additions & 33 deletions dbms/src/Storages/Page/V3/PageDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
Expand Down Expand Up @@ -119,15 +119,15 @@ 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<PageIdV3Internal> VersionedPageEntries::createNewExternal(const PageVersionType & ver)
std::shared_ptr<PageIdV3Internal> VersionedPageEntries::createNewExternal(const PageVersion & ver)
{
auto page_lock = acquireLock();
if (type == EditRecordType::VAR_DELETE)
{
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<PageIdV3Internal>(0, 0);
Expand All @@ -143,7 +143,7 @@ std::shared_ptr<PageIdV3Internal> 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<PageIdV3Internal>(0, 0);
Expand Down Expand Up @@ -172,7 +172,7 @@ std::shared_ptr<PageIdV3Internal> 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)
Expand Down Expand Up @@ -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)
Expand All @@ -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_)
Expand Down Expand Up @@ -292,14 +292,14 @@ std::shared_ptr<PageIdV3Internal> VersionedPageEntries::fromRestored(const PageE
}
}

std::tuple<VersionedPageEntries::ResolveResult, PageIdV3Internal, PageVersionType>
std::tuple<VersionedPageEntries::ResolveResult, PageIdV3Internal, PageVersion>
VersionedPageEntries::resolveToPageId(UInt64 seq, bool check_prev, PageEntryV3 * entry)
{
auto page_lock = acquireLock();
if (type == EditRecordType::VAR_ENTRY)
{
// entries are sorted by <ver, epoch>, find the first one less than <ver+1, 0>
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}
Expand All @@ -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
Expand All @@ -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
}
}
Expand All @@ -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)
Expand All @@ -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<PageEntryV3> VersionedPageEntries::getEntry(UInt64 seq) const
Expand All @@ -353,7 +353,7 @@ std::optional<PageEntryV3> VersionedPageEntries::getEntry(UInt64 seq) const
if (type == EditRecordType::VAR_ENTRY)
{
// entries are sorted by <ver, epoch>, find the first one less than <ver+1, 0>
if (auto iter = MapUtils::findLess(entries, PageVersionType(seq + 1));
if (auto iter = MapUtils::findLess(entries, PageVersion(seq + 1));
iter != entries.end())
{
// not deleted
Expand Down Expand Up @@ -393,7 +393,7 @@ bool VersionedPageEntries::isVisible(UInt64 seq) const
else if (type == EditRecordType::VAR_ENTRY)
{
// entries are sorted by <ver, epoch>, find the first one less than <ver+1, 0>
if (auto iter = MapUtils::findLess(entries, PageVersionType(seq + 1));
if (auto iter = MapUtils::findLess(entries, PageVersion(seq + 1));
iter != entries.end())
{
// not deleted
Expand All @@ -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())
Expand Down Expand Up @@ -476,7 +476,7 @@ PageSize VersionedPageEntries::getEntriesByBlobIds(

bool VersionedPageEntries::cleanOutdatedEntries(
UInt64 lowest_seq,
std::map<PageIdV3Internal, std::pair<PageVersionType, Int64>> * normal_entries_to_deref,
std::map<PageIdV3Internal, std::pair<PageVersion, Int64>> * normal_entries_to_deref,
PageEntriesV3 & entries_removed,
const PageLock & /*page_lock*/)
{
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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 <seq+1, 0> 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));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -803,8 +803,8 @@ std::pair<PageIDAndEntriesV3, PageIds> 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)
Expand Down Expand Up @@ -866,7 +866,7 @@ std::pair<PageIDAndEntriesV3, PageIds> 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)
{
Expand Down Expand Up @@ -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<bool, PageIdV3Internal, PageVersionType> {
auto [resolve_success, resolved_id, resolved_ver] = [&mvcc_table_directory](PageIdV3Internal id_to_resolve, PageVersion ver_to_resolve)
-> std::tuple<bool, PageIdV3Internal, PageVersion> {
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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1295,7 +1295,7 @@ PageEntriesV3 PageDirectory::gcInMemEntries()

// The page_id that we need to decrease ref count
// { id_0: <version, num to decrease>, id_1: <...>, ... }
std::map<PageIdV3Internal, std::pair<PageVersionType, Int64>> normal_entries_to_deref;
std::map<PageIdV3Internal, std::pair<PageVersion, Int64>> normal_entries_to_deref;
// Iterate all page_id and try to clean up useless var entries
while (true)
{
Expand Down
24 changes: 12 additions & 12 deletions dbms/src/Storages/Page/V3/PageDirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PageIdV3Internal> createNewExternal(const PageVersionType & ver);
std::shared_ptr<PageIdV3Internal> createNewExternal(const PageVersion & ver);

void createDelete(const PageVersionType & ver);
void createDelete(const PageVersion & ver);

std::shared_ptr<PageIdV3Internal> fromRestored(const PageEntriesEdit::EditRecord & rec);

Expand All @@ -165,10 +165,10 @@ class VersionedPageEntries
RESOLVE_TO_REF,
RESOLVE_TO_NORMAL,
};
std::tuple<ResolveResult, PageIdV3Internal, PageVersionType>
std::tuple<ResolveResult, PageIdV3Internal, PageVersion>
resolveToPageId(UInt64 seq, bool check_prev, PageEntryV3 * entry);

Int64 incrRefCount(const PageVersionType & ver);
Int64 incrRefCount(const PageVersion & ver);

std::optional<PageEntryV3> getEntry(UInt64 seq) const;

Expand Down Expand Up @@ -222,13 +222,13 @@ class VersionedPageEntries
*/
bool cleanOutdatedEntries(
UInt64 lowest_seq,
std::map<PageIdV3Internal, std::pair<PageVersionType, Int64>> * normal_entries_to_deref,
std::map<PageIdV3Internal, std::pair<PageVersion, Int64>> * 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);

Expand Down Expand Up @@ -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<PageVersionType, EntryOrDelete> entries;
std::multimap<PageVersion, EntryOrDelete> 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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Page/V3/PageDirectoryFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using WALStoreReaderPtr = std::shared_ptr<WALStoreReader>;
class PageDirectoryFactory
{
public:
PageVersionType max_applied_ver;
PageVersion max_applied_ver;
PageIdV3Internal max_applied_page_id;

PageDirectoryFactory & setBlobStore(BlobStore & blob_store)
Expand Down
Loading

0 comments on commit cb236c1

Please sign in to comment.