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

Review result #376

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions dbms/src/Storages/Page/PageEntries.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cassert>
#include <optional>
// REVIEW: mutex unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

#include <shared_mutex>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -232,6 +233,7 @@ void PageEntriesMixin<T>::put(PageId page_id, const PageEntry & entry)
max_page_id = std::max(max_page_id, page_id);
}

// REVIEW: the name `move` confused me for a while, until I see this code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to updateNormalPage

template <typename T>
void PageEntriesMixin<T>::move_normal_page(PageId normal_page_id, PageEntry entry)
{
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Storages/Page/PageFile.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

// REVIEW: mutex unused
#include <mutex>
#include <unordered_map>
#include <vector>
Expand Down
4 changes: 4 additions & 0 deletions dbms/src/Storages/Page/VersionSet/PageEntriesEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class PageEntriesEdit
struct EditRecord
{
WriteBatch::WriteType type;
// REVIEW: small opinion: I think this is a bit over engineering, cause this struct doesn't need to serialize,
// even if it need to serialize, we could use pragma packing,
// or use union{char, uint32}, union can be more reliable (if we change the type of WriteType, it don't cause problem)
// manually padding seems to be the worst way to do it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

char _padding[7]; // 7 bytes unused since type is only 1 byte.
PageId page_id;
PageId ori_page_id;
Expand Down
7 changes: 7 additions & 0 deletions dbms/src/Storages/Page/mvcc/VersionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ template <typename T>
struct MultiVersionCountable
{
public:
// REVIEW: thit two status: <this is valid, ref count> are related, and should be under a same mutex
std::atomic<uint32_t> ref_count;
T * next;
T * prev;
Expand All @@ -41,9 +42,11 @@ struct MultiVersionCountable

void incrRefCount() { ++ref_count; }

// REVIEW: MS used the method names of increase/release, is a stander name, we could use it too.
void decrRefCount(std::shared_mutex & mutex)
{
assert(ref_count >= 1);
// REVIEW: potential bug: 2 threads detected that ref_count == 1, then both execute delete (execute one by one cause by mutex)
if (--ref_count == 0)
{
// in case two neighbor nodes remove from linked list
Expand Down Expand Up @@ -105,6 +108,7 @@ class VersionSet

virtual ~VersionSet()
{
// REVIEW: why this doesn't need the mutex?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All versions of this VersionSet must be released before destructuring VersionSet, so we don't need to lock on mutex.

current->decrRefCount();
assert(placeholder_node.next == &placeholder_node); // List must be empty
}
Expand Down Expand Up @@ -140,6 +144,7 @@ class VersionSet
return sz;
}

// REVIEW: I read the tests, and I think lock it up should be better
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

std::string toDebugStringUnlocked() const
{
std::string s;
Expand Down Expand Up @@ -183,9 +188,11 @@ class VersionSet
}

protected:
// REVIEW: why can't we just use std::list?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we can lock on small parts of versions instead of the whole version-list, but now it seems to be the same as lock over the list...

VersionType placeholder_node; // Head of circular double-linked list of all versions
VersionPtr current; // current version; current == placeholder_node.prev

// REVIEW: this name is not accurate, cause this mutex also be used for editing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

mutable std::shared_mutex read_mutex;

protected:
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Storages/Page/mvcc/VersionSetWithDelta.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class VersionSetWithDelta
CurrentMetrics::add(CurrentMetrics::PSMVCCNumSnapshots);
}

// REVIEW: make sure Snapshot is uncopyable, or this will go wrong
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

~Snapshot()
{
vset->compactOnDeltaRelease(view.transferTailVersionOwn());
Expand Down Expand Up @@ -292,6 +293,7 @@ class VersionSetWithDelta
tail.reset();
}

// REVIEW: maybe relocate this two methods to VersionType?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

virtual VersionPtr compactDeltas(const VersionPtr & tail) const = 0;

virtual VersionPtr compactDeltaAndBase(const VersionPtr & old_base, const VersionPtr & delta) const = 0;
Expand Down Expand Up @@ -341,6 +343,7 @@ class VersionSetWithDelta
}

protected:
// REVIEW: this name is not accurate, cause this mutex also be used for editing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

mutable std::shared_mutex read_mutex;
VersionPtr current;
SnapshotPtr snapshots;
Expand Down