@nxtedition/rocksdb 8.1.17 → 8.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.cc +32 -2
- package/binding.gyp +8 -0
- package/deps/liburing/liburing.gyp +20 -0
- package/deps/rocksdb/rocksdb/CMakeLists.txt +4 -0
- package/deps/rocksdb/rocksdb/TARGETS +7 -0
- package/deps/rocksdb/rocksdb/cache/cache.cc +43 -0
- package/deps/rocksdb/rocksdb/cache/cache_bench_tool.cc +8 -5
- package/deps/rocksdb/rocksdb/cache/cache_entry_stats.h +1 -1
- package/deps/rocksdb/rocksdb/cache/cache_reservation_manager.cc +1 -1
- package/deps/rocksdb/rocksdb/cache/cache_test.cc +12 -48
- package/deps/rocksdb/rocksdb/cache/charged_cache.cc +26 -18
- package/deps/rocksdb/rocksdb/cache/charged_cache.h +5 -62
- package/deps/rocksdb/rocksdb/cache/clock_cache.cc +119 -44
- package/deps/rocksdb/rocksdb/cache/clock_cache.h +34 -29
- package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.cc +3 -3
- package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.h +2 -2
- package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache_test.cc +148 -209
- package/deps/rocksdb/rocksdb/cache/lru_cache.cc +118 -284
- package/deps/rocksdb/rocksdb/cache/lru_cache.h +23 -71
- package/deps/rocksdb/rocksdb/cache/lru_cache_test.cc +351 -392
- package/deps/rocksdb/rocksdb/cache/secondary_cache.cc +5 -2
- package/deps/rocksdb/rocksdb/cache/secondary_cache_adapter.cc +296 -0
- package/deps/rocksdb/rocksdb/cache/secondary_cache_adapter.h +52 -0
- package/deps/rocksdb/rocksdb/cache/sharded_cache.h +22 -19
- package/deps/rocksdb/rocksdb/cache/typed_cache.h +56 -20
- package/deps/rocksdb/rocksdb/db/arena_wrapped_db_iter.cc +3 -0
- package/deps/rocksdb/rocksdb/db/blob/blob_counting_iterator.h +4 -0
- package/deps/rocksdb/rocksdb/db/blob/blob_source.cc +3 -3
- package/deps/rocksdb/rocksdb/db/blob/blob_source_test.cc +19 -25
- package/deps/rocksdb/rocksdb/db/blob/db_blob_basic_test.cc +216 -0
- package/deps/rocksdb/rocksdb/db/c.cc +90 -1
- package/deps/rocksdb/rocksdb/db/column_family.cc +8 -7
- package/deps/rocksdb/rocksdb/db/column_family.h +0 -6
- package/deps/rocksdb/rocksdb/db/compaction/clipping_iterator.h +5 -0
- package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +24 -7
- package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.h +17 -1
- package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +18 -12
- package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +3 -1
- package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.cc +245 -302
- package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.h +13 -2
- package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.h +5 -0
- package/deps/rocksdb/rocksdb/db/db_basic_test.cc +75 -15
- package/deps/rocksdb/rocksdb/db/db_block_cache_test.cc +2 -3
- package/deps/rocksdb/rocksdb/db/db_filesnapshot.cc +1 -5
- package/deps/rocksdb/rocksdb/db/db_flush_test.cc +91 -1
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +5 -12
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +16 -4
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +47 -24
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_debug.cc +4 -2
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +1 -1
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_write.cc +32 -3
- package/deps/rocksdb/rocksdb/db/db_iter.cc +28 -29
- package/deps/rocksdb/rocksdb/db/db_iter.h +0 -3
- package/deps/rocksdb/rocksdb/db/db_properties_test.cc +176 -0
- package/deps/rocksdb/rocksdb/db/db_range_del_test.cc +391 -2
- package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +26 -0
- package/deps/rocksdb/rocksdb/db/db_write_test.cc +13 -5
- package/deps/rocksdb/rocksdb/db/dbformat.h +3 -1
- package/deps/rocksdb/rocksdb/db/error_handler_fs_test.cc +0 -1
- package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +0 -6
- package/deps/rocksdb/rocksdb/db/forward_iterator.cc +3 -0
- package/deps/rocksdb/rocksdb/db/forward_iterator.h +1 -1
- package/deps/rocksdb/rocksdb/db/history_trimming_iterator.h +4 -0
- package/deps/rocksdb/rocksdb/db/import_column_family_job.cc +68 -40
- package/deps/rocksdb/rocksdb/db/import_column_family_job.h +3 -3
- package/deps/rocksdb/rocksdb/db/import_column_family_test.cc +115 -0
- package/deps/rocksdb/rocksdb/db/internal_stats.cc +169 -72
- package/deps/rocksdb/rocksdb/db/internal_stats.h +36 -7
- package/deps/rocksdb/rocksdb/db/memtable.cc +6 -4
- package/deps/rocksdb/rocksdb/db/merge_helper.cc +4 -0
- package/deps/rocksdb/rocksdb/db/perf_context_test.cc +151 -0
- package/deps/rocksdb/rocksdb/db/range_del_aggregator.cc +47 -16
- package/deps/rocksdb/rocksdb/db/range_del_aggregator.h +10 -8
- package/deps/rocksdb/rocksdb/db/range_del_aggregator_test.cc +91 -93
- package/deps/rocksdb/rocksdb/db/range_tombstone_fragmenter.h +1 -2
- package/deps/rocksdb/rocksdb/db/version_edit_handler.cc +1 -1
- package/deps/rocksdb/rocksdb/db/version_set.cc +30 -14
- package/deps/rocksdb/rocksdb/db/version_set.h +1 -0
- package/deps/rocksdb/rocksdb/db/write_stall_stats.cc +179 -0
- package/deps/rocksdb/rocksdb/db/write_stall_stats.h +47 -0
- package/deps/rocksdb/rocksdb/db_stress_tool/batched_ops_stress.cc +109 -7
- package/deps/rocksdb/rocksdb/db_stress_tool/cf_consistency_stress.cc +147 -12
- package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.cc +31 -0
- package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +22 -0
- package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +4 -1
- package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +42 -59
- package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.h +7 -4
- package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_tool.cc +7 -0
- package/deps/rocksdb/rocksdb/db_stress_tool/expected_state.cc +6 -10
- package/deps/rocksdb/rocksdb/db_stress_tool/multi_ops_txns_stress.cc +6 -0
- package/deps/rocksdb/rocksdb/db_stress_tool/multi_ops_txns_stress.h +4 -0
- package/deps/rocksdb/rocksdb/db_stress_tool/no_batched_ops_stress.cc +127 -36
- package/deps/rocksdb/rocksdb/env/fs_posix.cc +8 -0
- package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +35 -0
- package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +29 -8
- package/deps/rocksdb/rocksdb/file/file_util.cc +14 -10
- package/deps/rocksdb/rocksdb/file/prefetch_test.cc +183 -63
- package/deps/rocksdb/rocksdb/include/rocksdb/advanced_cache.h +159 -66
- package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +3 -1
- package/deps/rocksdb/rocksdb/include/rocksdb/c.h +52 -5
- package/deps/rocksdb/rocksdb/include/rocksdb/cache.h +3 -3
- package/deps/rocksdb/rocksdb/include/rocksdb/compaction_filter.h +134 -73
- package/deps/rocksdb/rocksdb/include/rocksdb/db.h +46 -3
- package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +6 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/listener.h +0 -6
- package/deps/rocksdb/rocksdb/include/rocksdb/metadata.h +7 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/options.h +2 -2
- package/deps/rocksdb/rocksdb/include/rocksdb/perf_context.h +6 -1
- package/deps/rocksdb/rocksdb/include/rocksdb/secondary_cache.h +3 -3
- package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +18 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/types.h +28 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/version.h +2 -2
- package/deps/rocksdb/rocksdb/include/rocksdb/wide_columns.h +39 -0
- package/deps/rocksdb/rocksdb/monitoring/perf_context.cc +5 -0
- package/deps/rocksdb/rocksdb/monitoring/statistics.cc +9 -1
- package/deps/rocksdb/rocksdb/options/customizable_test.cc +2 -2
- package/deps/rocksdb/rocksdb/port/stack_trace.cc +17 -7
- package/deps/rocksdb/rocksdb/port/win/env_win.h +1 -0
- package/deps/rocksdb/rocksdb/src.mk +4 -0
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +38 -34
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +11 -12
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_impl.h +5 -5
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +126 -132
- package/deps/rocksdb/rocksdb/table/block_based/block_cache.cc +16 -16
- package/deps/rocksdb/rocksdb/table/block_based/cachable_entry.h +0 -16
- package/deps/rocksdb/rocksdb/table/block_based/filter_block_reader_common.cc +1 -1
- package/deps/rocksdb/rocksdb/table/block_based/index_reader_common.cc +1 -1
- package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +3 -4
- package/deps/rocksdb/rocksdb/table/block_based/partitioned_index_reader.cc +1 -1
- package/deps/rocksdb/rocksdb/table/block_based/uncompression_dict_reader.cc +1 -1
- package/deps/rocksdb/rocksdb/table/compaction_merging_iterator.cc +370 -0
- package/deps/rocksdb/rocksdb/table/compaction_merging_iterator.h +44 -0
- package/deps/rocksdb/rocksdb/table/get_context.cc +4 -2
- package/deps/rocksdb/rocksdb/table/merging_iterator.cc +555 -267
- package/deps/rocksdb/rocksdb/table/merging_iterator.h +10 -5
- package/deps/rocksdb/rocksdb/table/table_test.cc +113 -70
- package/deps/rocksdb/rocksdb/test_util/secondary_cache_test_util.cc +96 -0
- package/deps/rocksdb/rocksdb/test_util/secondary_cache_test_util.h +117 -0
- package/deps/rocksdb/rocksdb/utilities/checkpoint/checkpoint_impl.cc +5 -3
- package/deps/rocksdb/rocksdb/utilities/fault_injection_secondary_cache.cc +3 -3
- package/deps/rocksdb/rocksdb/utilities/fault_injection_secondary_cache.h +1 -1
- package/deps/rocksdb/rocksdb/utilities/simulator_cache/sim_cache.cc +9 -2
- package/deps/rocksdb/rocksdb/utilities/ttl/db_ttl_impl.cc +5 -1
- package/deps/rocksdb/rocksdb/utilities/ttl/ttl_test.cc +11 -0
- package/deps/rocksdb/rocksdb.gyp +7 -1
- package/package.json +1 -1
- package/prebuilds/linux-x64/node.napi.node +0 -0
|
@@ -12,98 +12,36 @@
|
|
|
12
12
|
|
|
13
13
|
#include "memory/jemalloc_nodump_allocator.h"
|
|
14
14
|
#include "rocksdb/convenience.h"
|
|
15
|
+
#include "test_util/secondary_cache_test_util.h"
|
|
15
16
|
#include "test_util/testharness.h"
|
|
16
17
|
#include "test_util/testutil.h"
|
|
17
18
|
|
|
18
19
|
namespace ROCKSDB_NAMESPACE {
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
public:
|
|
23
|
-
CompressedSecondaryCacheTest() : fail_create_(false) {}
|
|
24
|
-
~CompressedSecondaryCacheTest() override = default;
|
|
25
|
-
|
|
26
|
-
protected:
|
|
27
|
-
class TestItem {
|
|
28
|
-
public:
|
|
29
|
-
TestItem(const char* buf, size_t size) : buf_(new char[size]), size_(size) {
|
|
30
|
-
memcpy(buf_.get(), buf, size);
|
|
31
|
-
}
|
|
32
|
-
~TestItem() = default;
|
|
21
|
+
using secondary_cache_test_util::GetTestingCacheTypes;
|
|
22
|
+
using secondary_cache_test_util::WithCacheType;
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
// 16 bytes for HCC compatibility
|
|
25
|
+
const std::string key0 = "____ ____key0";
|
|
26
|
+
const std::string key1 = "____ ____key1";
|
|
27
|
+
const std::string key2 = "____ ____key2";
|
|
28
|
+
const std::string key3 = "____ ____key3";
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static size_t SizeCallback(Cache::ObjectPtr obj) {
|
|
43
|
-
return static_cast<TestItem*>(obj)->Size();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static Status SaveToCallback(Cache::ObjectPtr from_obj, size_t from_offset,
|
|
47
|
-
size_t length, char* out) {
|
|
48
|
-
auto item = static_cast<TestItem*>(from_obj);
|
|
49
|
-
const char* buf = item->Buf();
|
|
50
|
-
EXPECT_EQ(length, item->Size());
|
|
51
|
-
EXPECT_EQ(from_offset, 0);
|
|
52
|
-
memcpy(out, buf, length);
|
|
53
|
-
return Status::OK();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static void DeletionCallback(Cache::ObjectPtr obj,
|
|
57
|
-
MemoryAllocator* /*alloc*/) {
|
|
58
|
-
delete static_cast<TestItem*>(obj);
|
|
59
|
-
obj = nullptr;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static Status SaveToCallbackFail(Cache::ObjectPtr /*obj*/, size_t /*offset*/,
|
|
63
|
-
size_t /*size*/, char* /*out*/) {
|
|
64
|
-
return Status::NotSupported();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static Status CreateCallback(const Slice& data, Cache::CreateContext* context,
|
|
68
|
-
MemoryAllocator* /*allocator*/,
|
|
69
|
-
Cache::ObjectPtr* out_obj, size_t* out_charge) {
|
|
70
|
-
auto t = static_cast<CompressedSecondaryCacheTest*>(context);
|
|
71
|
-
if (t->fail_create_) {
|
|
72
|
-
return Status::NotSupported();
|
|
73
|
-
}
|
|
74
|
-
*out_obj = new TestItem(data.data(), data.size());
|
|
75
|
-
*out_charge = data.size();
|
|
76
|
-
return Status::OK();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static constexpr auto GenerateHelpersByRole() {
|
|
80
|
-
std::array<Cache::CacheItemHelper, kNumCacheEntryRoles> a;
|
|
81
|
-
for (uint32_t i = 0; i < kNumCacheEntryRoles; ++i) {
|
|
82
|
-
a[i] = Cache::CacheItemHelper{static_cast<CacheEntryRole>(i),
|
|
83
|
-
&DeletionCallback, &SizeCallback,
|
|
84
|
-
&SaveToCallback, &CreateCallback};
|
|
85
|
-
}
|
|
86
|
-
return a;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
static const std::array<Cache::CacheItemHelper, kNumCacheEntryRoles>
|
|
90
|
-
kHelperByRole;
|
|
91
|
-
|
|
92
|
-
static const Cache::CacheItemHelper& kHelper;
|
|
93
|
-
|
|
94
|
-
static constexpr Cache::CacheItemHelper kHelperFail{
|
|
95
|
-
CacheEntryRole::kDataBlock, &DeletionCallback, &SizeCallback,
|
|
96
|
-
&SaveToCallbackFail, &CreateCallback};
|
|
97
|
-
|
|
98
|
-
void SetFailCreate(bool fail) { fail_create_ = fail; }
|
|
30
|
+
class CompressedSecondaryCacheTestBase : public testing::Test,
|
|
31
|
+
public WithCacheType {
|
|
32
|
+
public:
|
|
33
|
+
CompressedSecondaryCacheTestBase() {}
|
|
34
|
+
~CompressedSecondaryCacheTestBase() override = default;
|
|
99
35
|
|
|
36
|
+
protected:
|
|
100
37
|
void BasicTestHelper(std::shared_ptr<SecondaryCache> sec_cache,
|
|
101
38
|
bool sec_cache_is_compressed) {
|
|
102
39
|
get_perf_context()->Reset();
|
|
103
|
-
bool
|
|
40
|
+
bool kept_in_sec_cache{true};
|
|
104
41
|
// Lookup an non-existent key.
|
|
105
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle0 =
|
|
106
|
-
|
|
42
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle0 =
|
|
43
|
+
sec_cache->Lookup(key0, GetHelper(), this, true, /*advise_erase=*/true,
|
|
44
|
+
kept_in_sec_cache);
|
|
107
45
|
ASSERT_EQ(handle0, nullptr);
|
|
108
46
|
|
|
109
47
|
Random rnd(301);
|
|
@@ -111,23 +49,25 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
111
49
|
std::string str1(rnd.RandomString(1000));
|
|
112
50
|
TestItem item1(str1.data(), str1.length());
|
|
113
51
|
// A dummy handle is inserted if the item is inserted for the first time.
|
|
114
|
-
ASSERT_OK(sec_cache->Insert(
|
|
52
|
+
ASSERT_OK(sec_cache->Insert(key1, &item1, GetHelper()));
|
|
115
53
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 1);
|
|
116
54
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_uncompressed_bytes, 0);
|
|
117
55
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_compressed_bytes, 0);
|
|
118
56
|
|
|
119
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle1_1 =
|
|
120
|
-
|
|
57
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle1_1 =
|
|
58
|
+
sec_cache->Lookup(key1, GetHelper(), this, true, /*advise_erase=*/false,
|
|
59
|
+
kept_in_sec_cache);
|
|
121
60
|
ASSERT_EQ(handle1_1, nullptr);
|
|
122
61
|
|
|
123
62
|
// Insert and Lookup the item k1 for the second time and advise erasing it.
|
|
124
|
-
ASSERT_OK(sec_cache->Insert(
|
|
63
|
+
ASSERT_OK(sec_cache->Insert(key1, &item1, GetHelper()));
|
|
125
64
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 1);
|
|
126
65
|
|
|
127
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle1_2 =
|
|
128
|
-
|
|
66
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle1_2 =
|
|
67
|
+
sec_cache->Lookup(key1, GetHelper(), this, true, /*advise_erase=*/true,
|
|
68
|
+
kept_in_sec_cache);
|
|
129
69
|
ASSERT_NE(handle1_2, nullptr);
|
|
130
|
-
ASSERT_FALSE(
|
|
70
|
+
ASSERT_FALSE(kept_in_sec_cache);
|
|
131
71
|
if (sec_cache_is_compressed) {
|
|
132
72
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_uncompressed_bytes,
|
|
133
73
|
1000);
|
|
@@ -144,20 +84,22 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
144
84
|
ASSERT_EQ(memcmp(val1->Buf(), item1.Buf(), item1.Size()), 0);
|
|
145
85
|
|
|
146
86
|
// Lookup the item k1 again.
|
|
147
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle1_3 =
|
|
148
|
-
|
|
87
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle1_3 =
|
|
88
|
+
sec_cache->Lookup(key1, GetHelper(), this, true, /*advise_erase=*/true,
|
|
89
|
+
kept_in_sec_cache);
|
|
149
90
|
ASSERT_EQ(handle1_3, nullptr);
|
|
150
91
|
|
|
151
92
|
// Insert and Lookup the item k2.
|
|
152
93
|
std::string str2(rnd.RandomString(1000));
|
|
153
94
|
TestItem item2(str2.data(), str2.length());
|
|
154
|
-
ASSERT_OK(sec_cache->Insert(
|
|
95
|
+
ASSERT_OK(sec_cache->Insert(key2, &item2, GetHelper()));
|
|
155
96
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 2);
|
|
156
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle2_1 =
|
|
157
|
-
|
|
97
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle2_1 =
|
|
98
|
+
sec_cache->Lookup(key2, GetHelper(), this, true, /*advise_erase=*/false,
|
|
99
|
+
kept_in_sec_cache);
|
|
158
100
|
ASSERT_EQ(handle2_1, nullptr);
|
|
159
101
|
|
|
160
|
-
ASSERT_OK(sec_cache->Insert(
|
|
102
|
+
ASSERT_OK(sec_cache->Insert(key2, &item2, GetHelper()));
|
|
161
103
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 2);
|
|
162
104
|
if (sec_cache_is_compressed) {
|
|
163
105
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_uncompressed_bytes,
|
|
@@ -168,8 +110,9 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
168
110
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_uncompressed_bytes, 0);
|
|
169
111
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_compressed_bytes, 0);
|
|
170
112
|
}
|
|
171
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle2_2 =
|
|
172
|
-
|
|
113
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle2_2 =
|
|
114
|
+
sec_cache->Lookup(key2, GetHelper(), this, true, /*advise_erase=*/false,
|
|
115
|
+
kept_in_sec_cache);
|
|
173
116
|
ASSERT_NE(handle2_2, nullptr);
|
|
174
117
|
std::unique_ptr<TestItem> val2 =
|
|
175
118
|
std::unique_ptr<TestItem>(static_cast<TestItem*>(handle2_2->Value()));
|
|
@@ -238,24 +181,26 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
238
181
|
std::string str1(rnd.RandomString(1000));
|
|
239
182
|
TestItem item1(str1.data(), str1.length());
|
|
240
183
|
// Insert a dummy handle.
|
|
241
|
-
ASSERT_OK(sec_cache->Insert(
|
|
184
|
+
ASSERT_OK(sec_cache->Insert(key1, &item1, GetHelper()));
|
|
242
185
|
// Insert k1.
|
|
243
|
-
ASSERT_OK(sec_cache->Insert(
|
|
186
|
+
ASSERT_OK(sec_cache->Insert(key1, &item1, GetHelper()));
|
|
244
187
|
|
|
245
188
|
// Insert and Lookup the second item.
|
|
246
189
|
std::string str2(rnd.RandomString(200));
|
|
247
190
|
TestItem item2(str2.data(), str2.length());
|
|
248
191
|
// Insert a dummy handle, k1 is not evicted.
|
|
249
|
-
ASSERT_OK(sec_cache->Insert(
|
|
250
|
-
bool
|
|
251
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle1 =
|
|
252
|
-
|
|
192
|
+
ASSERT_OK(sec_cache->Insert(key2, &item2, GetHelper()));
|
|
193
|
+
bool kept_in_sec_cache{false};
|
|
194
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle1 =
|
|
195
|
+
sec_cache->Lookup(key1, GetHelper(), this, true, /*advise_erase=*/false,
|
|
196
|
+
kept_in_sec_cache);
|
|
253
197
|
ASSERT_EQ(handle1, nullptr);
|
|
254
198
|
|
|
255
199
|
// Insert k2 and k1 is evicted.
|
|
256
|
-
ASSERT_OK(sec_cache->Insert(
|
|
257
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle2 =
|
|
258
|
-
|
|
200
|
+
ASSERT_OK(sec_cache->Insert(key2, &item2, GetHelper()));
|
|
201
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle2 =
|
|
202
|
+
sec_cache->Lookup(key2, GetHelper(), this, true, /*advise_erase=*/false,
|
|
203
|
+
kept_in_sec_cache);
|
|
259
204
|
ASSERT_NE(handle2, nullptr);
|
|
260
205
|
std::unique_ptr<TestItem> val2 =
|
|
261
206
|
std::unique_ptr<TestItem>(static_cast<TestItem*>(handle2->Value()));
|
|
@@ -263,24 +208,26 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
263
208
|
ASSERT_EQ(memcmp(val2->Buf(), item2.Buf(), item2.Size()), 0);
|
|
264
209
|
|
|
265
210
|
// Insert k1 again and a dummy handle is inserted.
|
|
266
|
-
ASSERT_OK(sec_cache->Insert(
|
|
211
|
+
ASSERT_OK(sec_cache->Insert(key1, &item1, GetHelper()));
|
|
267
212
|
|
|
268
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle1_1 =
|
|
269
|
-
|
|
213
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle1_1 =
|
|
214
|
+
sec_cache->Lookup(key1, GetHelper(), this, true, /*advise_erase=*/false,
|
|
215
|
+
kept_in_sec_cache);
|
|
270
216
|
ASSERT_EQ(handle1_1, nullptr);
|
|
271
217
|
|
|
272
218
|
// Create Fails.
|
|
273
219
|
SetFailCreate(true);
|
|
274
|
-
std::unique_ptr<SecondaryCacheResultHandle> handle2_1 =
|
|
275
|
-
|
|
220
|
+
std::unique_ptr<SecondaryCacheResultHandle> handle2_1 =
|
|
221
|
+
sec_cache->Lookup(key2, GetHelper(), this, true, /*advise_erase=*/true,
|
|
222
|
+
kept_in_sec_cache);
|
|
276
223
|
ASSERT_EQ(handle2_1, nullptr);
|
|
277
224
|
|
|
278
225
|
// Save Fails.
|
|
279
226
|
std::string str3 = rnd.RandomString(10);
|
|
280
227
|
TestItem item3(str3.data(), str3.length());
|
|
281
228
|
// The Status is OK because a dummy handle is inserted.
|
|
282
|
-
ASSERT_OK(sec_cache->Insert(
|
|
283
|
-
ASSERT_NOK(sec_cache->Insert(
|
|
229
|
+
ASSERT_OK(sec_cache->Insert(key3, &item3, GetHelperFail()));
|
|
230
|
+
ASSERT_NOK(sec_cache->Insert(key3, &item3, GetHelperFail()));
|
|
284
231
|
|
|
285
232
|
sec_cache.reset();
|
|
286
233
|
}
|
|
@@ -304,26 +251,22 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
304
251
|
secondary_cache_opts.enable_custom_split_merge = enable_custom_split_merge;
|
|
305
252
|
std::shared_ptr<SecondaryCache> secondary_cache =
|
|
306
253
|
NewCompressedSecondaryCache(secondary_cache_opts);
|
|
307
|
-
|
|
254
|
+
std::shared_ptr<Cache> cache = NewCache(
|
|
308
255
|
/*_capacity =*/1300, /*_num_shard_bits =*/0,
|
|
309
|
-
/*_strict_capacity_limit =*/
|
|
310
|
-
/*_memory_allocator =*/nullptr, kDefaultToAdaptiveMutex,
|
|
311
|
-
kDefaultCacheMetadataChargePolicy, /*_low_pri_pool_ratio =*/0.0);
|
|
312
|
-
lru_cache_opts.secondary_cache = secondary_cache;
|
|
313
|
-
std::shared_ptr<Cache> cache = NewLRUCache(lru_cache_opts);
|
|
256
|
+
/*_strict_capacity_limit =*/true, secondary_cache);
|
|
314
257
|
std::shared_ptr<Statistics> stats = CreateDBStatistics();
|
|
315
258
|
|
|
316
259
|
get_perf_context()->Reset();
|
|
317
260
|
Random rnd(301);
|
|
318
261
|
std::string str1 = rnd.RandomString(1001);
|
|
319
262
|
auto item1_1 = new TestItem(str1.data(), str1.length());
|
|
320
|
-
ASSERT_OK(cache->Insert(
|
|
263
|
+
ASSERT_OK(cache->Insert(key1, item1_1, GetHelper(), str1.length()));
|
|
321
264
|
|
|
322
265
|
std::string str2 = rnd.RandomString(1012);
|
|
323
266
|
auto item2_1 = new TestItem(str2.data(), str2.length());
|
|
324
267
|
// After this Insert, primary cache contains k2 and secondary cache contains
|
|
325
268
|
// k1's dummy item.
|
|
326
|
-
ASSERT_OK(cache->Insert(
|
|
269
|
+
ASSERT_OK(cache->Insert(key2, item2_1, GetHelper(), str2.length()));
|
|
327
270
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 1);
|
|
328
271
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_uncompressed_bytes, 0);
|
|
329
272
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_compressed_bytes, 0);
|
|
@@ -332,19 +275,19 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
332
275
|
auto item3_1 = new TestItem(str3.data(), str3.length());
|
|
333
276
|
// After this Insert, primary cache contains k3 and secondary cache contains
|
|
334
277
|
// k1's dummy item and k2's dummy item.
|
|
335
|
-
ASSERT_OK(cache->Insert(
|
|
278
|
+
ASSERT_OK(cache->Insert(key3, item3_1, GetHelper(), str3.length()));
|
|
336
279
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 2);
|
|
337
280
|
|
|
338
281
|
// After this Insert, primary cache contains k1 and secondary cache contains
|
|
339
282
|
// k1's dummy item, k2's dummy item, and k3's dummy item.
|
|
340
283
|
auto item1_2 = new TestItem(str1.data(), str1.length());
|
|
341
|
-
ASSERT_OK(cache->Insert(
|
|
284
|
+
ASSERT_OK(cache->Insert(key1, item1_2, GetHelper(), str1.length()));
|
|
342
285
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 3);
|
|
343
286
|
|
|
344
287
|
// After this Insert, primary cache contains k2 and secondary cache contains
|
|
345
288
|
// k1's item, k2's dummy item, and k3's dummy item.
|
|
346
289
|
auto item2_2 = new TestItem(str2.data(), str2.length());
|
|
347
|
-
ASSERT_OK(cache->Insert(
|
|
290
|
+
ASSERT_OK(cache->Insert(key2, item2_2, GetHelper(), str2.length()));
|
|
348
291
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 1);
|
|
349
292
|
if (sec_cache_is_compressed) {
|
|
350
293
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_uncompressed_bytes,
|
|
@@ -359,7 +302,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
359
302
|
// After this Insert, primary cache contains k3 and secondary cache contains
|
|
360
303
|
// k1's item and k2's item.
|
|
361
304
|
auto item3_2 = new TestItem(str3.data(), str3.length());
|
|
362
|
-
ASSERT_OK(cache->Insert(
|
|
305
|
+
ASSERT_OK(cache->Insert(key3, item3_2, GetHelper(), str3.length()));
|
|
363
306
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 2);
|
|
364
307
|
if (sec_cache_is_compressed) {
|
|
365
308
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_uncompressed_bytes,
|
|
@@ -372,7 +315,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
372
315
|
}
|
|
373
316
|
|
|
374
317
|
Cache::Handle* handle;
|
|
375
|
-
handle = cache->Lookup(
|
|
318
|
+
handle = cache->Lookup(key3, GetHelper(), this, Cache::Priority::LOW,
|
|
376
319
|
stats.get());
|
|
377
320
|
ASSERT_NE(handle, nullptr);
|
|
378
321
|
auto val3 = static_cast<TestItem*>(cache->Value(handle));
|
|
@@ -381,13 +324,13 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
381
324
|
cache->Release(handle);
|
|
382
325
|
|
|
383
326
|
// Lookup an non-existent key.
|
|
384
|
-
handle = cache->Lookup(
|
|
327
|
+
handle = cache->Lookup(key0, GetHelper(), this, Cache::Priority::LOW,
|
|
385
328
|
stats.get());
|
|
386
329
|
ASSERT_EQ(handle, nullptr);
|
|
387
330
|
|
|
388
331
|
// This Lookup should just insert a dummy handle in the primary cache
|
|
389
332
|
// and the k1 is still in the secondary cache.
|
|
390
|
-
handle = cache->Lookup(
|
|
333
|
+
handle = cache->Lookup(key1, GetHelper(), this, Cache::Priority::LOW,
|
|
391
334
|
stats.get());
|
|
392
335
|
ASSERT_NE(handle, nullptr);
|
|
393
336
|
ASSERT_EQ(get_perf_context()->block_cache_standalone_handle_count, 1);
|
|
@@ -399,7 +342,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
399
342
|
// This Lookup should erase k1 from the secondary cache and insert
|
|
400
343
|
// it into primary cache; then k3 is demoted.
|
|
401
344
|
// k2 and k3 are in secondary cache.
|
|
402
|
-
handle = cache->Lookup(
|
|
345
|
+
handle = cache->Lookup(key1, GetHelper(), this, Cache::Priority::LOW,
|
|
403
346
|
stats.get());
|
|
404
347
|
ASSERT_NE(handle, nullptr);
|
|
405
348
|
ASSERT_EQ(get_perf_context()->block_cache_standalone_handle_count, 1);
|
|
@@ -407,7 +350,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
407
350
|
cache->Release(handle);
|
|
408
351
|
|
|
409
352
|
// k2 is still in secondary cache.
|
|
410
|
-
handle = cache->Lookup(
|
|
353
|
+
handle = cache->Lookup(key2, GetHelper(), this, Cache::Priority::LOW,
|
|
411
354
|
stats.get());
|
|
412
355
|
ASSERT_NE(handle, nullptr);
|
|
413
356
|
ASSERT_EQ(get_perf_context()->block_cache_standalone_handle_count, 2);
|
|
@@ -415,7 +358,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
415
358
|
|
|
416
359
|
// Testing SetCapacity().
|
|
417
360
|
ASSERT_OK(secondary_cache->SetCapacity(0));
|
|
418
|
-
handle = cache->Lookup(
|
|
361
|
+
handle = cache->Lookup(key3, GetHelper(), this, Cache::Priority::LOW,
|
|
419
362
|
stats.get());
|
|
420
363
|
ASSERT_EQ(handle, nullptr);
|
|
421
364
|
|
|
@@ -425,30 +368,30 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
425
368
|
ASSERT_EQ(capacity, 7000);
|
|
426
369
|
auto item1_3 = new TestItem(str1.data(), str1.length());
|
|
427
370
|
// After this Insert, primary cache contains k1.
|
|
428
|
-
ASSERT_OK(cache->Insert(
|
|
371
|
+
ASSERT_OK(cache->Insert(key1, item1_3, GetHelper(), str2.length()));
|
|
429
372
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 3);
|
|
430
373
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 4);
|
|
431
374
|
|
|
432
375
|
auto item2_3 = new TestItem(str2.data(), str2.length());
|
|
433
376
|
// After this Insert, primary cache contains k2 and secondary cache contains
|
|
434
377
|
// k1's dummy item.
|
|
435
|
-
ASSERT_OK(cache->Insert(
|
|
378
|
+
ASSERT_OK(cache->Insert(key2, item2_3, GetHelper(), str1.length()));
|
|
436
379
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 4);
|
|
437
380
|
|
|
438
381
|
auto item1_4 = new TestItem(str1.data(), str1.length());
|
|
439
382
|
// After this Insert, primary cache contains k1 and secondary cache contains
|
|
440
383
|
// k1's dummy item and k2's dummy item.
|
|
441
|
-
ASSERT_OK(cache->Insert(
|
|
384
|
+
ASSERT_OK(cache->Insert(key1, item1_4, GetHelper(), str2.length()));
|
|
442
385
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 5);
|
|
443
386
|
|
|
444
387
|
auto item2_4 = new TestItem(str2.data(), str2.length());
|
|
445
388
|
// After this Insert, primary cache contains k2 and secondary cache contains
|
|
446
389
|
// k1's real item and k2's dummy item.
|
|
447
|
-
ASSERT_OK(cache->Insert(
|
|
390
|
+
ASSERT_OK(cache->Insert(key2, item2_4, GetHelper(), str2.length()));
|
|
448
391
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 5);
|
|
449
392
|
// This Lookup should just insert a dummy handle in the primary cache
|
|
450
393
|
// and the k1 is still in the secondary cache.
|
|
451
|
-
handle = cache->Lookup(
|
|
394
|
+
handle = cache->Lookup(key1, GetHelper(), this, Cache::Priority::LOW,
|
|
452
395
|
stats.get());
|
|
453
396
|
|
|
454
397
|
ASSERT_NE(handle, nullptr);
|
|
@@ -476,26 +419,31 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
476
419
|
std::shared_ptr<SecondaryCache> secondary_cache =
|
|
477
420
|
NewCompressedSecondaryCache(secondary_cache_opts);
|
|
478
421
|
|
|
479
|
-
|
|
422
|
+
std::shared_ptr<Cache> cache = NewCache(
|
|
480
423
|
/*_capacity=*/1300, /*_num_shard_bits=*/0,
|
|
481
|
-
/*_strict_capacity_limit=*/false,
|
|
482
|
-
/*_memory_allocator=*/nullptr, kDefaultToAdaptiveMutex,
|
|
483
|
-
kDefaultCacheMetadataChargePolicy, /*_low_pri_pool_ratio=*/0.0);
|
|
484
|
-
opts.secondary_cache = secondary_cache;
|
|
485
|
-
std::shared_ptr<Cache> cache = NewLRUCache(opts);
|
|
424
|
+
/*_strict_capacity_limit=*/false, secondary_cache);
|
|
486
425
|
|
|
487
426
|
Random rnd(301);
|
|
488
427
|
std::string str1 = rnd.RandomString(1001);
|
|
489
428
|
auto item1 = std::make_unique<TestItem>(str1.data(), str1.length());
|
|
490
|
-
ASSERT_OK(cache->Insert(
|
|
429
|
+
ASSERT_OK(cache->Insert(key1, item1.get(), GetHelper(), str1.length()));
|
|
491
430
|
item1.release(); // Appease clang-analyze "potential memory leak"
|
|
492
431
|
|
|
493
432
|
Cache::Handle* handle;
|
|
494
|
-
handle = cache->Lookup(
|
|
433
|
+
handle = cache->Lookup(key2, nullptr, this, Cache::Priority::LOW);
|
|
495
434
|
ASSERT_EQ(handle, nullptr);
|
|
496
|
-
handle = cache->Lookup(
|
|
435
|
+
handle = cache->Lookup(key2, GetHelper(), this, Cache::Priority::LOW);
|
|
497
436
|
ASSERT_EQ(handle, nullptr);
|
|
498
437
|
|
|
438
|
+
Cache::AsyncLookupHandle ah;
|
|
439
|
+
ah.key = key2;
|
|
440
|
+
ah.helper = GetHelper();
|
|
441
|
+
ah.create_context = this;
|
|
442
|
+
ah.priority = Cache::Priority::LOW;
|
|
443
|
+
cache->StartAsyncLookup(ah);
|
|
444
|
+
cache->Wait(ah);
|
|
445
|
+
ASSERT_EQ(ah.Result(), nullptr);
|
|
446
|
+
|
|
499
447
|
cache.reset();
|
|
500
448
|
secondary_cache.reset();
|
|
501
449
|
}
|
|
@@ -518,36 +466,29 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
518
466
|
std::shared_ptr<SecondaryCache> secondary_cache =
|
|
519
467
|
NewCompressedSecondaryCache(secondary_cache_opts);
|
|
520
468
|
|
|
521
|
-
|
|
469
|
+
std::shared_ptr<Cache> cache = NewCache(
|
|
522
470
|
/*_capacity=*/1300, /*_num_shard_bits=*/0,
|
|
523
|
-
/*_strict_capacity_limit=*/
|
|
524
|
-
/*_memory_allocator=*/nullptr, kDefaultToAdaptiveMutex,
|
|
525
|
-
kDefaultCacheMetadataChargePolicy, /*_low_pri_pool_ratio=*/0.0);
|
|
526
|
-
opts.secondary_cache = secondary_cache;
|
|
527
|
-
std::shared_ptr<Cache> cache = NewLRUCache(opts);
|
|
471
|
+
/*_strict_capacity_limit=*/true, secondary_cache);
|
|
528
472
|
|
|
529
473
|
Random rnd(301);
|
|
530
474
|
std::string str1 = rnd.RandomString(1001);
|
|
531
475
|
auto item1 = new TestItem(str1.data(), str1.length());
|
|
532
|
-
ASSERT_OK(cache->Insert(
|
|
476
|
+
ASSERT_OK(cache->Insert(key1, item1, GetHelperFail(), str1.length()));
|
|
533
477
|
|
|
534
478
|
std::string str2 = rnd.RandomString(1002);
|
|
535
479
|
auto item2 = new TestItem(str2.data(), str2.length());
|
|
536
480
|
// k1 should be demoted to the secondary cache.
|
|
537
|
-
ASSERT_OK(cache->Insert(
|
|
481
|
+
ASSERT_OK(cache->Insert(key2, item2, GetHelperFail(), str2.length()));
|
|
538
482
|
|
|
539
483
|
Cache::Handle* handle;
|
|
540
|
-
handle =
|
|
541
|
-
cache->Lookup("k2", &kHelperFail, this, Cache::Priority::LOW, true);
|
|
484
|
+
handle = cache->Lookup(key2, GetHelperFail(), this, Cache::Priority::LOW);
|
|
542
485
|
ASSERT_NE(handle, nullptr);
|
|
543
486
|
cache->Release(handle);
|
|
544
487
|
// This lookup should fail, since k1 demotion would have failed.
|
|
545
|
-
handle =
|
|
546
|
-
cache->Lookup("k1", &kHelperFail, this, Cache::Priority::LOW, true);
|
|
488
|
+
handle = cache->Lookup(key1, GetHelperFail(), this, Cache::Priority::LOW);
|
|
547
489
|
ASSERT_EQ(handle, nullptr);
|
|
548
490
|
// Since k1 was not promoted, k2 should still be in cache.
|
|
549
|
-
handle =
|
|
550
|
-
cache->Lookup("k2", &kHelperFail, this, Cache::Priority::LOW, true);
|
|
491
|
+
handle = cache->Lookup(key2, GetHelperFail(), this, Cache::Priority::LOW);
|
|
551
492
|
ASSERT_NE(handle, nullptr);
|
|
552
493
|
cache->Release(handle);
|
|
553
494
|
|
|
@@ -573,34 +514,30 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
573
514
|
std::shared_ptr<SecondaryCache> secondary_cache =
|
|
574
515
|
NewCompressedSecondaryCache(secondary_cache_opts);
|
|
575
516
|
|
|
576
|
-
|
|
517
|
+
std::shared_ptr<Cache> cache = NewCache(
|
|
577
518
|
/*_capacity=*/1300, /*_num_shard_bits=*/0,
|
|
578
|
-
/*_strict_capacity_limit=*/
|
|
579
|
-
/*_memory_allocator=*/nullptr, kDefaultToAdaptiveMutex,
|
|
580
|
-
kDefaultCacheMetadataChargePolicy, /*_low_pri_pool_ratio=*/0.0);
|
|
581
|
-
opts.secondary_cache = secondary_cache;
|
|
582
|
-
std::shared_ptr<Cache> cache = NewLRUCache(opts);
|
|
519
|
+
/*_strict_capacity_limit=*/true, secondary_cache);
|
|
583
520
|
|
|
584
521
|
Random rnd(301);
|
|
585
522
|
std::string str1 = rnd.RandomString(1001);
|
|
586
523
|
auto item1 = new TestItem(str1.data(), str1.length());
|
|
587
|
-
ASSERT_OK(cache->Insert(
|
|
524
|
+
ASSERT_OK(cache->Insert(key1, item1, GetHelper(), str1.length()));
|
|
588
525
|
|
|
589
526
|
std::string str2 = rnd.RandomString(1002);
|
|
590
527
|
auto item2 = new TestItem(str2.data(), str2.length());
|
|
591
528
|
// k1 should be demoted to the secondary cache.
|
|
592
|
-
ASSERT_OK(cache->Insert(
|
|
529
|
+
ASSERT_OK(cache->Insert(key2, item2, GetHelper(), str2.length()));
|
|
593
530
|
|
|
594
531
|
Cache::Handle* handle;
|
|
595
532
|
SetFailCreate(true);
|
|
596
|
-
handle = cache->Lookup(
|
|
533
|
+
handle = cache->Lookup(key2, GetHelper(), this, Cache::Priority::LOW);
|
|
597
534
|
ASSERT_NE(handle, nullptr);
|
|
598
535
|
cache->Release(handle);
|
|
599
536
|
// This lookup should fail, since k1 creation would have failed
|
|
600
|
-
handle = cache->Lookup(
|
|
537
|
+
handle = cache->Lookup(key1, GetHelper(), this, Cache::Priority::LOW);
|
|
601
538
|
ASSERT_EQ(handle, nullptr);
|
|
602
539
|
// Since k1 didn't get promoted, k2 should still be in cache
|
|
603
|
-
handle = cache->Lookup(
|
|
540
|
+
handle = cache->Lookup(key2, GetHelper(), this, Cache::Priority::LOW);
|
|
604
541
|
ASSERT_NE(handle, nullptr);
|
|
605
542
|
cache->Release(handle);
|
|
606
543
|
|
|
@@ -626,38 +563,34 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
626
563
|
std::shared_ptr<SecondaryCache> secondary_cache =
|
|
627
564
|
NewCompressedSecondaryCache(secondary_cache_opts);
|
|
628
565
|
|
|
629
|
-
|
|
566
|
+
std::shared_ptr<Cache> cache = NewCache(
|
|
630
567
|
/*_capacity=*/1300, /*_num_shard_bits=*/0,
|
|
631
|
-
/*_strict_capacity_limit=*/false,
|
|
632
|
-
/*_memory_allocator=*/nullptr, kDefaultToAdaptiveMutex,
|
|
633
|
-
kDefaultCacheMetadataChargePolicy, /*_low_pri_pool_ratio=*/0.0);
|
|
634
|
-
opts.secondary_cache = secondary_cache;
|
|
635
|
-
std::shared_ptr<Cache> cache = NewLRUCache(opts);
|
|
568
|
+
/*_strict_capacity_limit=*/false, secondary_cache);
|
|
636
569
|
|
|
637
570
|
Random rnd(301);
|
|
638
571
|
std::string str1 = rnd.RandomString(1001);
|
|
639
572
|
auto item1_1 = new TestItem(str1.data(), str1.length());
|
|
640
|
-
ASSERT_OK(cache->Insert(
|
|
573
|
+
ASSERT_OK(cache->Insert(key1, item1_1, GetHelper(), str1.length()));
|
|
641
574
|
|
|
642
575
|
std::string str2 = rnd.RandomString(1002);
|
|
643
576
|
std::string str2_clone{str2};
|
|
644
577
|
auto item2 = new TestItem(str2.data(), str2.length());
|
|
645
578
|
// After this Insert, primary cache contains k2 and secondary cache contains
|
|
646
579
|
// k1's dummy item.
|
|
647
|
-
ASSERT_OK(cache->Insert(
|
|
580
|
+
ASSERT_OK(cache->Insert(key2, item2, GetHelper(), str2.length()));
|
|
648
581
|
|
|
649
582
|
// After this Insert, primary cache contains k1 and secondary cache contains
|
|
650
583
|
// k1's dummy item and k2's dummy item.
|
|
651
584
|
auto item1_2 = new TestItem(str1.data(), str1.length());
|
|
652
|
-
ASSERT_OK(cache->Insert(
|
|
585
|
+
ASSERT_OK(cache->Insert(key1, item1_2, GetHelper(), str1.length()));
|
|
653
586
|
|
|
654
587
|
auto item2_2 = new TestItem(str2.data(), str2.length());
|
|
655
588
|
// After this Insert, primary cache contains k2 and secondary cache contains
|
|
656
589
|
// k1's item and k2's dummy item.
|
|
657
|
-
ASSERT_OK(cache->Insert(
|
|
590
|
+
ASSERT_OK(cache->Insert(key2, item2_2, GetHelper(), str2.length()));
|
|
658
591
|
|
|
659
592
|
Cache::Handle* handle2;
|
|
660
|
-
handle2 = cache->Lookup(
|
|
593
|
+
handle2 = cache->Lookup(key2, GetHelper(), this, Cache::Priority::LOW);
|
|
661
594
|
ASSERT_NE(handle2, nullptr);
|
|
662
595
|
cache->Release(handle2);
|
|
663
596
|
|
|
@@ -665,12 +598,12 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
665
598
|
// strict_capacity_limit is true, but the lookup should still succeed.
|
|
666
599
|
// A k1's dummy item is inserted into primary cache.
|
|
667
600
|
Cache::Handle* handle1;
|
|
668
|
-
handle1 = cache->Lookup(
|
|
601
|
+
handle1 = cache->Lookup(key1, GetHelper(), this, Cache::Priority::LOW);
|
|
669
602
|
ASSERT_NE(handle1, nullptr);
|
|
670
603
|
cache->Release(handle1);
|
|
671
604
|
|
|
672
605
|
// Since k1 didn't get inserted, k2 should still be in cache
|
|
673
|
-
handle2 = cache->Lookup(
|
|
606
|
+
handle2 = cache->Lookup(key2, GetHelper(), this, Cache::Priority::LOW);
|
|
674
607
|
ASSERT_NE(handle2, nullptr);
|
|
675
608
|
cache->Release(handle2);
|
|
676
609
|
|
|
@@ -794,26 +727,27 @@ class CompressedSecondaryCacheTest : public testing::Test,
|
|
|
794
727
|
|
|
795
728
|
sec_cache->GetHelper(true)->del_cb(chunks_head, /*alloc*/ nullptr);
|
|
796
729
|
}
|
|
797
|
-
|
|
798
|
-
private:
|
|
799
|
-
bool fail_create_;
|
|
800
730
|
};
|
|
801
731
|
|
|
802
|
-
|
|
803
|
-
|
|
732
|
+
class CompressedSecondaryCacheTest
|
|
733
|
+
: public CompressedSecondaryCacheTestBase,
|
|
734
|
+
public testing::WithParamInterface<std::string> {
|
|
735
|
+
const std::string& Type() override { return GetParam(); }
|
|
736
|
+
};
|
|
804
737
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
CacheEntryRole::kDataBlock)];
|
|
738
|
+
INSTANTIATE_TEST_CASE_P(CompressedSecondaryCacheTest,
|
|
739
|
+
CompressedSecondaryCacheTest, GetTestingCacheTypes());
|
|
808
740
|
|
|
809
741
|
class CompressedSecCacheTestWithCompressAndAllocatorParam
|
|
810
|
-
: public
|
|
811
|
-
public ::testing::WithParamInterface<
|
|
742
|
+
: public CompressedSecondaryCacheTestBase,
|
|
743
|
+
public ::testing::WithParamInterface<
|
|
744
|
+
std::tuple<bool, bool, std::string>> {
|
|
812
745
|
public:
|
|
813
746
|
CompressedSecCacheTestWithCompressAndAllocatorParam() {
|
|
814
747
|
sec_cache_is_compressed_ = std::get<0>(GetParam());
|
|
815
748
|
use_jemalloc_ = std::get<1>(GetParam());
|
|
816
749
|
}
|
|
750
|
+
const std::string& Type() override { return std::get<2>(GetParam()); }
|
|
817
751
|
bool sec_cache_is_compressed_;
|
|
818
752
|
bool use_jemalloc_;
|
|
819
753
|
};
|
|
@@ -824,19 +758,20 @@ TEST_P(CompressedSecCacheTestWithCompressAndAllocatorParam, BasicTes) {
|
|
|
824
758
|
|
|
825
759
|
INSTANTIATE_TEST_CASE_P(CompressedSecCacheTests,
|
|
826
760
|
CompressedSecCacheTestWithCompressAndAllocatorParam,
|
|
827
|
-
::testing::Combine(testing::Bool(), testing::Bool()
|
|
761
|
+
::testing::Combine(testing::Bool(), testing::Bool(),
|
|
762
|
+
GetTestingCacheTypes()));
|
|
828
763
|
|
|
829
764
|
class CompressedSecondaryCacheTestWithCompressionParam
|
|
830
|
-
: public
|
|
831
|
-
public ::testing::WithParamInterface<bool
|
|
765
|
+
: public CompressedSecondaryCacheTestBase,
|
|
766
|
+
public ::testing::WithParamInterface<std::tuple<bool, std::string>> {
|
|
832
767
|
public:
|
|
833
768
|
CompressedSecondaryCacheTestWithCompressionParam() {
|
|
834
|
-
sec_cache_is_compressed_ = GetParam();
|
|
769
|
+
sec_cache_is_compressed_ = std::get<0>(GetParam());
|
|
835
770
|
}
|
|
771
|
+
const std::string& Type() override { return std::get<1>(GetParam()); }
|
|
836
772
|
bool sec_cache_is_compressed_;
|
|
837
773
|
};
|
|
838
774
|
|
|
839
|
-
|
|
840
775
|
TEST_P(CompressedSecondaryCacheTestWithCompressionParam, BasicTestFromString) {
|
|
841
776
|
std::shared_ptr<SecondaryCache> sec_cache{nullptr};
|
|
842
777
|
std::string sec_cache_uri;
|
|
@@ -961,19 +896,19 @@ TEST_P(CompressedSecondaryCacheTestWithCompressionParam, EntryRoles) {
|
|
|
961
896
|
// Uniquify `junk`
|
|
962
897
|
junk[0] = static_cast<char>(i);
|
|
963
898
|
TestItem item{junk.data(), junk.length()};
|
|
964
|
-
Slice ith_key = Slice(junk.data(),
|
|
899
|
+
Slice ith_key = Slice(junk.data(), 16);
|
|
965
900
|
|
|
966
901
|
get_perf_context()->Reset();
|
|
967
|
-
ASSERT_OK(sec_cache->Insert(ith_key, &item,
|
|
902
|
+
ASSERT_OK(sec_cache->Insert(ith_key, &item, GetHelper(role)));
|
|
968
903
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_dummy_count, 1U);
|
|
969
904
|
|
|
970
|
-
ASSERT_OK(sec_cache->Insert(ith_key, &item,
|
|
905
|
+
ASSERT_OK(sec_cache->Insert(ith_key, &item, GetHelper(role)));
|
|
971
906
|
ASSERT_EQ(get_perf_context()->compressed_sec_cache_insert_real_count, 1U);
|
|
972
907
|
|
|
973
|
-
bool
|
|
908
|
+
bool kept_in_sec_cache{true};
|
|
974
909
|
std::unique_ptr<SecondaryCacheResultHandle> handle =
|
|
975
|
-
sec_cache->Lookup(ith_key,
|
|
976
|
-
/*advise_erase=*/true,
|
|
910
|
+
sec_cache->Lookup(ith_key, GetHelper(role), this, true,
|
|
911
|
+
/*advise_erase=*/true, kept_in_sec_cache);
|
|
977
912
|
ASSERT_NE(handle, nullptr);
|
|
978
913
|
|
|
979
914
|
// Lookup returns the right data
|
|
@@ -998,16 +933,19 @@ TEST_P(CompressedSecondaryCacheTestWithCompressionParam, EntryRoles) {
|
|
|
998
933
|
|
|
999
934
|
INSTANTIATE_TEST_CASE_P(CompressedSecCacheTests,
|
|
1000
935
|
CompressedSecondaryCacheTestWithCompressionParam,
|
|
1001
|
-
testing::Bool()
|
|
936
|
+
testing::Combine(testing::Bool(),
|
|
937
|
+
GetTestingCacheTypes()));
|
|
1002
938
|
|
|
1003
939
|
class CompressedSecCacheTestWithCompressAndSplitParam
|
|
1004
|
-
: public
|
|
1005
|
-
public ::testing::WithParamInterface<
|
|
940
|
+
: public CompressedSecondaryCacheTestBase,
|
|
941
|
+
public ::testing::WithParamInterface<
|
|
942
|
+
std::tuple<bool, bool, std::string>> {
|
|
1006
943
|
public:
|
|
1007
944
|
CompressedSecCacheTestWithCompressAndSplitParam() {
|
|
1008
945
|
sec_cache_is_compressed_ = std::get<0>(GetParam());
|
|
1009
946
|
enable_custom_split_merge_ = std::get<1>(GetParam());
|
|
1010
947
|
}
|
|
948
|
+
const std::string& Type() override { return std::get<2>(GetParam()); }
|
|
1011
949
|
bool sec_cache_is_compressed_;
|
|
1012
950
|
bool enable_custom_split_merge_;
|
|
1013
951
|
};
|
|
@@ -1018,17 +956,18 @@ TEST_P(CompressedSecCacheTestWithCompressAndSplitParam, BasicIntegrationTest) {
|
|
|
1018
956
|
|
|
1019
957
|
INSTANTIATE_TEST_CASE_P(CompressedSecCacheTests,
|
|
1020
958
|
CompressedSecCacheTestWithCompressAndSplitParam,
|
|
1021
|
-
::testing::Combine(testing::Bool(), testing::Bool()
|
|
959
|
+
::testing::Combine(testing::Bool(), testing::Bool(),
|
|
960
|
+
GetTestingCacheTypes()));
|
|
1022
961
|
|
|
1023
|
-
|
|
962
|
+
TEST_P(CompressedSecondaryCacheTest, SplitValueIntoChunksTest) {
|
|
1024
963
|
SplitValueIntoChunksTest();
|
|
1025
964
|
}
|
|
1026
965
|
|
|
1027
|
-
|
|
966
|
+
TEST_P(CompressedSecondaryCacheTest, MergeChunksIntoValueTest) {
|
|
1028
967
|
MergeChunksIntoValueTest();
|
|
1029
968
|
}
|
|
1030
969
|
|
|
1031
|
-
|
|
970
|
+
TEST_P(CompressedSecondaryCacheTest, SplictValueAndMergeChunksTest) {
|
|
1032
971
|
SplictValueAndMergeChunksTest();
|
|
1033
972
|
}
|
|
1034
973
|
|