Skip to content

Commit

Permalink
Fix DBTest.FlushSchedule
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi Wu committed May 18, 2017
1 parent d107f4b commit 2a93957
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions db/flush_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ namespace rocksdb {

void FlushScheduler::ScheduleFlush(ColumnFamilyData* cfd) {
#ifndef NDEBUG
{
std::lock_guard<std::mutex> lock(checking_mutex_);
assert(checking_set_.count(cfd) == 0);
checking_set_.insert(cfd);
}
std::lock_guard<std::mutex> lock(checking_mutex_);
assert(checking_set_.count(cfd) == 0);
checking_set_.insert(cfd);
#endif // NDEBUG
cfd->Ref();
// Suppress false positive clang analyzer warnings.
Expand All @@ -36,8 +34,11 @@ void FlushScheduler::ScheduleFlush(ColumnFamilyData* cfd) {
}

ColumnFamilyData* FlushScheduler::TakeNextColumnFamily() {
#ifndef NDEBUG
std::lock_guard<std::mutex> lock(checking_mutex_);
#endif // NDEBUG
while (true) {
if (Empty()) {
if (head_.load(std::memory_order_relaxed) == nullptr) {
return nullptr;
}

Expand All @@ -48,12 +49,9 @@ ColumnFamilyData* FlushScheduler::TakeNextColumnFamily() {
delete node;

#ifndef NDEBUG
{
std::lock_guard<std::mutex> lock(checking_mutex_);
auto iter = checking_set_.find(cfd);
assert(iter != checking_set_.end());
checking_set_.erase(iter);
}
auto iter = checking_set_.find(cfd);
assert(iter != checking_set_.end());
checking_set_.erase(iter);
#endif // NDEBUG

if (!cfd->IsDropped()) {
Expand All @@ -69,8 +67,13 @@ ColumnFamilyData* FlushScheduler::TakeNextColumnFamily() {
}

bool FlushScheduler::Empty() {
#ifndef NDEBUG
std::lock_guard<std::mutex> lock(checking_mutex_);
#endif // NDEBUG
auto rv = head_.load(std::memory_order_relaxed) == nullptr;
// assert(rv == checking_set_.empty());
#ifndef NDEBUG
assert(rv == checking_set_.empty());
#endif // NDEBUG
return rv;
}

Expand All @@ -81,7 +84,7 @@ void FlushScheduler::Clear() {
delete cfd;
}
}
assert(Empty());
assert(head_.load(std::memory_order_relaxed) == nullptr);
}

} // namespace rocksdb
2 changes: 1 addition & 1 deletion db/write_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class WriteThread {
Status FinalStatus() {
if (!status.ok()) {
// a non-ok memtable write status takes presidence
// assert(callback == nullptr || callback_status.ok());
assert(callback == nullptr || callback_status.ok());
return status;
} else if (!callback_status.ok()) {
// if the callback failed then that is the status we want
Expand Down

0 comments on commit 2a93957

Please sign in to comment.