@nxtedition/rocksdb 7.1.25 → 7.1.27
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 +15 -7
- package/deps/rocksdb/rocksdb/cache/clock_cache.cc +7 -4
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +18 -2
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +5 -1
- package/deps/rocksdb/rocksdb/db/db_iter.cc +2 -1
- package/deps/rocksdb/rocksdb/db/db_test_util.cc +4 -2
- package/deps/rocksdb/rocksdb/db/db_test_util.h +1 -1
- package/deps/rocksdb/rocksdb/db/version_set.cc +1 -1
- package/deps/rocksdb/rocksdb/include/rocksdb/block_cache_trace_writer.h +149 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/db.h +8 -1
- package/deps/rocksdb/rocksdb/include/rocksdb/table.h +1 -1
- package/deps/rocksdb/rocksdb/{table → include/rocksdb}/table_reader_caller.h +0 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/utilities/stackable_db.h +7 -1
- package/deps/rocksdb/rocksdb/table/table_reader.h +1 -1
- package/deps/rocksdb/rocksdb/table/table_test.cc +29 -22
- package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_trace_analyzer.cc +1 -1
- package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_trace_analyzer.h +1 -1
- package/deps/rocksdb/rocksdb/tools/block_cache_analyzer/block_cache_trace_analyzer_test.cc +25 -16
- package/deps/rocksdb/rocksdb/trace_replay/block_cache_tracer.cc +28 -21
- package/deps/rocksdb/rocksdb/trace_replay/block_cache_tracer.h +16 -72
- package/deps/rocksdb/rocksdb/trace_replay/block_cache_tracer_test.cc +74 -38
- package/deps/rocksdb/rocksdb/util/user_comparator_wrapper.h +11 -31
- package/deps/rocksdb/rocksdb/utilities/simulator_cache/cache_simulator.cc +2 -2
- package/deps/rocksdb/rocksdb/utilities/simulator_cache/cache_simulator_test.cc +13 -13
- package/deps/rocksdb/rocksdb.gyp +1 -0
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
namespace ROCKSDB_NAMESPACE {
|
|
21
21
|
|
|
22
22
|
namespace {
|
|
23
|
-
bool ShouldTrace(const Slice& block_key,
|
|
23
|
+
bool ShouldTrace(const Slice& block_key,
|
|
24
|
+
const BlockCacheTraceOptions& trace_options) {
|
|
24
25
|
if (trace_options.sampling_frequency == 0 ||
|
|
25
26
|
trace_options.sampling_frequency == 1) {
|
|
26
27
|
return true;
|
|
@@ -36,6 +37,7 @@ const uint64_t kSecondInMinute = 60;
|
|
|
36
37
|
const uint64_t kSecondInHour = 3600;
|
|
37
38
|
const std::string BlockCacheTraceHelper::kUnknownColumnFamilyName =
|
|
38
39
|
"UnknownColumnFamily";
|
|
40
|
+
const uint64_t BlockCacheTraceRecord::kReservedGetId = 0;
|
|
39
41
|
const uint64_t BlockCacheTraceHelper::kReservedGetId = 0;
|
|
40
42
|
|
|
41
43
|
bool BlockCacheTraceHelper::IsGetOrMultiGetOnDataBlock(
|
|
@@ -79,9 +81,9 @@ uint64_t BlockCacheTraceHelper::GetSequenceNumber(
|
|
|
79
81
|
if (!IsGetOrMultiGet(access.caller)) {
|
|
80
82
|
return 0;
|
|
81
83
|
}
|
|
82
|
-
return access.get_from_user_specified_snapshot
|
|
83
|
-
?
|
|
84
|
-
:
|
|
84
|
+
return access.get_from_user_specified_snapshot
|
|
85
|
+
? 1 + GetInternalKeySeqno(access.referenced_key)
|
|
86
|
+
: 0;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
uint64_t BlockCacheTraceHelper::GetBlockOffsetInFile(
|
|
@@ -99,14 +101,14 @@ uint64_t BlockCacheTraceHelper::GetBlockOffsetInFile(
|
|
|
99
101
|
return offset;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
|
|
103
|
-
SystemClock* clock, const
|
|
104
|
+
BlockCacheTraceWriterImpl::BlockCacheTraceWriterImpl(
|
|
105
|
+
SystemClock* clock, const BlockCacheTraceWriterOptions& trace_options,
|
|
104
106
|
std::unique_ptr<TraceWriter>&& trace_writer)
|
|
105
107
|
: clock_(clock),
|
|
106
108
|
trace_options_(trace_options),
|
|
107
109
|
trace_writer_(std::move(trace_writer)) {}
|
|
108
110
|
|
|
109
|
-
Status
|
|
111
|
+
Status BlockCacheTraceWriterImpl::WriteBlockAccess(
|
|
110
112
|
const BlockCacheTraceRecord& record, const Slice& block_key,
|
|
111
113
|
const Slice& cf_name, const Slice& referenced_key) {
|
|
112
114
|
uint64_t trace_file_size = trace_writer_->GetFileSize();
|
|
@@ -141,7 +143,7 @@ Status BlockCacheTraceWriter::WriteBlockAccess(
|
|
|
141
143
|
return trace_writer_->Write(encoded_trace);
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
Status
|
|
146
|
+
Status BlockCacheTraceWriterImpl::WriteHeader() {
|
|
145
147
|
Trace trace;
|
|
146
148
|
trace.ts = clock_->NowMicros();
|
|
147
149
|
trace.type = TraceType::kTraceBegin;
|
|
@@ -255,13 +257,13 @@ Status BlockCacheTraceReader::ReadAccess(BlockCacheTraceRecord* record) {
|
|
|
255
257
|
return Status::Incomplete(
|
|
256
258
|
"Incomplete access record: Failed to read is_cache_hit.");
|
|
257
259
|
}
|
|
258
|
-
record->is_cache_hit = static_cast<
|
|
260
|
+
record->is_cache_hit = static_cast<char>(enc_slice[0]);
|
|
259
261
|
enc_slice.remove_prefix(kCharSize);
|
|
260
262
|
if (enc_slice.empty()) {
|
|
261
263
|
return Status::Incomplete(
|
|
262
264
|
"Incomplete access record: Failed to read no_insert.");
|
|
263
265
|
}
|
|
264
|
-
record->no_insert = static_cast<
|
|
266
|
+
record->no_insert = static_cast<char>(enc_slice[0]);
|
|
265
267
|
enc_slice.remove_prefix(kCharSize);
|
|
266
268
|
if (BlockCacheTraceHelper::IsGetOrMultiGet(record->caller)) {
|
|
267
269
|
if (!GetFixed64(&enc_slice, &record->get_id)) {
|
|
@@ -273,8 +275,7 @@ Status BlockCacheTraceReader::ReadAccess(BlockCacheTraceRecord* record) {
|
|
|
273
275
|
"Incomplete access record: Failed to read "
|
|
274
276
|
"get_from_user_specified_snapshot.");
|
|
275
277
|
}
|
|
276
|
-
record->get_from_user_specified_snapshot =
|
|
277
|
-
static_cast<Boolean>(enc_slice[0]);
|
|
278
|
+
record->get_from_user_specified_snapshot = static_cast<char>(enc_slice[0]);
|
|
278
279
|
enc_slice.remove_prefix(kCharSize);
|
|
279
280
|
Slice referenced_key;
|
|
280
281
|
if (!GetLengthPrefixedSlice(&enc_slice, &referenced_key)) {
|
|
@@ -299,7 +300,7 @@ Status BlockCacheTraceReader::ReadAccess(BlockCacheTraceRecord* record) {
|
|
|
299
300
|
"Incomplete access record: Failed to read "
|
|
300
301
|
"referenced_key_exist_in_block.");
|
|
301
302
|
}
|
|
302
|
-
record->referenced_key_exist_in_block = static_cast<
|
|
303
|
+
record->referenced_key_exist_in_block = static_cast<char>(enc_slice[0]);
|
|
303
304
|
}
|
|
304
305
|
return Status::OK();
|
|
305
306
|
}
|
|
@@ -391,14 +392,14 @@ Status BlockCacheHumanReadableTraceReader::ReadAccess(
|
|
|
391
392
|
record->level = static_cast<uint32_t>(ParseUint64(record_strs[6]));
|
|
392
393
|
record->sst_fd_number = ParseUint64(record_strs[7]);
|
|
393
394
|
record->caller = static_cast<TableReaderCaller>(ParseUint64(record_strs[8]));
|
|
394
|
-
record->no_insert = static_cast<
|
|
395
|
+
record->no_insert = static_cast<char>(ParseUint64(record_strs[9]));
|
|
395
396
|
record->get_id = ParseUint64(record_strs[10]);
|
|
396
397
|
uint64_t get_key_id = ParseUint64(record_strs[11]);
|
|
397
398
|
|
|
398
399
|
record->referenced_data_size = ParseUint64(record_strs[12]);
|
|
399
|
-
record->is_cache_hit = static_cast<
|
|
400
|
+
record->is_cache_hit = static_cast<char>(ParseUint64(record_strs[13]));
|
|
400
401
|
record->referenced_key_exist_in_block =
|
|
401
|
-
static_cast<
|
|
402
|
+
static_cast<char>(ParseUint64(record_strs[14]));
|
|
402
403
|
record->num_keys_in_block = ParseUint64(record_strs[15]);
|
|
403
404
|
uint64_t table_id = ParseUint64(record_strs[16]);
|
|
404
405
|
if (table_id > 0) {
|
|
@@ -408,7 +409,7 @@ Status BlockCacheHumanReadableTraceReader::ReadAccess(
|
|
|
408
409
|
}
|
|
409
410
|
uint64_t get_sequence_number = ParseUint64(record_strs[17]);
|
|
410
411
|
if (get_sequence_number > 0) {
|
|
411
|
-
record->get_from_user_specified_snapshot =
|
|
412
|
+
record->get_from_user_specified_snapshot = true;
|
|
412
413
|
// Decrement since valid seq number in the trace file equals traced seq
|
|
413
414
|
// number + 1.
|
|
414
415
|
get_sequence_number -= 1;
|
|
@@ -445,16 +446,15 @@ BlockCacheTracer::BlockCacheTracer() { writer_.store(nullptr); }
|
|
|
445
446
|
BlockCacheTracer::~BlockCacheTracer() { EndTrace(); }
|
|
446
447
|
|
|
447
448
|
Status BlockCacheTracer::StartTrace(
|
|
448
|
-
|
|
449
|
-
std::unique_ptr<
|
|
449
|
+
const BlockCacheTraceOptions& trace_options,
|
|
450
|
+
std::unique_ptr<BlockCacheTraceWriter>&& trace_writer) {
|
|
450
451
|
InstrumentedMutexLock lock_guard(&trace_writer_mutex_);
|
|
451
452
|
if (writer_.load()) {
|
|
452
453
|
return Status::Busy();
|
|
453
454
|
}
|
|
454
455
|
get_id_counter_.store(1);
|
|
455
456
|
trace_options_ = trace_options;
|
|
456
|
-
writer_.store(
|
|
457
|
-
new BlockCacheTraceWriter(clock, trace_options, std::move(trace_writer)));
|
|
457
|
+
writer_.store(trace_writer.release());
|
|
458
458
|
return writer_.load()->WriteHeader();
|
|
459
459
|
}
|
|
460
460
|
|
|
@@ -494,4 +494,11 @@ uint64_t BlockCacheTracer::NextGetId() {
|
|
|
494
494
|
return prev_value;
|
|
495
495
|
}
|
|
496
496
|
|
|
497
|
+
std::unique_ptr<BlockCacheTraceWriter> NewBlockCacheTraceWriter(
|
|
498
|
+
SystemClock* clock, const BlockCacheTraceWriterOptions& trace_options,
|
|
499
|
+
std::unique_ptr<TraceWriter>&& trace_writer) {
|
|
500
|
+
return std::unique_ptr<BlockCacheTraceWriter>(new BlockCacheTraceWriterImpl(
|
|
501
|
+
clock, trace_options, std::move(trace_writer)));
|
|
502
|
+
}
|
|
503
|
+
|
|
497
504
|
} // namespace ROCKSDB_NAMESPACE
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
#include <fstream>
|
|
10
10
|
|
|
11
11
|
#include "monitoring/instrumented_mutex.h"
|
|
12
|
+
#include "rocksdb/block_cache_trace_writer.h"
|
|
12
13
|
#include "rocksdb/options.h"
|
|
14
|
+
#include "rocksdb/table_reader_caller.h"
|
|
13
15
|
#include "rocksdb/trace_reader_writer.h"
|
|
14
|
-
#include "table/table_reader_caller.h"
|
|
15
16
|
#include "trace_replay/trace_replay.h"
|
|
16
17
|
|
|
17
18
|
namespace ROCKSDB_NAMESPACE {
|
|
@@ -102,65 +103,6 @@ struct BlockCacheLookupContext {
|
|
|
102
103
|
}
|
|
103
104
|
};
|
|
104
105
|
|
|
105
|
-
enum Boolean : char { kTrue = 1, kFalse = 0 };
|
|
106
|
-
|
|
107
|
-
struct BlockCacheTraceRecord {
|
|
108
|
-
// Required fields for all accesses.
|
|
109
|
-
uint64_t access_timestamp = 0;
|
|
110
|
-
std::string block_key;
|
|
111
|
-
TraceType block_type = TraceType::kTraceMax;
|
|
112
|
-
uint64_t block_size = 0;
|
|
113
|
-
uint64_t cf_id = 0;
|
|
114
|
-
std::string cf_name;
|
|
115
|
-
uint32_t level = 0;
|
|
116
|
-
uint64_t sst_fd_number = 0;
|
|
117
|
-
TableReaderCaller caller = TableReaderCaller::kMaxBlockCacheLookupCaller;
|
|
118
|
-
Boolean is_cache_hit = Boolean::kFalse;
|
|
119
|
-
Boolean no_insert = Boolean::kFalse;
|
|
120
|
-
// Required field for Get and MultiGet
|
|
121
|
-
uint64_t get_id = BlockCacheTraceHelper::kReservedGetId;
|
|
122
|
-
Boolean get_from_user_specified_snapshot = Boolean::kFalse;
|
|
123
|
-
std::string referenced_key;
|
|
124
|
-
// Required fields for data block and user Get/Multi-Get only.
|
|
125
|
-
uint64_t referenced_data_size = 0;
|
|
126
|
-
uint64_t num_keys_in_block = 0;
|
|
127
|
-
Boolean referenced_key_exist_in_block = Boolean::kFalse;
|
|
128
|
-
|
|
129
|
-
BlockCacheTraceRecord() {}
|
|
130
|
-
|
|
131
|
-
BlockCacheTraceRecord(
|
|
132
|
-
uint64_t _access_timestamp, std::string _block_key, TraceType _block_type,
|
|
133
|
-
uint64_t _block_size, uint64_t _cf_id, std::string _cf_name,
|
|
134
|
-
uint32_t _level, uint64_t _sst_fd_number, TableReaderCaller _caller,
|
|
135
|
-
bool _is_cache_hit, bool _no_insert,
|
|
136
|
-
uint64_t _get_id = BlockCacheTraceHelper::kReservedGetId,
|
|
137
|
-
bool _get_from_user_specified_snapshot = false,
|
|
138
|
-
std::string _referenced_key = "", uint64_t _referenced_data_size = 0,
|
|
139
|
-
uint64_t _num_keys_in_block = 0,
|
|
140
|
-
bool _referenced_key_exist_in_block = false)
|
|
141
|
-
: access_timestamp(_access_timestamp),
|
|
142
|
-
block_key(_block_key),
|
|
143
|
-
block_type(_block_type),
|
|
144
|
-
block_size(_block_size),
|
|
145
|
-
cf_id(_cf_id),
|
|
146
|
-
cf_name(_cf_name),
|
|
147
|
-
level(_level),
|
|
148
|
-
sst_fd_number(_sst_fd_number),
|
|
149
|
-
caller(_caller),
|
|
150
|
-
is_cache_hit(_is_cache_hit ? Boolean::kTrue : Boolean::kFalse),
|
|
151
|
-
no_insert(_no_insert ? Boolean::kTrue : Boolean::kFalse),
|
|
152
|
-
get_id(_get_id),
|
|
153
|
-
get_from_user_specified_snapshot(_get_from_user_specified_snapshot
|
|
154
|
-
? Boolean::kTrue
|
|
155
|
-
: Boolean::kFalse),
|
|
156
|
-
referenced_key(_referenced_key),
|
|
157
|
-
referenced_data_size(_referenced_data_size),
|
|
158
|
-
num_keys_in_block(_num_keys_in_block),
|
|
159
|
-
referenced_key_exist_in_block(
|
|
160
|
-
_referenced_key_exist_in_block ? Boolean::kTrue : Boolean::kFalse) {
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
106
|
struct BlockCacheTraceHeader {
|
|
165
107
|
uint64_t start_time;
|
|
166
108
|
uint32_t rocksdb_major_version;
|
|
@@ -171,16 +113,18 @@ struct BlockCacheTraceHeader {
|
|
|
171
113
|
// user-provided TraceWriter. Every RocksDB operation is written as a single
|
|
172
114
|
// trace. Each trace will have a timestamp and type, followed by the trace
|
|
173
115
|
// payload.
|
|
174
|
-
class BlockCacheTraceWriter {
|
|
116
|
+
class BlockCacheTraceWriterImpl : public BlockCacheTraceWriter {
|
|
175
117
|
public:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
118
|
+
BlockCacheTraceWriterImpl(SystemClock* clock,
|
|
119
|
+
const BlockCacheTraceWriterOptions& trace_options,
|
|
120
|
+
std::unique_ptr<TraceWriter>&& trace_writer);
|
|
121
|
+
~BlockCacheTraceWriterImpl() = default;
|
|
179
122
|
// No copy and move.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
123
|
+
BlockCacheTraceWriterImpl(const BlockCacheTraceWriterImpl&) = delete;
|
|
124
|
+
BlockCacheTraceWriterImpl& operator=(const BlockCacheTraceWriterImpl&) =
|
|
125
|
+
delete;
|
|
126
|
+
BlockCacheTraceWriterImpl(BlockCacheTraceWriterImpl&&) = delete;
|
|
127
|
+
BlockCacheTraceWriterImpl& operator=(BlockCacheTraceWriterImpl&&) = delete;
|
|
184
128
|
|
|
185
129
|
// Pass Slice references to avoid copy.
|
|
186
130
|
Status WriteBlockAccess(const BlockCacheTraceRecord& record,
|
|
@@ -193,7 +137,7 @@ class BlockCacheTraceWriter {
|
|
|
193
137
|
|
|
194
138
|
private:
|
|
195
139
|
SystemClock* clock_;
|
|
196
|
-
|
|
140
|
+
BlockCacheTraceWriterOptions trace_options_;
|
|
197
141
|
std::unique_ptr<TraceWriter> trace_writer_;
|
|
198
142
|
};
|
|
199
143
|
|
|
@@ -267,8 +211,8 @@ class BlockCacheTracer {
|
|
|
267
211
|
BlockCacheTracer& operator=(BlockCacheTracer&&) = delete;
|
|
268
212
|
|
|
269
213
|
// Start writing block cache accesses to the trace_writer.
|
|
270
|
-
Status StartTrace(
|
|
271
|
-
std::unique_ptr<
|
|
214
|
+
Status StartTrace(const BlockCacheTraceOptions& trace_options,
|
|
215
|
+
std::unique_ptr<BlockCacheTraceWriter>&& trace_writer);
|
|
272
216
|
|
|
273
217
|
// Stop writing block cache accesses to the trace_writer.
|
|
274
218
|
void EndTrace();
|
|
@@ -285,7 +229,7 @@ class BlockCacheTracer {
|
|
|
285
229
|
uint64_t NextGetId();
|
|
286
230
|
|
|
287
231
|
private:
|
|
288
|
-
|
|
232
|
+
BlockCacheTraceOptions trace_options_;
|
|
289
233
|
// A mutex protects the writer_.
|
|
290
234
|
InstrumentedMutex trace_writer_mutex_;
|
|
291
235
|
std::atomic<BlockCacheTraceWriter*> writer_;
|
|
@@ -74,17 +74,17 @@ class BlockCacheTracerTest : public testing::Test {
|
|
|
74
74
|
record.caller = GetCaller(key_id);
|
|
75
75
|
record.level = kLevel;
|
|
76
76
|
record.sst_fd_number = kSSTFDNumber + key_id;
|
|
77
|
-
record.is_cache_hit =
|
|
78
|
-
record.no_insert =
|
|
77
|
+
record.is_cache_hit = false;
|
|
78
|
+
record.no_insert = false;
|
|
79
79
|
// Provide get_id for all callers. The writer should only write get_id
|
|
80
80
|
// when the caller is either GET or MGET.
|
|
81
81
|
record.get_id = key_id + 1;
|
|
82
|
-
record.get_from_user_specified_snapshot =
|
|
82
|
+
record.get_from_user_specified_snapshot = true;
|
|
83
83
|
// Provide these fields for all block types.
|
|
84
84
|
// The writer should only write these fields for data blocks and the
|
|
85
85
|
// caller is either GET or MGET.
|
|
86
86
|
record.referenced_key = (kRefKeyPrefix + std::to_string(key_id));
|
|
87
|
-
record.referenced_key_exist_in_block =
|
|
87
|
+
record.referenced_key_exist_in_block = true;
|
|
88
88
|
record.num_keys_in_block = kNumKeysInBlock;
|
|
89
89
|
record.referenced_data_size = kReferencedDataSize + key_id;
|
|
90
90
|
ASSERT_OK(writer->WriteBlockAccess(
|
|
@@ -104,10 +104,10 @@ class BlockCacheTracerTest : public testing::Test {
|
|
|
104
104
|
record.caller = GetCaller(key_id);
|
|
105
105
|
record.level = kLevel;
|
|
106
106
|
record.sst_fd_number = kSSTFDNumber + key_id;
|
|
107
|
-
record.is_cache_hit =
|
|
108
|
-
record.no_insert =
|
|
107
|
+
record.is_cache_hit = false;
|
|
108
|
+
record.no_insert = false;
|
|
109
109
|
record.referenced_key = kRefKeyPrefix + std::to_string(key_id);
|
|
110
|
-
record.referenced_key_exist_in_block =
|
|
110
|
+
record.referenced_key_exist_in_block = true;
|
|
111
111
|
record.num_keys_in_block = kNumKeysInBlock;
|
|
112
112
|
return record;
|
|
113
113
|
}
|
|
@@ -127,28 +127,28 @@ class BlockCacheTracerTest : public testing::Test {
|
|
|
127
127
|
ASSERT_EQ(GetCaller(key_id), record.caller);
|
|
128
128
|
ASSERT_EQ(kLevel, record.level);
|
|
129
129
|
ASSERT_EQ(kSSTFDNumber + key_id, record.sst_fd_number);
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
ASSERT_FALSE(record.is_cache_hit);
|
|
131
|
+
ASSERT_FALSE(record.no_insert);
|
|
132
132
|
if (record.caller == TableReaderCaller::kUserGet ||
|
|
133
133
|
record.caller == TableReaderCaller::kUserMultiGet) {
|
|
134
134
|
ASSERT_EQ(key_id + 1, record.get_id);
|
|
135
|
-
|
|
135
|
+
ASSERT_TRUE(record.get_from_user_specified_snapshot);
|
|
136
136
|
ASSERT_EQ(kRefKeyPrefix + std::to_string(key_id),
|
|
137
137
|
record.referenced_key);
|
|
138
138
|
} else {
|
|
139
139
|
ASSERT_EQ(BlockCacheTraceHelper::kReservedGetId, record.get_id);
|
|
140
|
-
|
|
140
|
+
ASSERT_FALSE(record.get_from_user_specified_snapshot);
|
|
141
141
|
ASSERT_EQ("", record.referenced_key);
|
|
142
142
|
}
|
|
143
143
|
if (block_type == TraceType::kBlockTraceDataBlock &&
|
|
144
144
|
(record.caller == TableReaderCaller::kUserGet ||
|
|
145
145
|
record.caller == TableReaderCaller::kUserMultiGet)) {
|
|
146
|
-
|
|
146
|
+
ASSERT_TRUE(record.referenced_key_exist_in_block);
|
|
147
147
|
ASSERT_EQ(kNumKeysInBlock, record.num_keys_in_block);
|
|
148
148
|
ASSERT_EQ(kReferencedDataSize + key_id, record.referenced_data_size);
|
|
149
149
|
continue;
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
ASSERT_FALSE(record.referenced_key_exist_in_block);
|
|
152
152
|
ASSERT_EQ(0, record.num_keys_in_block);
|
|
153
153
|
ASSERT_EQ(0, record.referenced_data_size);
|
|
154
154
|
}
|
|
@@ -188,12 +188,18 @@ TEST_F(BlockCacheTracerTest, AtomicWriteBeforeStartTrace) {
|
|
|
188
188
|
TEST_F(BlockCacheTracerTest, AtomicWrite) {
|
|
189
189
|
BlockCacheTraceRecord record = GenerateAccessRecord();
|
|
190
190
|
{
|
|
191
|
-
|
|
191
|
+
BlockCacheTraceWriterOptions trace_writer_opt;
|
|
192
|
+
BlockCacheTraceOptions trace_opt;
|
|
192
193
|
std::unique_ptr<TraceWriter> trace_writer;
|
|
193
194
|
ASSERT_OK(NewFileTraceWriter(env_, env_options_, trace_file_path_,
|
|
194
195
|
&trace_writer));
|
|
196
|
+
std::unique_ptr<BlockCacheTraceWriter> block_cache_trace_writer =
|
|
197
|
+
NewBlockCacheTraceWriter(env_->GetSystemClock().get(), trace_writer_opt,
|
|
198
|
+
std::move(trace_writer));
|
|
199
|
+
ASSERT_NE(block_cache_trace_writer, nullptr);
|
|
195
200
|
BlockCacheTracer writer;
|
|
196
|
-
ASSERT_OK(
|
|
201
|
+
ASSERT_OK(
|
|
202
|
+
writer.StartTrace(trace_opt, std::move(block_cache_trace_writer)));
|
|
197
203
|
ASSERT_OK(writer.WriteBlockAccess(record, record.block_key, record.cf_name,
|
|
198
204
|
record.referenced_key));
|
|
199
205
|
ASSERT_OK(env_->FileExists(trace_file_path_));
|
|
@@ -214,25 +220,36 @@ TEST_F(BlockCacheTracerTest, AtomicWrite) {
|
|
|
214
220
|
}
|
|
215
221
|
|
|
216
222
|
TEST_F(BlockCacheTracerTest, ConsecutiveStartTrace) {
|
|
217
|
-
|
|
223
|
+
BlockCacheTraceWriterOptions trace_writer_opt;
|
|
224
|
+
BlockCacheTraceOptions trace_opt;
|
|
218
225
|
std::unique_ptr<TraceWriter> trace_writer;
|
|
219
226
|
ASSERT_OK(
|
|
220
227
|
NewFileTraceWriter(env_, env_options_, trace_file_path_, &trace_writer));
|
|
228
|
+
std::unique_ptr<BlockCacheTraceWriter> block_cache_trace_writer =
|
|
229
|
+
NewBlockCacheTraceWriter(env_->GetSystemClock().get(), trace_writer_opt,
|
|
230
|
+
std::move(trace_writer));
|
|
231
|
+
ASSERT_NE(block_cache_trace_writer, nullptr);
|
|
221
232
|
BlockCacheTracer writer;
|
|
222
|
-
ASSERT_OK(writer.StartTrace(
|
|
223
|
-
ASSERT_NOK(writer.StartTrace(
|
|
233
|
+
ASSERT_OK(writer.StartTrace(trace_opt, std::move(block_cache_trace_writer)));
|
|
234
|
+
ASSERT_NOK(writer.StartTrace(trace_opt, std::move(block_cache_trace_writer)));
|
|
224
235
|
ASSERT_OK(env_->FileExists(trace_file_path_));
|
|
225
236
|
}
|
|
226
237
|
|
|
227
238
|
TEST_F(BlockCacheTracerTest, AtomicNoWriteAfterEndTrace) {
|
|
228
239
|
BlockCacheTraceRecord record = GenerateAccessRecord();
|
|
229
240
|
{
|
|
230
|
-
|
|
241
|
+
BlockCacheTraceWriterOptions trace_writer_opt;
|
|
242
|
+
BlockCacheTraceOptions trace_opt;
|
|
231
243
|
std::unique_ptr<TraceWriter> trace_writer;
|
|
232
244
|
ASSERT_OK(NewFileTraceWriter(env_, env_options_, trace_file_path_,
|
|
233
245
|
&trace_writer));
|
|
246
|
+
std::unique_ptr<BlockCacheTraceWriter> block_cache_trace_writer =
|
|
247
|
+
NewBlockCacheTraceWriter(env_->GetSystemClock().get(), trace_writer_opt,
|
|
248
|
+
std::move(trace_writer));
|
|
249
|
+
ASSERT_NE(block_cache_trace_writer, nullptr);
|
|
234
250
|
BlockCacheTracer writer;
|
|
235
|
-
ASSERT_OK(
|
|
251
|
+
ASSERT_OK(
|
|
252
|
+
writer.StartTrace(trace_opt, std::move(block_cache_trace_writer)));
|
|
236
253
|
ASSERT_OK(writer.WriteBlockAccess(record, record.block_key, record.cf_name,
|
|
237
254
|
record.referenced_key));
|
|
238
255
|
writer.EndTrace();
|
|
@@ -260,14 +277,20 @@ TEST_F(BlockCacheTracerTest, AtomicNoWriteAfterEndTrace) {
|
|
|
260
277
|
TEST_F(BlockCacheTracerTest, NextGetId) {
|
|
261
278
|
BlockCacheTracer writer;
|
|
262
279
|
{
|
|
263
|
-
|
|
280
|
+
BlockCacheTraceWriterOptions trace_writer_opt;
|
|
281
|
+
BlockCacheTraceOptions trace_opt;
|
|
264
282
|
std::unique_ptr<TraceWriter> trace_writer;
|
|
265
283
|
ASSERT_OK(NewFileTraceWriter(env_, env_options_, trace_file_path_,
|
|
266
284
|
&trace_writer));
|
|
285
|
+
std::unique_ptr<BlockCacheTraceWriter> block_cache_trace_writer =
|
|
286
|
+
NewBlockCacheTraceWriter(env_->GetSystemClock().get(), trace_writer_opt,
|
|
287
|
+
std::move(trace_writer));
|
|
288
|
+
ASSERT_NE(block_cache_trace_writer, nullptr);
|
|
267
289
|
// next get id should always return 0 before we call StartTrace.
|
|
268
290
|
ASSERT_EQ(0, writer.NextGetId());
|
|
269
291
|
ASSERT_EQ(0, writer.NextGetId());
|
|
270
|
-
ASSERT_OK(
|
|
292
|
+
ASSERT_OK(
|
|
293
|
+
writer.StartTrace(trace_opt, std::move(block_cache_trace_writer)));
|
|
271
294
|
ASSERT_EQ(1, writer.NextGetId());
|
|
272
295
|
ASSERT_EQ(2, writer.NextGetId());
|
|
273
296
|
writer.EndTrace();
|
|
@@ -277,11 +300,17 @@ TEST_F(BlockCacheTracerTest, NextGetId) {
|
|
|
277
300
|
|
|
278
301
|
// Start trace again and next get id should return 1.
|
|
279
302
|
{
|
|
280
|
-
|
|
303
|
+
BlockCacheTraceWriterOptions trace_writer_opt;
|
|
304
|
+
BlockCacheTraceOptions trace_opt;
|
|
281
305
|
std::unique_ptr<TraceWriter> trace_writer;
|
|
282
306
|
ASSERT_OK(NewFileTraceWriter(env_, env_options_, trace_file_path_,
|
|
283
307
|
&trace_writer));
|
|
284
|
-
|
|
308
|
+
std::unique_ptr<BlockCacheTraceWriter> block_cache_trace_writer =
|
|
309
|
+
NewBlockCacheTraceWriter(env_->GetSystemClock().get(), trace_writer_opt,
|
|
310
|
+
std::move(trace_writer));
|
|
311
|
+
ASSERT_NE(block_cache_trace_writer, nullptr);
|
|
312
|
+
ASSERT_OK(
|
|
313
|
+
writer.StartTrace(trace_opt, std::move(block_cache_trace_writer)));
|
|
285
314
|
ASSERT_EQ(1, writer.NextGetId());
|
|
286
315
|
}
|
|
287
316
|
}
|
|
@@ -289,19 +318,26 @@ TEST_F(BlockCacheTracerTest, NextGetId) {
|
|
|
289
318
|
TEST_F(BlockCacheTracerTest, MixedBlocks) {
|
|
290
319
|
{
|
|
291
320
|
// Generate a trace file containing a mix of blocks.
|
|
292
|
-
|
|
321
|
+
BlockCacheTraceWriterOptions trace_writer_opt;
|
|
293
322
|
std::unique_ptr<TraceWriter> trace_writer;
|
|
294
323
|
ASSERT_OK(NewFileTraceWriter(env_, env_options_, trace_file_path_,
|
|
295
324
|
&trace_writer));
|
|
296
|
-
BlockCacheTraceWriter
|
|
297
|
-
|
|
325
|
+
std::unique_ptr<BlockCacheTraceWriter> block_cache_trace_writer =
|
|
326
|
+
NewBlockCacheTraceWriter(env_->GetSystemClock().get(), trace_writer_opt,
|
|
327
|
+
std::move(trace_writer));
|
|
328
|
+
ASSERT_NE(block_cache_trace_writer, nullptr);
|
|
329
|
+
ASSERT_OK(block_cache_trace_writer->WriteHeader());
|
|
298
330
|
// Write blocks of different types.
|
|
299
|
-
WriteBlockAccess(
|
|
300
|
-
10);
|
|
301
|
-
WriteBlockAccess(
|
|
302
|
-
|
|
303
|
-
WriteBlockAccess(
|
|
304
|
-
|
|
331
|
+
WriteBlockAccess(block_cache_trace_writer.get(), 0,
|
|
332
|
+
TraceType::kBlockTraceUncompressionDictBlock, 10);
|
|
333
|
+
WriteBlockAccess(block_cache_trace_writer.get(), 10,
|
|
334
|
+
TraceType::kBlockTraceDataBlock, 10);
|
|
335
|
+
WriteBlockAccess(block_cache_trace_writer.get(), 20,
|
|
336
|
+
TraceType::kBlockTraceFilterBlock, 10);
|
|
337
|
+
WriteBlockAccess(block_cache_trace_writer.get(), 30,
|
|
338
|
+
TraceType::kBlockTraceIndexBlock, 10);
|
|
339
|
+
WriteBlockAccess(block_cache_trace_writer.get(), 40,
|
|
340
|
+
TraceType::kBlockTraceRangeDeletionBlock, 10);
|
|
305
341
|
ASSERT_OK(env_->FileExists(trace_file_path_));
|
|
306
342
|
}
|
|
307
343
|
|
|
@@ -332,7 +368,7 @@ TEST_F(BlockCacheTracerTest, HumanReadableTrace) {
|
|
|
332
368
|
record.get_id = 1;
|
|
333
369
|
record.referenced_key = "";
|
|
334
370
|
record.caller = TableReaderCaller::kUserGet;
|
|
335
|
-
record.get_from_user_specified_snapshot =
|
|
371
|
+
record.get_from_user_specified_snapshot = true;
|
|
336
372
|
record.referenced_data_size = kReferencedDataSize;
|
|
337
373
|
PutFixed32(&record.referenced_key, 111);
|
|
338
374
|
PutLengthPrefixedSlice(&record.referenced_key, "get_key");
|
|
@@ -359,11 +395,11 @@ TEST_F(BlockCacheTracerTest, HumanReadableTrace) {
|
|
|
359
395
|
ASSERT_EQ(TableReaderCaller::kUserGet, read_record.caller);
|
|
360
396
|
ASSERT_EQ(kLevel, read_record.level);
|
|
361
397
|
ASSERT_EQ(kSSTFDNumber, read_record.sst_fd_number);
|
|
362
|
-
|
|
363
|
-
|
|
398
|
+
ASSERT_FALSE(read_record.is_cache_hit);
|
|
399
|
+
ASSERT_FALSE(read_record.no_insert);
|
|
364
400
|
ASSERT_EQ(1, read_record.get_id);
|
|
365
|
-
|
|
366
|
-
|
|
401
|
+
ASSERT_TRUE(read_record.get_from_user_specified_snapshot);
|
|
402
|
+
ASSERT_TRUE(read_record.referenced_key_exist_in_block);
|
|
367
403
|
ASSERT_EQ(kNumKeysInBlock, read_record.num_keys_in_block);
|
|
368
404
|
ASSERT_EQ(kReferencedDataSize, read_record.referenced_data_size);
|
|
369
405
|
ASSERT_EQ(record.block_key.size(), read_record.block_key.size());
|
|
@@ -15,65 +15,45 @@ namespace ROCKSDB_NAMESPACE {
|
|
|
15
15
|
|
|
16
16
|
// Wrapper of user comparator, with auto increment to
|
|
17
17
|
// perf_context.user_key_comparison_count.
|
|
18
|
-
class UserComparatorWrapper
|
|
18
|
+
class UserComparatorWrapper {
|
|
19
19
|
public:
|
|
20
20
|
// `UserComparatorWrapper`s constructed with the default constructor are not
|
|
21
21
|
// usable and will segfault on any attempt to use them for comparisons.
|
|
22
22
|
UserComparatorWrapper() : user_comparator_(nullptr) {}
|
|
23
23
|
|
|
24
24
|
explicit UserComparatorWrapper(const Comparator* const user_cmp)
|
|
25
|
-
:
|
|
25
|
+
: user_comparator_(user_cmp) {}
|
|
26
26
|
|
|
27
27
|
~UserComparatorWrapper() = default;
|
|
28
28
|
|
|
29
29
|
const Comparator* user_comparator() const { return user_comparator_; }
|
|
30
30
|
|
|
31
|
-
int Compare(const Slice& a, const Slice& b) const
|
|
31
|
+
int Compare(const Slice& a, const Slice& b) const {
|
|
32
32
|
PERF_COUNTER_ADD(user_key_comparison_count, 1);
|
|
33
33
|
return user_comparator_->Compare(a, b);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
bool Equal(const Slice& a, const Slice& b) const
|
|
36
|
+
bool Equal(const Slice& a, const Slice& b) const {
|
|
37
37
|
PERF_COUNTER_ADD(user_key_comparison_count, 1);
|
|
38
38
|
return user_comparator_->Equal(a, b);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
void FindShortestSeparator(std::string* start,
|
|
44
|
-
const Slice& limit) const override {
|
|
45
|
-
return user_comparator_->FindShortestSeparator(start, limit);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
void FindShortSuccessor(std::string* key) const override {
|
|
49
|
-
return user_comparator_->FindShortSuccessor(key);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const Comparator* GetRootComparator() const override {
|
|
53
|
-
return user_comparator_->GetRootComparator();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
bool IsSameLengthImmediateSuccessor(const Slice& s,
|
|
57
|
-
const Slice& t) const override {
|
|
58
|
-
return user_comparator_->IsSameLengthImmediateSuccessor(s, t);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
bool CanKeysWithDifferentByteContentsBeEqual() const override {
|
|
62
|
-
return user_comparator_->CanKeysWithDifferentByteContentsBeEqual();
|
|
41
|
+
int CompareTimestamp(const Slice& ts1, const Slice& ts2) const {
|
|
42
|
+
return user_comparator_->CompareTimestamp(ts1, ts2);
|
|
63
43
|
}
|
|
64
44
|
|
|
65
|
-
int
|
|
66
|
-
|
|
45
|
+
int CompareWithoutTimestamp(const Slice& a, const Slice& b) const {
|
|
46
|
+
PERF_COUNTER_ADD(user_key_comparison_count, 1);
|
|
47
|
+
return user_comparator_->CompareWithoutTimestamp(a, b);
|
|
67
48
|
}
|
|
68
49
|
|
|
69
|
-
using Comparator::CompareWithoutTimestamp;
|
|
70
50
|
int CompareWithoutTimestamp(const Slice& a, bool a_has_ts, const Slice& b,
|
|
71
|
-
bool b_has_ts) const
|
|
51
|
+
bool b_has_ts) const {
|
|
72
52
|
PERF_COUNTER_ADD(user_key_comparison_count, 1);
|
|
73
53
|
return user_comparator_->CompareWithoutTimestamp(a, a_has_ts, b, b_has_ts);
|
|
74
54
|
}
|
|
75
55
|
|
|
76
|
-
bool EqualWithoutTimestamp(const Slice& a, const Slice& b) const
|
|
56
|
+
bool EqualWithoutTimestamp(const Slice& a, const Slice& b) const {
|
|
77
57
|
return user_comparator_->EqualWithoutTimestamp(a, b);
|
|
78
58
|
}
|
|
79
59
|
|
|
@@ -41,7 +41,7 @@ void CacheSimulator::Access(const BlockCacheTraceRecord& access) {
|
|
|
41
41
|
const bool is_user_access =
|
|
42
42
|
BlockCacheTraceHelper::IsUserAccess(access.caller);
|
|
43
43
|
bool is_cache_miss = true;
|
|
44
|
-
if (ghost_cache_ && access.no_insert
|
|
44
|
+
if (ghost_cache_ && !access.no_insert) {
|
|
45
45
|
admit = ghost_cache_->Admit(access.block_key);
|
|
46
46
|
}
|
|
47
47
|
auto handle = sim_cache_->Lookup(access.block_key);
|
|
@@ -49,7 +49,7 @@ void CacheSimulator::Access(const BlockCacheTraceRecord& access) {
|
|
|
49
49
|
sim_cache_->Release(handle);
|
|
50
50
|
is_cache_miss = false;
|
|
51
51
|
} else {
|
|
52
|
-
if (access.no_insert
|
|
52
|
+
if (!access.no_insert && admit && access.block_size > 0) {
|
|
53
53
|
// Ignore errors on insert
|
|
54
54
|
auto s = sim_cache_->Insert(access.block_key, /*value=*/nullptr,
|
|
55
55
|
access.block_size,
|