mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Get rid of some shared_ptrs
Summary: I went through all remaining shared_ptrs and removed the ones that I found not-necessary. Only GenerateCachePrefix() is called fairly often, so don't expect much perf wins. The ones that are left are accessed infrequently and I think we're fine with keeping them. Test Plan: make asan_check Reviewers: dhruba, haobo Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D14427
This commit is contained in:
@@ -127,9 +127,10 @@ BlockBasedTableBuilder::BlockBasedTableBuilder(
|
||||
rep_->filter_block->StartBlock(0);
|
||||
}
|
||||
if (options.block_cache_compressed.get() != nullptr) {
|
||||
BlockBasedTable::GenerateCachePrefix(options.block_cache_compressed, file,
|
||||
&rep_->compressed_cache_key_prefix[0],
|
||||
&rep_->compressed_cache_key_prefix_size);
|
||||
BlockBasedTable::GenerateCachePrefix(
|
||||
options.block_cache_compressed.get(), file,
|
||||
&rep_->compressed_cache_key_prefix[0],
|
||||
&rep_->compressed_cache_key_prefix_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,18 +95,18 @@ void BlockBasedTable::SetupCacheKeyPrefix(Rep* rep) {
|
||||
rep->cache_key_prefix_size = 0;
|
||||
rep->compressed_cache_key_prefix_size = 0;
|
||||
if (rep->options.block_cache != nullptr) {
|
||||
GenerateCachePrefix(rep->options.block_cache, rep->file.get(),
|
||||
GenerateCachePrefix(rep->options.block_cache.get(), rep->file.get(),
|
||||
&rep->cache_key_prefix[0],
|
||||
&rep->cache_key_prefix_size);
|
||||
}
|
||||
if (rep->options.block_cache_compressed != nullptr) {
|
||||
GenerateCachePrefix(rep->options.block_cache_compressed, rep->file.get(),
|
||||
&rep->compressed_cache_key_prefix[0],
|
||||
GenerateCachePrefix(rep->options.block_cache_compressed.get(),
|
||||
rep->file.get(), &rep->compressed_cache_key_prefix[0],
|
||||
&rep->compressed_cache_key_prefix_size);
|
||||
}
|
||||
}
|
||||
|
||||
void BlockBasedTable::GenerateCachePrefix(shared_ptr<Cache> cc,
|
||||
void BlockBasedTable::GenerateCachePrefix(Cache* cc,
|
||||
RandomAccessFile* file, char* buffer, size_t* size) {
|
||||
|
||||
// generate an id from the file
|
||||
@@ -120,7 +120,7 @@ void BlockBasedTable::GenerateCachePrefix(shared_ptr<Cache> cc,
|
||||
}
|
||||
}
|
||||
|
||||
void BlockBasedTable::GenerateCachePrefix(shared_ptr<Cache> cc,
|
||||
void BlockBasedTable::GenerateCachePrefix(Cache* cc,
|
||||
WritableFile* file, char* buffer, size_t* size) {
|
||||
|
||||
// generate an id from the file
|
||||
|
||||
@@ -167,9 +167,9 @@ class BlockBasedTable : public TableReader {
|
||||
rep_ = rep;
|
||||
}
|
||||
// Generate a cache key prefix from the file
|
||||
static void GenerateCachePrefix(shared_ptr<Cache> cc,
|
||||
static void GenerateCachePrefix(Cache* cc,
|
||||
RandomAccessFile* file, char* buffer, size_t* size);
|
||||
static void GenerateCachePrefix(shared_ptr<Cache> cc,
|
||||
static void GenerateCachePrefix(Cache* cc,
|
||||
WritableFile* file, char* buffer, size_t* size);
|
||||
|
||||
// The longest prefix of the cache key used to identify blocks.
|
||||
|
||||
@@ -370,7 +370,7 @@ class MemTableConstructor: public Constructor {
|
||||
: Constructor(cmp),
|
||||
internal_comparator_(cmp),
|
||||
table_factory_(new SkipListFactory) {
|
||||
memtable_ = new MemTable(internal_comparator_, table_factory_);
|
||||
memtable_ = new MemTable(internal_comparator_, table_factory_.get());
|
||||
memtable_->Ref();
|
||||
}
|
||||
~MemTableConstructor() {
|
||||
@@ -378,7 +378,7 @@ class MemTableConstructor: public Constructor {
|
||||
}
|
||||
virtual Status FinishImpl(const Options& options, const KVMap& data) {
|
||||
delete memtable_->Unref();
|
||||
memtable_ = new MemTable(internal_comparator_, table_factory_);
|
||||
memtable_ = new MemTable(internal_comparator_, table_factory_.get());
|
||||
memtable_->Ref();
|
||||
int seq = 1;
|
||||
for (KVMap::const_iterator it = data.begin();
|
||||
@@ -930,19 +930,19 @@ TEST(TableTest, NumBlockStat) {
|
||||
|
||||
class BlockCacheProperties {
|
||||
public:
|
||||
explicit BlockCacheProperties(std::shared_ptr<Statistics> statistics) {
|
||||
explicit BlockCacheProperties(Statistics* statistics) {
|
||||
block_cache_miss =
|
||||
statistics.get()->getTickerCount(BLOCK_CACHE_MISS);
|
||||
statistics->getTickerCount(BLOCK_CACHE_MISS);
|
||||
block_cache_hit =
|
||||
statistics.get()->getTickerCount(BLOCK_CACHE_HIT);
|
||||
statistics->getTickerCount(BLOCK_CACHE_HIT);
|
||||
index_block_cache_miss =
|
||||
statistics.get()->getTickerCount(BLOCK_CACHE_INDEX_MISS);
|
||||
statistics->getTickerCount(BLOCK_CACHE_INDEX_MISS);
|
||||
index_block_cache_hit =
|
||||
statistics.get()->getTickerCount(BLOCK_CACHE_INDEX_HIT);
|
||||
statistics->getTickerCount(BLOCK_CACHE_INDEX_HIT);
|
||||
data_block_cache_miss =
|
||||
statistics.get()->getTickerCount(BLOCK_CACHE_DATA_MISS);
|
||||
statistics->getTickerCount(BLOCK_CACHE_DATA_MISS);
|
||||
data_block_cache_hit =
|
||||
statistics.get()->getTickerCount(BLOCK_CACHE_DATA_HIT);
|
||||
statistics->getTickerCount(BLOCK_CACHE_DATA_HIT);
|
||||
}
|
||||
|
||||
// Check if the fetched props matches the expected ones.
|
||||
@@ -993,7 +993,7 @@ TEST(TableTest, BlockCacheTest) {
|
||||
|
||||
// At first, no block will be accessed.
|
||||
{
|
||||
BlockCacheProperties props(options.statistics);
|
||||
BlockCacheProperties props(options.statistics.get());
|
||||
// index will be added to block cache.
|
||||
props.AssertEqual(
|
||||
1, // index block miss
|
||||
@@ -1006,7 +1006,7 @@ TEST(TableTest, BlockCacheTest) {
|
||||
// Only index block will be accessed
|
||||
{
|
||||
iter.reset(c.NewIterator());
|
||||
BlockCacheProperties props(options.statistics);
|
||||
BlockCacheProperties props(options.statistics.get());
|
||||
// NOTE: to help better highlight the "detla" of each ticker, I use
|
||||
// <last_value> + <added_value> to indicate the increment of changed
|
||||
// value; other numbers remain the same.
|
||||
@@ -1021,7 +1021,7 @@ TEST(TableTest, BlockCacheTest) {
|
||||
// Only data block will be accessed
|
||||
{
|
||||
iter->SeekToFirst();
|
||||
BlockCacheProperties props(options.statistics);
|
||||
BlockCacheProperties props(options.statistics.get());
|
||||
props.AssertEqual(
|
||||
1,
|
||||
1,
|
||||
@@ -1034,7 +1034,7 @@ TEST(TableTest, BlockCacheTest) {
|
||||
{
|
||||
iter.reset(c.NewIterator());
|
||||
iter->SeekToFirst();
|
||||
BlockCacheProperties props(options.statistics);
|
||||
BlockCacheProperties props(options.statistics.get());
|
||||
props.AssertEqual(
|
||||
1,
|
||||
1 + 1, // index block hit
|
||||
@@ -1054,7 +1054,7 @@ TEST(TableTest, BlockCacheTest) {
|
||||
iter.reset(c.NewIterator());
|
||||
iter->SeekToFirst();
|
||||
ASSERT_EQ("key", iter->key().ToString());
|
||||
BlockCacheProperties props(options.statistics);
|
||||
BlockCacheProperties props(options.statistics.get());
|
||||
// Nothing is affected at all
|
||||
props.AssertEqual(0, 0, 0, 0);
|
||||
}
|
||||
@@ -1065,7 +1065,7 @@ TEST(TableTest, BlockCacheTest) {
|
||||
options.block_cache = NewLRUCache(1);
|
||||
c.Reopen(options);
|
||||
{
|
||||
BlockCacheProperties props(options.statistics);
|
||||
BlockCacheProperties props(options.statistics.get());
|
||||
props.AssertEqual(
|
||||
1, // index block miss
|
||||
0,
|
||||
@@ -1080,7 +1080,7 @@ TEST(TableTest, BlockCacheTest) {
|
||||
// It first cache index block then data block. But since the cache size
|
||||
// is only 1, index block will be purged after data block is inserted.
|
||||
iter.reset(c.NewIterator());
|
||||
BlockCacheProperties props(options.statistics);
|
||||
BlockCacheProperties props(options.statistics.get());
|
||||
props.AssertEqual(
|
||||
1 + 1, // index block miss
|
||||
0,
|
||||
@@ -1093,7 +1093,7 @@ TEST(TableTest, BlockCacheTest) {
|
||||
// SeekToFirst() accesses data block. With similar reason, we expect data
|
||||
// block's cache miss.
|
||||
iter->SeekToFirst();
|
||||
BlockCacheProperties props(options.statistics);
|
||||
BlockCacheProperties props(options.statistics.get());
|
||||
props.AssertEqual(
|
||||
2,
|
||||
0,
|
||||
@@ -1268,7 +1268,7 @@ class MemTableTest { };
|
||||
TEST(MemTableTest, Simple) {
|
||||
InternalKeyComparator cmp(BytewiseComparator());
|
||||
auto table_factory = std::make_shared<SkipListFactory>();
|
||||
MemTable* memtable = new MemTable(cmp, table_factory);
|
||||
MemTable* memtable = new MemTable(cmp, table_factory.get());
|
||||
memtable->Ref();
|
||||
WriteBatch batch;
|
||||
Options options;
|
||||
|
||||
Reference in New Issue
Block a user