|
|
@ -6,6 +6,9 @@ |
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <inttypes.h> |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include <algorithm> |
|
|
|
#include <algorithm> |
|
|
|
#include <map> |
|
|
|
#include <map> |
|
|
|
#include <string> |
|
|
|
#include <string> |
|
|
@ -25,6 +28,7 @@ |
|
|
|
#include "rocksdb/slice_transform.h" |
|
|
|
#include "rocksdb/slice_transform.h" |
|
|
|
#include "rocksdb/memtablerep.h" |
|
|
|
#include "rocksdb/memtablerep.h" |
|
|
|
#include "table/block.h" |
|
|
|
#include "table/block.h" |
|
|
|
|
|
|
|
#include "table/meta_blocks.h" |
|
|
|
#include "table/block_based_table_builder.h" |
|
|
|
#include "table/block_based_table_builder.h" |
|
|
|
#include "table/block_based_table_factory.h" |
|
|
|
#include "table/block_based_table_factory.h" |
|
|
|
#include "table/block_based_table_reader.h" |
|
|
|
#include "table/block_based_table_reader.h" |
|
|
@ -946,10 +950,7 @@ TEST(BlockBasedTableTest, BasicBlockBasedTableProperties) { |
|
|
|
block_builder.Add(item.first, item.second); |
|
|
|
block_builder.Add(item.first, item.second); |
|
|
|
} |
|
|
|
} |
|
|
|
Slice content = block_builder.Finish(); |
|
|
|
Slice content = block_builder.Finish(); |
|
|
|
ASSERT_EQ( |
|
|
|
ASSERT_EQ(content.size() + kBlockTrailerSize, props.data_size); |
|
|
|
content.size() + kBlockTrailerSize, |
|
|
|
|
|
|
|
props.data_size |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(BlockBasedTableTest, FilterPolicyNameProperties) { |
|
|
|
TEST(BlockBasedTableTest, FilterPolicyNameProperties) { |
|
|
@ -958,9 +959,7 @@ TEST(BlockBasedTableTest, FilterPolicyNameProperties) { |
|
|
|
std::vector<std::string> keys; |
|
|
|
std::vector<std::string> keys; |
|
|
|
KVMap kvmap; |
|
|
|
KVMap kvmap; |
|
|
|
Options options; |
|
|
|
Options options; |
|
|
|
std::unique_ptr<const FilterPolicy> filter_policy( |
|
|
|
std::unique_ptr<const FilterPolicy> filter_policy(NewBloomFilterPolicy(10)); |
|
|
|
NewBloomFilterPolicy(10) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
options.filter_policy = filter_policy.get(); |
|
|
|
options.filter_policy = filter_policy.get(); |
|
|
|
|
|
|
|
|
|
|
|
c.Finish(options, GetPlainInternalComparator(options.comparator), &keys, |
|
|
|
c.Finish(options, GetPlainInternalComparator(options.comparator), &keys, |
|
|
@ -1032,10 +1031,8 @@ TEST(BlockBasedTableTest, NumBlockStat) { |
|
|
|
KVMap kvmap; |
|
|
|
KVMap kvmap; |
|
|
|
c.Finish(options, GetPlainInternalComparator(options.comparator), &ks, |
|
|
|
c.Finish(options, GetPlainInternalComparator(options.comparator), &ks, |
|
|
|
&kvmap); |
|
|
|
&kvmap); |
|
|
|
ASSERT_EQ( |
|
|
|
ASSERT_EQ(kvmap.size(), |
|
|
|
kvmap.size(), |
|
|
|
c.table_reader()->GetTableProperties().num_data_blocks); |
|
|
|
c.table_reader()->GetTableProperties().num_data_blocks |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class BlockCacheProperties { |
|
|
|
class BlockCacheProperties { |
|
|
@ -1050,32 +1047,26 @@ class BlockCacheProperties { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if the fetched props matches the expected ones.
|
|
|
|
// Check if the fetched props matches the expected ones.
|
|
|
|
void AssertEqual( |
|
|
|
void AssertEqual(int64_t index_block_cache_miss, |
|
|
|
long index_block_cache_miss, |
|
|
|
int64_t index_block_cache_hit, int64_t data_block_cache_miss, |
|
|
|
long index_block_cache_hit, |
|
|
|
int64_t data_block_cache_hit) const { |
|
|
|
long data_block_cache_miss, |
|
|
|
|
|
|
|
long data_block_cache_hit) const { |
|
|
|
|
|
|
|
ASSERT_EQ(index_block_cache_miss, this->index_block_cache_miss); |
|
|
|
ASSERT_EQ(index_block_cache_miss, this->index_block_cache_miss); |
|
|
|
ASSERT_EQ(index_block_cache_hit, this->index_block_cache_hit); |
|
|
|
ASSERT_EQ(index_block_cache_hit, this->index_block_cache_hit); |
|
|
|
ASSERT_EQ(data_block_cache_miss, this->data_block_cache_miss); |
|
|
|
ASSERT_EQ(data_block_cache_miss, this->data_block_cache_miss); |
|
|
|
ASSERT_EQ(data_block_cache_hit, this->data_block_cache_hit); |
|
|
|
ASSERT_EQ(data_block_cache_hit, this->data_block_cache_hit); |
|
|
|
ASSERT_EQ( |
|
|
|
ASSERT_EQ(index_block_cache_miss + data_block_cache_miss, |
|
|
|
index_block_cache_miss + data_block_cache_miss, |
|
|
|
this->block_cache_miss); |
|
|
|
this->block_cache_miss |
|
|
|
ASSERT_EQ(index_block_cache_hit + data_block_cache_hit, |
|
|
|
); |
|
|
|
this->block_cache_hit); |
|
|
|
ASSERT_EQ( |
|
|
|
|
|
|
|
index_block_cache_hit + data_block_cache_hit, |
|
|
|
|
|
|
|
this->block_cache_hit |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
long block_cache_miss = 0; |
|
|
|
int64_t block_cache_miss = 0; |
|
|
|
long block_cache_hit = 0; |
|
|
|
int64_t block_cache_hit = 0; |
|
|
|
long index_block_cache_miss = 0; |
|
|
|
int64_t index_block_cache_miss = 0; |
|
|
|
long index_block_cache_hit = 0; |
|
|
|
int64_t index_block_cache_hit = 0; |
|
|
|
long data_block_cache_miss = 0; |
|
|
|
int64_t data_block_cache_miss = 0; |
|
|
|
long data_block_cache_hit = 0; |
|
|
|
int64_t data_block_cache_hit = 0; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
TEST(BlockBasedTableTest, BlockCacheTest) { |
|
|
|
TEST(BlockBasedTableTest, BlockCacheTest) { |
|
|
@ -1105,12 +1096,8 @@ TEST(BlockBasedTableTest, BlockCacheTest) { |
|
|
|
{ |
|
|
|
{ |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
// index will be added to block cache.
|
|
|
|
// index will be added to block cache.
|
|
|
|
props.AssertEqual( |
|
|
|
props.AssertEqual(1, // index block miss
|
|
|
|
1, // index block miss
|
|
|
|
0, 0, 0); |
|
|
|
0, |
|
|
|
|
|
|
|
0, |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Only index block will be accessed
|
|
|
|
// Only index block will be accessed
|
|
|
@ -1120,24 +1107,16 @@ TEST(BlockBasedTableTest, BlockCacheTest) { |
|
|
|
// NOTE: to help better highlight the "detla" of each ticker, I use
|
|
|
|
// NOTE: to help better highlight the "detla" of each ticker, I use
|
|
|
|
// <last_value> + <added_value> to indicate the increment of changed
|
|
|
|
// <last_value> + <added_value> to indicate the increment of changed
|
|
|
|
// value; other numbers remain the same.
|
|
|
|
// value; other numbers remain the same.
|
|
|
|
props.AssertEqual( |
|
|
|
props.AssertEqual(1, 0 + 1, // index block hit
|
|
|
|
1, |
|
|
|
0, 0); |
|
|
|
0 + 1, // index block hit
|
|
|
|
|
|
|
|
0, |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Only data block will be accessed
|
|
|
|
// Only data block will be accessed
|
|
|
|
{ |
|
|
|
{ |
|
|
|
iter->SeekToFirst(); |
|
|
|
iter->SeekToFirst(); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
props.AssertEqual( |
|
|
|
props.AssertEqual(1, 1, 0 + 1, // data block miss
|
|
|
|
1, |
|
|
|
0); |
|
|
|
1, |
|
|
|
|
|
|
|
0 + 1, // data block miss
|
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Data block will be in cache
|
|
|
|
// Data block will be in cache
|
|
|
@ -1145,12 +1124,8 @@ TEST(BlockBasedTableTest, BlockCacheTest) { |
|
|
|
iter.reset(c.NewIterator()); |
|
|
|
iter.reset(c.NewIterator()); |
|
|
|
iter->SeekToFirst(); |
|
|
|
iter->SeekToFirst(); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
props.AssertEqual( |
|
|
|
props.AssertEqual(1, 1 + 1, /* index block hit */ |
|
|
|
1, |
|
|
|
1, 0 + 1 /* data block hit */); |
|
|
|
1 + 1, // index block hit
|
|
|
|
|
|
|
|
1, |
|
|
|
|
|
|
|
0 + 1 // data block hit
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// release the iterator so that the block cache can reset correctly.
|
|
|
|
// release the iterator so that the block cache can reset correctly.
|
|
|
|
iter.reset(); |
|
|
|
iter.reset(); |
|
|
@ -1176,12 +1151,8 @@ TEST(BlockBasedTableTest, BlockCacheTest) { |
|
|
|
c.Reopen(options); |
|
|
|
c.Reopen(options); |
|
|
|
{ |
|
|
|
{ |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
props.AssertEqual( |
|
|
|
props.AssertEqual(1, // index block miss
|
|
|
|
1, // index block miss
|
|
|
|
0, 0, 0); |
|
|
|
0, |
|
|
|
|
|
|
|
0, |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1191,12 +1162,9 @@ TEST(BlockBasedTableTest, BlockCacheTest) { |
|
|
|
// is only 1, index block will be purged after data block is inserted.
|
|
|
|
// is only 1, index block will be purged after data block is inserted.
|
|
|
|
iter.reset(c.NewIterator()); |
|
|
|
iter.reset(c.NewIterator()); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
props.AssertEqual( |
|
|
|
props.AssertEqual(1 + 1, // index block miss
|
|
|
|
1 + 1, // index block miss
|
|
|
|
0, 0, // data block miss
|
|
|
|
0, |
|
|
|
0); |
|
|
|
0, // data block miss
|
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
@ -1204,12 +1172,8 @@ TEST(BlockBasedTableTest, BlockCacheTest) { |
|
|
|
// block's cache miss.
|
|
|
|
// block's cache miss.
|
|
|
|
iter->SeekToFirst(); |
|
|
|
iter->SeekToFirst(); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
BlockCacheProperties props(options.statistics.get()); |
|
|
|
props.AssertEqual( |
|
|
|
props.AssertEqual(2, 0, 0 + 1, // data block miss
|
|
|
|
2, |
|
|
|
0); |
|
|
|
0, |
|
|
|
|
|
|
|
0 + 1, // data block miss
|
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1316,7 +1280,6 @@ TEST(GeneralTableTest, ApproximateOffsetOfPlain) { |
|
|
|
ASSERT_TRUE(Between(c.ApproximateOffsetOf("k06"), 510000, 511000)); |
|
|
|
ASSERT_TRUE(Between(c.ApproximateOffsetOf("k06"), 510000, 511000)); |
|
|
|
ASSERT_TRUE(Between(c.ApproximateOffsetOf("k07"), 510000, 511000)); |
|
|
|
ASSERT_TRUE(Between(c.ApproximateOffsetOf("k07"), 510000, 511000)); |
|
|
|
ASSERT_TRUE(Between(c.ApproximateOffsetOf("xyz"), 610000, 612000)); |
|
|
|
ASSERT_TRUE(Between(c.ApproximateOffsetOf("xyz"), 610000, 612000)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void DoCompressionTest(CompressionType comp) { |
|
|
|
static void DoCompressionTest(CompressionType comp) { |
|
|
@ -1360,11 +1323,9 @@ TEST(GeneralTableTest, ApproximateOffsetOfCompressed) { |
|
|
|
valid++; |
|
|
|
valid++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(int i =0; i < valid; i++) |
|
|
|
for (int i = 0; i < valid; i++) { |
|
|
|
{ |
|
|
|
|
|
|
|
DoCompressionTest(compression_state[i]); |
|
|
|
DoCompressionTest(compression_state[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(Harness, Randomized) { |
|
|
|
TEST(Harness, Randomized) { |
|
|
@ -1375,8 +1336,8 @@ TEST(Harness, Randomized) { |
|
|
|
for (int num_entries = 0; num_entries < 2000; |
|
|
|
for (int num_entries = 0; num_entries < 2000; |
|
|
|
num_entries += (num_entries < 50 ? 1 : 200)) { |
|
|
|
num_entries += (num_entries < 50 ? 1 : 200)) { |
|
|
|
if ((num_entries % 10) == 0) { |
|
|
|
if ((num_entries % 10) == 0) { |
|
|
|
fprintf(stderr, "case %d of %d: num_entries = %d\n", |
|
|
|
fprintf(stderr, "case %d of %d: num_entries = %d\n", (i + 1), |
|
|
|
(i + 1), int(args.size()), num_entries); |
|
|
|
static_cast<int>(args.size()), num_entries); |
|
|
|
} |
|
|
|
} |
|
|
|
for (int e = 0; e < num_entries; e++) { |
|
|
|
for (int e = 0; e < num_entries; e++) { |
|
|
|
std::string v; |
|
|
|
std::string v; |
|
|
|