-
Notifications
You must be signed in to change notification settings - Fork 119
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
Delete iterator in replication_test #295
base: master
Are you sure you want to change the base?
Conversation
c1f83cd
to
0bf47a9
Compare
0bf47a9
to
40b0bc2
Compare
@@ -4092,7 +4094,8 @@ Status DBImpl::GetSuperSnapshots( | |||
for (auto& cf : column_families) { | |||
auto cfh = static_cast_with_check<ColumnFamilyHandleImpl>(cf); | |||
auto cfd = cfh->cfd(); | |||
auto sv = cfd->GetReferencedSuperVersion(this); | |||
auto sv = cfd->GetSuperVersion(); | |||
sv->Ref(); |
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.
Not sure what the difference is here could you give me some context?
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.
They are equivalent, but GetReferencedSuperVersion()
is meant to (and optimized to) be called outside of the lock. By adding a mutex to GetSuperSnapshots()
(oops) it caused a deadlock :)
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.
It's using quite an interesting technique:
rocksdb-cloud/db/column_family.cc
Lines 1260 to 1277 in 43810fe
// The SuperVersion is cached in thread local storage to avoid acquiring | |
// mutex when SuperVersion does not change since the last use. When a new | |
// SuperVersion is installed, the compaction or flush thread cleans up | |
// cached SuperVersion in all existing thread local storage. To avoid | |
// acquiring mutex for this operation, we use atomic Swap() on the thread | |
// local pointer to guarantee exclusive access. If the thread local pointer | |
// is being used while a new SuperVersion is installed, the cached | |
// SuperVersion can become stale. In that case, the background thread would | |
// have swapped in kSVObsolete. We re-check the value at when returning | |
// SuperVersion back to thread local, with an atomic compare and swap. | |
// The superversion will need to be released if detected to be stale. | |
void* ptr = local_sv_->Swap(SuperVersion::kSVInUse); | |
// Invariant: | |
// (1) Scrape (always) installs kSVObsolete in ThreadLocal storage | |
// (2) the Swap above (always) installs kSVInUse, ThreadLocal storage | |
// should only keep kSVInUse before ReturnThreadLocalSuperVersion call | |
// (if no Scrape happens). | |
assert(ptr != SuperVersion::kSVInUse); |
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.
Will have to read more outside the function but definitely interesting. Not quite clear to me how thread local super versions get cleaned after a swap since local_sv becomes obsolete (dump thread does it? but then wouldn't that mess up the currently used sv for the thread?)
No description provided.