Skip to content

Commit

Permalink
fixed rocksdb get filter partition non-thread safe trigger coredump
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongxiu committed May 28, 2019
1 parent e264eeb commit 24ee5b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 16 additions & 12 deletions table/partitioned_filter_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,21 @@ PartitionedFilterBlockReader::GetFilterPartition(
const bool is_a_filter_partition = true;
auto block_cache = table_->rep_->table_options.block_cache.get();
if (LIKELY(block_cache != nullptr)) {
if (filter_map_.size() != 0) {
auto iter = filter_map_.find(fltr_blk_handle.offset());
// This is a possible scenario since block cache might not have had space
// for the partition
if (iter != filter_map_.end()) {
PERF_COUNTER_ADD(block_cache_hit_count, 1);
RecordTick(statistics(), BLOCK_CACHE_FILTER_HIT);
RecordTick(statistics(), BLOCK_CACHE_HIT);
RecordTick(statistics(), BLOCK_CACHE_BYTES_READ,
block_cache->GetUsage(iter->second.GetCacheHandle()));
return {iter->second.GetValue(), nullptr /* cache */,
nullptr /* cache_handle */, false /* own_value */};
{
MutexLock lock_guard(&mutex_);
if (filter_map_.size() != 0) {
auto iter = filter_map_.find(fltr_blk_handle.offset());
// This is a possible scenario since block cache might not have had space
// for the partition
if (iter != filter_map_.end()) {
PERF_COUNTER_ADD(block_cache_hit_count, 1);
RecordTick(statistics(), BLOCK_CACHE_FILTER_HIT);
RecordTick(statistics(), BLOCK_CACHE_HIT);
RecordTick(statistics(), BLOCK_CACHE_BYTES_READ,
block_cache->GetUsage(iter->second.GetCacheHandle()));
return {iter->second.GetValue(), nullptr /* cache */,
nullptr /* cache_handle */, false /* own_value */};
}
}
}
return table_->GetFilter(/*prefetch_buffer*/ nullptr, fltr_blk_handle,
Expand Down Expand Up @@ -312,6 +315,7 @@ void PartitionedFilterBlockReader::CacheDependencies(
/* get_context */ nullptr, prefix_extractor);
if (LIKELY(filter.IsCached())) {
if (pin) {
MutexLock lock_guard(&mutex_);
filter_map_[handle.offset()] = std::move(filter);
}
}
Expand Down
2 changes: 2 additions & 0 deletions table/partitioned_filter_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "table/full_filter_block.h"
#include "table/index_builder.h"
#include "util/autovector.h"
#include "util/mutexlock.h"

namespace rocksdb {

Expand Down Expand Up @@ -106,6 +107,7 @@ class PartitionedFilterBlockReader : public FilterBlockReader {
const bool index_key_includes_seq_;
const bool index_value_is_full_;
std::unordered_map<uint64_t, CachableEntry<FilterBlockReader>> filter_map_;
port::Mutex mutex_;
};

} // namespace rocksdb

0 comments on commit 24ee5b2

Please sign in to comment.