c2029f9716
Summary: It's easy to cause coredump when closing ColumnFamilyHandle with unreleased iterators, especially iterators release is controlled by java GC when using JNI. This patch fixed concurrent CF iteration and drop, we let iterators(actually SuperVersion) hold a ColumnFamilyData reference to prevent the CF from being released too early. fixed https://github.com/facebook/rocksdb/issues/5982 Pull Request resolved: https://github.com/facebook/rocksdb/pull/6147 Differential Revision: D18926378 fbshipit-source-id: 1dff6d068c603d012b81446812368bfee95a5e15
55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#include "db/trim_history_scheduler.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include "db/column_family.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
void TrimHistoryScheduler::ScheduleWork(ColumnFamilyData* cfd) {
|
|
std::lock_guard<std::mutex> lock(checking_mutex_);
|
|
cfd->Ref();
|
|
cfds_.push_back(cfd);
|
|
is_empty_.store(false, std::memory_order_relaxed);
|
|
}
|
|
|
|
ColumnFamilyData* TrimHistoryScheduler::TakeNextColumnFamily() {
|
|
std::lock_guard<std::mutex> lock(checking_mutex_);
|
|
while (true) {
|
|
if (cfds_.empty()) {
|
|
return nullptr;
|
|
}
|
|
ColumnFamilyData* cfd = cfds_.back();
|
|
cfds_.pop_back();
|
|
if (cfds_.empty()) {
|
|
is_empty_.store(true, std::memory_order_relaxed);
|
|
}
|
|
|
|
if (!cfd->IsDropped()) {
|
|
// success
|
|
return cfd;
|
|
}
|
|
cfd->UnrefAndTryDelete();
|
|
}
|
|
}
|
|
|
|
bool TrimHistoryScheduler::Empty() {
|
|
bool is_empty = is_empty_.load(std::memory_order_relaxed);
|
|
return is_empty;
|
|
}
|
|
|
|
void TrimHistoryScheduler::Clear() {
|
|
ColumnFamilyData* cfd;
|
|
while ((cfd = TakeNextColumnFamily()) != nullptr) {
|
|
cfd->UnrefAndTryDelete();
|
|
}
|
|
assert(Empty());
|
|
}
|
|
|
|
} // namespace rocksdb
|