-
Notifications
You must be signed in to change notification settings - Fork 411
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
Review result #376
Changes from 2 commits
e39ea20
ce926fd
61f3d60
29b0006
0252098
e953d5c
a5f4ef2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
#include <cassert> | ||
#include <optional> | ||
// REVIEW: mutex unused | ||
#include <shared_mutex> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
{ | ||
|
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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -105,6 +108,7 @@ class VersionSet | |
|
||
virtual ~VersionSet() | ||
{ | ||
// REVIEW: why this doesn't need the mutex? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
@@ -140,6 +144,7 @@ class VersionSet | |
return sz; | ||
} | ||
|
||
// REVIEW: I read the tests, and I think lock it up should be better | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
std::string toDebugStringUnlocked() const | ||
{ | ||
std::string s; | ||
|
@@ -183,9 +188,11 @@ class VersionSet | |
} | ||
|
||
protected: | ||
// REVIEW: why can't we just use std::list? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
mutable std::shared_mutex read_mutex; | ||
|
||
protected: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,7 @@ class VersionSetWithDelta | |
CurrentMetrics::add(CurrentMetrics::PSMVCCNumSnapshots); | ||
} | ||
|
||
// REVIEW: make sure Snapshot is uncopyable, or this will go wrong | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
~Snapshot() | ||
{ | ||
vset->compactOnDeltaRelease(view.transferTailVersionOwn()); | ||
|
@@ -292,6 +293,7 @@ class VersionSetWithDelta | |
tail.reset(); | ||
} | ||
|
||
// REVIEW: maybe relocate this two methods to VersionType? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -341,6 +343,7 @@ class VersionSetWithDelta | |
} | ||
|
||
protected: | ||
// REVIEW: this name is not accurate, cause this mutex also be used for editing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
mutable std::shared_mutex read_mutex; | ||
VersionPtr current; | ||
SnapshotPtr snapshots; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK