Skip to content

Commit

Permalink
mvcc: some locking cleanup
Browse files Browse the repository at this point in the history
Close was notifying waiters before erasing them from the waiters_ list. In
practice this didn't matter: lock_ was always held around any manipulation
of waiters_. But for consistency, let's do what AdjustCleanTime does.

AdjustCleanTime required lock_ to be held, so let's enforce that.

Change-Id: I189553d0f589794ad830a30b3c0b4ce5fd5569ba
Reviewed-on: http://gerrit.cloudera.org:8080/14816
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <[email protected]>
  • Loading branch information
adembo committed Dec 3, 2019
1 parent 618b711 commit 7917a81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/kudu/tablet/mvcc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void MvccManager::CommitTransaction(Timestamp timestamp) {
if (was_earliest && safe_time_ >= timestamp) {
// If this transaction was the earliest in-flight, we might have to adjust
// the "clean" timestamp.
AdjustCleanTime();
AdjustCleanTimeUnlocked();
}
}

Expand Down Expand Up @@ -206,7 +206,7 @@ void MvccManager::AdjustSafeTime(Timestamp safe_time) {
return;
}

AdjustCleanTime();
AdjustCleanTimeUnlocked();
}

// Remove any elements from 'v' which are < the given watermark.
Expand All @@ -226,12 +226,15 @@ void MvccManager::Close() {
std::lock_guard<LockType> l(lock_);
auto iter = waiters_.begin();
while (iter != waiters_.end()) {
(*iter)->latch->CountDown();
auto* waiter = *iter;
iter = waiters_.erase(iter);
waiter->latch->CountDown();
}
}

void MvccManager::AdjustCleanTime() {
void MvccManager::AdjustCleanTimeUnlocked() {
DCHECK(lock_.is_locked());

// There are two possibilities:
//
// 1) We still have an in-flight transaction earlier than 'safe_time_'.
Expand Down Expand Up @@ -269,7 +272,7 @@ void MvccManager::AdjustCleanTime() {
if (PREDICT_FALSE(!waiters_.empty())) {
auto iter = waiters_.begin();
while (iter != waiters_.end()) {
WaitingState* waiter = *iter;
auto* waiter = *iter;
if (IsDoneWaitingUnlocked(*waiter)) {
iter = waiters_.erase(iter);
waiter->latch->CountDown();
Expand Down Expand Up @@ -305,8 +308,8 @@ Status MvccManager::WaitUntil(WaitFor wait_for, Timestamp ts, const MonoTime& de
// We timed out. We need to clean up our entry in the waiters_ array.

std::lock_guard<LockType> l(lock_);
// It's possible that while we were re-acquiring the lock, we did not get
// notified. In that case, we have no cleanup to do.
// It's possible that we got notified while we were re-acquiring the lock. In
// that case, we have no cleanup to do.
if (waiting_state.latch->count() == 0) {
return CheckOpen();
}
Expand Down
4 changes: 3 additions & 1 deletion src/kudu/tablet/mvcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ class MvccManager {
// Adjusts the clean time, i.e. the timestamp such that all transactions with
// lower timestamps are committed or aborted, based on which transactions are
// currently in flight and on what is the latest value of 'safe_time_'.
void AdjustCleanTime();
//
// Must be called with lock_ held.
void AdjustCleanTimeUnlocked();

// Advances the earliest in-flight timestamp, based on which transactions are
// currently in-flight. Usually called when the previous earliest transaction
Expand Down

0 comments on commit 7917a81

Please sign in to comment.