diff options
author | Yi Wu <yiwu@fb.com> | 2018-10-26 14:27:09 -0700 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2018-10-26 14:30:30 -0700 |
commit | f560c8f5c8904ee36782c8acbe027c8bbfc8175d (patch) | |
tree | 3e7a652d8ab5375326c2096ce01b7633e57cca38 /table | |
parent | 7528130e383d7dbc889f18005d00942ea47118cd (diff) |
s/CacheAllocator/MemoryAllocator/g (#4590)
Summary:
Rename the interface, as it is mean to be a generic interface for memory allocation.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4590
Differential Revision: D10866340
Pulled By: yiwu-arbug
fbshipit-source-id: 85cb753351a40cb856c046aeaa3f3b369eef3d16
Diffstat (limited to 'table')
-rw-r--r-- | table/block_based_table_builder.cc | 4 | ||||
-rw-r--r-- | table/block_based_table_reader.cc | 46 | ||||
-rw-r--r-- | table/block_based_table_reader.h | 4 | ||||
-rw-r--r-- | table/block_fetcher.cc | 2 | ||||
-rw-r--r-- | table/block_fetcher.h | 6 | ||||
-rw-r--r-- | table/format.cc | 6 | ||||
-rw-r--r-- | table/format.h | 6 | ||||
-rw-r--r-- | table/table_test.cc | 18 |
8 files changed, 47 insertions, 45 deletions
diff --git a/table/block_based_table_builder.cc b/table/block_based_table_builder.cc index 26c14d21d..d78f1e27f 100644 --- a/table/block_based_table_builder.cc +++ b/table/block_based_table_builder.cc @@ -39,10 +39,10 @@ #include "table/full_filter_block.h" #include "table/table_builder.h" -#include "util/cache_allocator.h" #include "util/coding.h" #include "util/compression.h" #include "util/crc32c.h" +#include "util/memory_allocator.h" #include "util/stop_watch.h" #include "util/string_util.h" #include "util/xxhash.h" @@ -656,7 +656,7 @@ Status BlockBasedTableBuilder::InsertBlockInCache(const Slice& block_contents, size_t size = block_contents.size(); auto ubuf = - AllocateBlock(size + 1, block_cache_compressed->cache_allocator()); + AllocateBlock(size + 1, block_cache_compressed->memory_allocator()); memcpy(ubuf.get(), block_contents.data(), size); ubuf[size] = type; diff --git a/table/block_based_table_reader.cc b/table/block_based_table_reader.cc index 6595462d0..e6272cee8 100644 --- a/table/block_based_table_reader.cc +++ b/table/block_based_table_reader.cc @@ -80,7 +80,7 @@ Status ReadBlockFromFile( std::unique_ptr<Block>* result, const ImmutableCFOptions& ioptions, bool do_uncompress, const Slice& compression_dict, const PersistentCacheOptions& cache_options, SequenceNumber global_seqno, - size_t read_amp_bytes_per_bit, CacheAllocator* allocator = nullptr, + size_t read_amp_bytes_per_bit, MemoryAllocator* allocator = nullptr, const bool immortal_file = false) { BlockContents contents; BlockFetcher block_fetcher( @@ -95,10 +95,10 @@ Status ReadBlockFromFile( return s; } -inline CacheAllocator* GetCacheAllocator( +inline MemoryAllocator* GetMemoryAllocator( const BlockBasedTableOptions& table_options) { return table_options.block_cache.get() - ? table_options.block_cache->cache_allocator() + ? table_options.block_cache->memory_allocator() : nullptr; } @@ -1160,7 +1160,7 @@ Status BlockBasedTable::ReadMetaBlock(Rep* rep, rep->footer.metaindex_handle(), &meta, rep->ioptions, true /* decompress */, Slice() /*compression dict*/, rep->persistent_cache_options, kDisableGlobalSequenceNumber, - 0 /* read_amp_bytes_per_bit */, GetCacheAllocator(rep->table_options)); + 0 /* read_amp_bytes_per_bit */, GetMemoryAllocator(rep->table_options)); if (!s.ok()) { ROCKS_LOG_ERROR(rep->ioptions.info_log, @@ -1183,7 +1183,7 @@ Status BlockBasedTable::GetDataBlockFromCache( const ImmutableCFOptions& ioptions, const ReadOptions& read_options, BlockBasedTable::CachableEntry<Block>* block, uint32_t format_version, const Slice& compression_dict, size_t read_amp_bytes_per_bit, bool is_index, - GetContext* get_context, CacheAllocator* allocator) { + GetContext* get_context, MemoryAllocator* allocator) { Status s; Block* compressed_block = nullptr; Cache::Handle* block_cache_compressed_handle = nullptr; @@ -1303,7 +1303,7 @@ Status BlockBasedTable::PutDataBlockToCache( CachableEntry<Block>* block, Block* raw_block, uint32_t format_version, const Slice& compression_dict, size_t read_amp_bytes_per_bit, bool is_index, Cache::Priority priority, GetContext* get_context, - CacheAllocator* allocator) { + MemoryAllocator* allocator) { assert(raw_block->compression_type() == kNoCompression || block_cache_compressed != nullptr); @@ -1414,7 +1414,7 @@ FilterBlockReader* BlockBasedTable::ReadFilter( ReadOptions(), filter_handle, &block, rep->ioptions, false /* decompress */, dummy_comp_dict, rep->persistent_cache_options, - GetCacheAllocator(rep->table_options)); + GetMemoryAllocator(rep->table_options)); Status s = block_fetcher.ReadBlockContents(); if (!s.ok()) { @@ -1713,7 +1713,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator( compression_dict, rep->persistent_cache_options, is_index ? kDisableGlobalSequenceNumber : rep->global_seqno, rep->table_options.read_amp_bytes_per_bit, - GetCacheAllocator(rep->table_options), rep->immortal_table); + GetMemoryAllocator(rep->table_options), rep->immortal_table); } if (s.ok()) { block.value = block_value.release(); @@ -1806,7 +1806,7 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache( key, ckey, block_cache, block_cache_compressed, rep->ioptions, ro, block_entry, rep->table_options.format_version, compression_dict, rep->table_options.read_amp_bytes_per_bit, is_index, get_context, - GetCacheAllocator(rep->table_options)); + GetMemoryAllocator(rep->table_options)); if (block_entry->value == nullptr && !no_io && ro.fill_cache) { std::unique_ptr<Block> raw_block; @@ -1819,7 +1819,7 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache( compression_dict, rep->persistent_cache_options, is_index ? kDisableGlobalSequenceNumber : rep->global_seqno, rep->table_options.read_amp_bytes_per_bit, - GetCacheAllocator(rep->table_options), rep->immortal_table); + GetMemoryAllocator(rep->table_options), rep->immortal_table); } if (s.ok()) { @@ -1832,7 +1832,7 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache( .cache_index_and_filter_blocks_with_high_priority ? Cache::Priority::HIGH : Cache::Priority::LOW, - get_context, GetCacheAllocator(rep->table_options)); + get_context, GetMemoryAllocator(rep->table_options)); } } } @@ -2553,11 +2553,12 @@ Status BlockBasedTable::VerifyChecksumInBlocks( BlockHandle handle = index_iter->value(); BlockContents contents; Slice dummy_comp_dict; - BlockFetcher block_fetcher( - rep_->file.get(), nullptr /* prefetch buffer */, rep_->footer, - ReadOptions(), handle, &contents, rep_->ioptions, - false /* decompress */, dummy_comp_dict /*compression dict*/, - rep_->persistent_cache_options, GetCacheAllocator(rep_->table_options)); + BlockFetcher block_fetcher(rep_->file.get(), nullptr /* prefetch buffer */, + rep_->footer, ReadOptions(), handle, &contents, + rep_->ioptions, false /* decompress */, + dummy_comp_dict /*compression dict*/, + rep_->persistent_cache_options, + GetMemoryAllocator(rep_->table_options)); s = block_fetcher.ReadBlockContents(); if (!s.ok()) { break; @@ -2579,11 +2580,12 @@ Status BlockBasedTable::VerifyChecksumInBlocks( s = handle.DecodeFrom(&input); BlockContents contents; Slice dummy_comp_dict; - BlockFetcher block_fetcher( - rep_->file.get(), nullptr /* prefetch buffer */, rep_->footer, - ReadOptions(), handle, &contents, rep_->ioptions, - false /* decompress */, dummy_comp_dict /*compression dict*/, - rep_->persistent_cache_options, GetCacheAllocator(rep_->table_options)); + BlockFetcher block_fetcher(rep_->file.get(), nullptr /* prefetch buffer */, + rep_->footer, ReadOptions(), handle, &contents, + rep_->ioptions, false /* decompress */, + dummy_comp_dict /*compression dict*/, + rep_->persistent_cache_options, + GetMemoryAllocator(rep_->table_options)); s = block_fetcher.ReadBlockContents(); if (!s.ok()) { break; @@ -2888,7 +2890,7 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file, ReadOptions(), handle, &block, rep_->ioptions, false /*decompress*/, dummy_comp_dict /*compression dict*/, rep_->persistent_cache_options, - GetCacheAllocator(rep_->table_options)); + GetMemoryAllocator(rep_->table_options)); s = block_fetcher.ReadBlockContents(); if (!s.ok()) { rep_->filter.reset(new BlockBasedFilterBlockReader( diff --git a/table/block_based_table_reader.h b/table/block_based_table_reader.h index c3dd3d2f1..3502c26c4 100644 --- a/table/block_based_table_reader.h +++ b/table/block_based_table_reader.h @@ -305,7 +305,7 @@ class BlockBasedTable : public TableReader { BlockBasedTable::CachableEntry<Block>* block, uint32_t format_version, const Slice& compression_dict, size_t read_amp_bytes_per_bit, bool is_index = false, GetContext* get_context = nullptr, - CacheAllocator* allocator = nullptr); + MemoryAllocator* allocator = nullptr); // Put a raw block (maybe compressed) to the corresponding block caches. // This method will perform decompression against raw_block if needed and then @@ -324,7 +324,7 @@ class BlockBasedTable : public TableReader { CachableEntry<Block>* block, Block* raw_block, uint32_t format_version, const Slice& compression_dict, size_t read_amp_bytes_per_bit, bool is_index = false, Cache::Priority pri = Cache::Priority::LOW, - GetContext* get_context = nullptr, CacheAllocator* allocator = nullptr); + GetContext* get_context = nullptr, MemoryAllocator* allocator = nullptr); // Calls (*handle_result)(arg, ...) repeatedly, starting with the entry found // after a call to Seek(key), until handle_result returns false. diff --git a/table/block_fetcher.cc b/table/block_fetcher.cc index 489705758..b2873574c 100644 --- a/table/block_fetcher.cc +++ b/table/block_fetcher.cc @@ -19,12 +19,12 @@ #include "table/block_based_table_reader.h" #include "table/format.h" #include "table/persistent_cache_helper.h" -#include "util/cache_allocator.h" #include "util/coding.h" #include "util/compression.h" #include "util/crc32c.h" #include "util/file_reader_writer.h" #include "util/logging.h" +#include "util/memory_allocator.h" #include "util/stop_watch.h" #include "util/string_util.h" #include "util/xxhash.h" diff --git a/table/block_fetcher.h b/table/block_fetcher.h index a8d9d6572..c277f3b67 100644 --- a/table/block_fetcher.h +++ b/table/block_fetcher.h @@ -11,7 +11,7 @@ #include "table/block.h" #include "table/format.h" -#include "util/cache_allocator.h" +#include "util/memory_allocator.h" namespace rocksdb { class BlockFetcher { @@ -28,7 +28,7 @@ class BlockFetcher { BlockContents* contents, const ImmutableCFOptions& ioptions, bool do_uncompress, const Slice& compression_dict, const PersistentCacheOptions& cache_options, - CacheAllocator* allocator = nullptr, + MemoryAllocator* allocator = nullptr, const bool immortal_source = false) : file_(file), prefetch_buffer_(prefetch_buffer), @@ -58,7 +58,7 @@ class BlockFetcher { const bool immortal_source_; const Slice& compression_dict_; const PersistentCacheOptions& cache_options_; - CacheAllocator* allocator_; + MemoryAllocator* allocator_; Status status_; Slice slice_; char* used_buf_ = nullptr; diff --git a/table/format.cc b/table/format.cc index 3eaa97065..62f5ab6dc 100644 --- a/table/format.cc +++ b/table/format.cc @@ -19,12 +19,12 @@ #include "table/block_based_table_reader.h" #include "table/block_fetcher.h" #include "table/persistent_cache_helper.h" -#include "util/cache_allocator.h" #include "util/coding.h" #include "util/compression.h" #include "util/crc32c.h" #include "util/file_reader_writer.h" #include "util/logging.h" +#include "util/memory_allocator.h" #include "util/stop_watch.h" #include "util/string_util.h" #include "util/xxhash.h" @@ -280,7 +280,7 @@ Status ReadFooterFromFile(RandomAccessFileReader* file, Status UncompressBlockContentsForCompressionType( const UncompressionContext& uncompression_ctx, const char* data, size_t n, BlockContents* contents, uint32_t format_version, - const ImmutableCFOptions& ioptions, CacheAllocator* allocator) { + const ImmutableCFOptions& ioptions, MemoryAllocator* allocator) { CacheAllocationPtr ubuf; assert(uncompression_ctx.type() != kNoCompression && @@ -405,7 +405,7 @@ Status UncompressBlockContents(const UncompressionContext& uncompression_ctx, const char* data, size_t n, BlockContents* contents, uint32_t format_version, const ImmutableCFOptions& ioptions, - CacheAllocator* allocator) { + MemoryAllocator* allocator) { assert(data[n] != kNoCompression); assert(data[n] == uncompression_ctx.type()); return UncompressBlockContentsForCompressionType(uncompression_ctx, data, n, diff --git a/table/format.h b/table/format.h index aa6b123f0..e40616eb2 100644 --- a/table/format.h +++ b/table/format.h @@ -25,8 +25,8 @@ #include "options/cf_options.h" #include "port/port.h" // noexcept #include "table/persistent_cache_options.h" -#include "util/cache_allocator.h" #include "util/file_reader_writer.h" +#include "util/memory_allocator.h" namespace rocksdb { @@ -265,7 +265,7 @@ extern Status ReadBlockContents( extern Status UncompressBlockContents( const UncompressionContext& uncompression_ctx, const char* data, size_t n, BlockContents* contents, uint32_t compress_format_version, - const ImmutableCFOptions& ioptions, CacheAllocator* allocator = nullptr); + const ImmutableCFOptions& ioptions, MemoryAllocator* allocator = nullptr); // This is an extension to UncompressBlockContents that accepts // a specific compression type. This is used by un-wrapped blocks @@ -273,7 +273,7 @@ extern Status UncompressBlockContents( extern Status UncompressBlockContentsForCompressionType( const UncompressionContext& uncompression_ctx, const char* data, size_t n, BlockContents* contents, uint32_t compress_format_version, - const ImmutableCFOptions& ioptions, CacheAllocator* allocator = nullptr); + const ImmutableCFOptions& ioptions, MemoryAllocator* allocator = nullptr); // Implementation details follow. Clients should ignore, diff --git a/table/table_test.cc b/table/table_test.cc index f4fc82b5c..a17c78638 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -2486,14 +2486,14 @@ TEST_P(BlockBasedTableTest, BlockCacheLeak) { } namespace { -class CustomCacheAllocator : public CacheAllocator { +class CustomMemoryAllocator : public MemoryAllocator { public: - virtual const char* Name() const override { return "CustomCacheAllocator"; } + virtual const char* Name() const override { return "CustomMemoryAllocator"; } void* Allocate(size_t size) override { ++numAllocations; auto ptr = new char[size + 16]; - memcpy(ptr, "cache_allocator_", 16); // mangle first 16 bytes + memcpy(ptr, "memory_allocator_", 16); // mangle first 16 bytes return reinterpret_cast<void*>(ptr + 16); } void Deallocate(void* p) override { @@ -2507,8 +2507,8 @@ class CustomCacheAllocator : public CacheAllocator { }; } // namespace -TEST_P(BlockBasedTableTest, CacheAllocator) { - auto custom_cache_allocator = std::make_shared<CustomCacheAllocator>(); +TEST_P(BlockBasedTableTest, MemoryAllocator) { + auto custom_memory_allocator = std::make_shared<CustomMemoryAllocator>(); { Options opt; unique_ptr<InternalKeyComparator> ikc; @@ -2517,7 +2517,7 @@ TEST_P(BlockBasedTableTest, CacheAllocator) { BlockBasedTableOptions table_options; table_options.block_size = 1024; LRUCacheOptions lruOptions; - lruOptions.cache_allocator = custom_cache_allocator; + lruOptions.memory_allocator = custom_memory_allocator; lruOptions.capacity = 16 * 1024 * 1024; lruOptions.num_shard_bits = 4; table_options.block_cache = NewLRUCache(std::move(lruOptions)); @@ -2551,10 +2551,10 @@ TEST_P(BlockBasedTableTest, CacheAllocator) { // out of scope, block cache should have been deleted, all allocations // deallocated - EXPECT_EQ(custom_cache_allocator->numAllocations.load(), - custom_cache_allocator->numDeallocations.load()); + EXPECT_EQ(custom_memory_allocator->numAllocations.load(), + custom_memory_allocator->numDeallocations.load()); // make sure that allocations actually happened through the cache allocator - EXPECT_GT(custom_cache_allocator->numAllocations.load(), 0); + EXPECT_GT(custom_memory_allocator->numAllocations.load(), 0); } TEST_P(BlockBasedTableTest, NewIndexIteratorLeak) { |