Branch data Line data Source code
1 : : // Copyright (c) The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <dbwrapper.h>
6 : : #include <compat/byteswap.h>
7 : : #include <random.h>
8 : : #include <sync.h>
9 : : #include <test/fuzz/FuzzedDataProvider.h>
10 : : #include <test/fuzz/fuzz.h>
11 : : #include <test/fuzz/util.h>
12 : : #include <test/util/random.h>
13 : : #include <test/util/setup_common.h>
14 : : #include <util/byte_units.h>
15 : : #include <util/check.h>
16 : : #include <util/threadpool.h>
17 : :
18 : : #include <leveldb/env.h>
19 : : #include <leveldb/helpers/memenv/memenv.h>
20 : :
21 : : #include <algorithm>
22 : : #include <cstdint>
23 : : #include <deque>
24 : : #include <functional>
25 : : #include <future>
26 : : #include <latch>
27 : : #include <map>
28 : : #include <memory>
29 : : #include <numeric>
30 : : #include <optional>
31 : : #include <set>
32 : : #include <span>
33 : : #include <string>
34 : : #include <tuple>
35 : : #include <vector>
36 : :
37 : : namespace {
38 : :
39 : : /**
40 : : * A leveldb::Env that wraps a memenv and captures scheduled background
41 : : * work (compaction) instead of dispatching to a real thread. The fuzz
42 : : * harness calls RunOne() or DrainWork() at fuzzer-chosen points to
43 : : * execute it, giving deterministic control over when compaction
44 : : * interleaves with foreground operations.
45 : : *
46 : : * Deadlock prevention: LevelDB's MakeRoomForWrite blocks on a condition
47 : : * variable when the previous immutable memtable is still awaiting compaction,
48 : : * or when the L0 file count hits kL0_StopWritesTrigger. Since both conditions
49 : : * can only be resolved by the (deferred) background work, the harness drains
50 : : * all pending work before every write to avoid a single-threaded deadlock.
51 : : * Callers must also DrainWork() before destroying the CDBWrapper, since the
52 : : * leveldb destructor waits for any pending background work to complete.
53 : : *
54 : : * The same reasoning rules out exercising DBOptions::force_compact under
55 : : * this env, because CompactRange(nullptr, nullptr) blocks waiting for
56 : : * background work that is queued on the (blocked) foreground thread. The
57 : : * sibling dbwrapper_threaded target covers that path.
58 : : */
59 : : class DeterministicEnv final : public leveldb::EnvWrapper
60 : : {
61 : : using WorkFunction = void (*)(void*);
62 : :
63 : : struct Work {
64 : : WorkFunction function;
65 : : void* arg;
66 : : };
67 : :
68 : : Mutex m_mutex;
69 : : std::deque<Work> m_queue GUARDED_BY(m_mutex);
70 : :
71 : : public:
72 [ + - ]: 1639 : explicit DeterministicEnv(leveldb::Env* base) : EnvWrapper(base) {}
73 : :
74 : 27284 : void Schedule(WorkFunction function, void* arg) override EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
75 : : {
76 : 27284 : LOCK(m_mutex);
77 [ + - + - ]: 27284 : m_queue.push_back({function, arg});
78 : 27284 : }
79 : :
80 : : /** Execute one pending background task. The task may schedule a
81 : : * successor which is left pending for a later call. */
82 : 211656 : bool RunOne() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
83 : : {
84 : 211656 : Work work;
85 : 211656 : {
86 : 211656 : LOCK(m_mutex);
87 [ + + + - ]: 211656 : if (m_queue.empty()) return false;
88 : 27284 : work = m_queue.front();
89 [ + - ]: 27284 : m_queue.pop_front();
90 : 184372 : }
91 : 27284 : work.function(work.arg);
92 : 27284 : return true;
93 : : }
94 : :
95 : : /** Execute pending background tasks until none remain. */
96 : 203366 : void DrainWork() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) { while (RunOne()) {} }
[ + - + +
+ - + + +
- - + +
+ ]
97 : : };
98 : :
99 : : constexpr size_t MAX_VALUE_LEN{4096};
100 : : constexpr uint8_t MAX_VALUE_MULTIPLIER{8};
101 : : constexpr size_t WRITE_BATCH_HEADER{12}; // See kHeader in db/write_batch.cc
102 : :
103 : : /** Mirror of CDBWrapper::OBFUSCATION_KEY, the fixed key under which leveldb
104 : : * stores the obfuscation metadata entry when obfuscation is enabled. */
105 : : const std::string OBFUSCATION_KEY{"\000obfuscate_key", 14};
106 : :
107 : : /** Generate a deterministic value from key and size. The fuzz input picks
108 : : * a 16-bit length (up to MAX_VALUE_LEN) and an 8-bit multiplier so that a
109 : : * small amount of fuzz input can produce a wide range of value sizes. */
110 : 3588496 : std::vector<uint8_t> MakeValue(uint16_t key, uint32_t size)
111 : : {
112 : 3588496 : std::vector<uint8_t> v(size);
113 : 3588496 : std::iota(v.begin(), v.end(), static_cast<uint8_t>(key ^ (key >> 8)));
114 : 3588496 : return v;
115 : : }
116 : :
117 : : /** Equivalent to leveldb::BytewiseComparator() on 2-byte little-endian
118 : : * serialized uint16_t keys, while keeping the oracle keyed by uint16_t. */
119 : : struct LevelDBBytewiseU16Cmp {
120 : 15871364 : bool operator()(uint16_t a, uint16_t b) const { return internal_bswap_16(a) < internal_bswap_16(b); }
[ + - - +
- - - - +
+ + + + -
+ - + - -
- - - + +
- - - - -
- - - - -
- - - - +
+ + + + +
+ + ]
121 : : };
122 : :
123 : : /** key → value-size map ordered by LevelDB's bytewise comparator. */
124 : : using Oracle = std::map<uint16_t, uint32_t, LevelDBBytewiseU16Cmp>;
125 : :
126 : : struct FailUnserialize {
127 : : template <typename Stream>
128 [ + - ]: 5638 : void Unserialize(Stream&) { throw std::ios_base::failure{"always fail"}; }
129 : : };
130 : :
131 : 2587782 : uint16_t ConsumeKey(FuzzedDataProvider& provider) { return provider.ConsumeIntegral<uint16_t>(); }
132 : 1945611 : uint32_t ConsumeValueSize(FuzzedDataProvider& provider)
133 : : {
134 : 1945611 : const uint16_t len{provider.ConsumeIntegralInRange<uint16_t>(0, MAX_VALUE_LEN)};
135 : 1945611 : const uint8_t multiplier{provider.ConsumeIntegralInRange<uint8_t>(1, MAX_VALUE_MULTIPLIER)};
136 : 1945611 : return static_cast<uint32_t>(len) * multiplier;
137 : : }
138 : :
139 : : /** Verify that the DB iterator matches the oracle, handling the obfuscation
140 : : * metadata entry (stored under a non-uint16_t key) when obfuscation is on. */
141 : 173828 : void VerifyIterator(CDBWrapper& dbw, const Oracle& oracle,
142 : : bool obfuscate, std::optional<uint16_t> seek_key = std::nullopt)
143 : : {
144 [ + + ]: 173828 : const std::unique_ptr<CDBIterator> it{dbw.NewIterator()};
145 [ + + ]: 173828 : auto oracle_it{seek_key ? oracle.lower_bound(*seek_key) : oracle.begin()};
146 [ + + ]: 173828 : if (seek_key) {
147 [ + - ]: 25614 : it->Seek(*seek_key);
148 : : } else {
149 [ + - ]: 148214 : it->SeekToFirst();
150 : : }
151 [ + - + - : 1577244 : for (; it->Valid(); it->Next()) {
+ + ]
152 : 1403416 : uint16_t db_key;
153 [ + - - + ]: 1403416 : assert(it->GetKey(db_key));
154 [ + + + + ]: 1403416 : if (oracle_it != oracle.end() && db_key == oracle_it->first) {
155 : 1296626 : std::vector<uint8_t> db_value;
156 [ + - - + ]: 1296626 : assert(it->GetValue(db_value));
157 [ + - - + ]: 1296626 : assert(db_value == MakeValue(db_key, oracle_it->second));
158 : 1296626 : ++oracle_it;
159 : 1296626 : } else {
160 [ - + ]: 106790 : assert(obfuscate);
161 [ + - ]: 106790 : std::string key_str;
162 [ + - - + ]: 106790 : assert(it->GetKey(key_str));
163 [ - + ]: 106790 : assert(key_str == OBFUSCATION_KEY);
164 : 106790 : }
165 : : }
166 [ - + ]: 173828 : assert(oracle_it == oracle.end());
167 : 173828 : }
168 : :
169 : : /** Maximum number of concurrent reader threads in dbwrapper_concurrent_reads. */
170 : : constexpr size_t MAX_READ_WORKERS{8};
171 : :
172 : : /** Maximum number of queries each worker executes in dbwrapper_concurrent_reads. */
173 : : constexpr size_t MAX_READ_QUERIES_PER_WORKER{128};
174 : :
175 : : ThreadPool g_read_pool{"dbfuzz"};
176 : :
177 : 855 : void StartReadPoolIfNeeded()
178 : : {
179 [ + + ]: 855 : if (!g_read_pool.WorkersCount()) g_read_pool.Start(MAX_READ_WORKERS);
180 : 855 : }
181 : :
182 : : /** Build randomized DBParams from the fuzz input, shared by all targets. */
183 : 145469 : DBParams ConsumeDBParams(FuzzedDataProvider& provider, leveldb::Env* testing_env,
184 : : bool obfuscate, DBOptions options = {})
185 : : {
186 : 290938 : return DBParams{
187 : : .path = "dbwrapper_fuzz",
188 : 145469 : .cache_bytes = provider.ConsumeIntegralInRange<size_t>(64 << 10, 1_MiB),
189 : : .obfuscate = obfuscate,
190 : 145469 : .bloom_filter = provider.ConsumeBool(),
191 : : .options = options,
192 : : .testing_env = testing_env,
193 : 145469 : .max_file_size = provider.ConsumeBool()
194 [ + + ]: 145469 : ? DBWRAPPER_MAX_FILE_SIZE
195 : 9175 : : provider.ConsumeIntegralInRange<size_t>(1_MiB, 4_MiB),
196 : 145469 : };
197 : : }
198 : :
199 : : template <typename DrainWorkFn, typename RunOneFn>
200 : 1697 : void TestDbWrapper(FuzzedDataProvider& provider,
201 : : leveldb::Env* testing_env,
202 : : DrainWorkFn drain_work,
203 : : RunOneFn run_one,
204 : : bool allow_force_compact)
205 : : {
206 : 1697 : SeedRandomStateForTest(SeedRand::ZEROS);
207 : :
208 : 1697 : const bool obfuscate{provider.ConsumeBool()};
209 : :
210 : 146311 : const auto make_db{[&](DBOptions options = {}) {
211 [ + - + - ]: 289228 : return std::make_unique<CDBWrapper>(ConsumeDBParams(provider, testing_env, obfuscate, options));
212 : : }};
213 : 1697 : std::unique_ptr<CDBWrapper> dbw{make_db()};
214 : :
215 : : // Oracle: key → value size. Content is reconstructed via MakeValue().
216 : 1697 : Oracle oracle;
217 : :
218 [ + + + + ]: 489755 : LIMITED_WHILE (provider.ConsumeBool(), 1'000) {
219 [ + - ][ + - ]: 488058 : CallOneOf(
220 : : provider,
221 : : // --- Mutations ---
222 : 92078 : [&] {
223 : 46039 : const auto key{ConsumeKey(provider)};
224 : 46039 : const auto size{ConsumeValueSize(provider)};
225 : 21704 : drain_work();
226 [ + - + - ]: 46039 : dbw->Write(key, MakeValue(key, size), /*fSync=*/provider.ConsumeBool());
227 : 46039 : oracle[key] = size;
228 : : },
229 : 294554 : [&] {
230 : 147277 : const auto key{ConsumeKey(provider)};
231 : 61574 : drain_work();
232 : 147277 : dbw->Erase(key, /*fSync=*/provider.ConsumeBool());
233 : 147277 : oracle.erase(key);
234 : : },
235 : 26501 : [&] {
236 [ + - + - ]: 26501 : CDBBatch batch{*dbw};
237 [ + - + - ]: 26501 : std::map<uint16_t, uint32_t> batch_writes;
238 : 26501 : std::set<uint16_t> batch_erases;
239 : 67668 : const auto fill{[&] {
240 [ + + + + : 361256 : LIMITED_WHILE (provider.ConsumeBool(), 20) {
+ + + + ]
241 : 320089 : const auto key{ConsumeKey(provider)};
242 [ + + + + ]: 320089 : if (provider.ConsumeBool()) {
243 : 193875 : const auto size{ConsumeValueSize(provider)};
244 [ + - + - ]: 193875 : batch.Write(key, MakeValue(key, size));
245 : 193875 : batch_writes[key] = size;
246 : 193875 : batch_erases.erase(key);
247 : : } else {
248 : 126214 : batch.Erase(key);
249 : 126214 : batch_erases.insert(key);
250 : 126214 : batch_writes.erase(key);
251 : : }
252 : : }
253 : : }};
254 [ + - + - ]: 26501 : fill();
255 [ + + + + ]: 26501 : if (provider.ConsumeBool()) {
256 [ + - - + : 14666 : assert(batch.ApproximateSize() >= WRITE_BATCH_HEADER);
+ - - + ]
257 [ + - + - ]: 14666 : batch.Clear();
258 [ + - - + : 14666 : assert(batch.ApproximateSize() == WRITE_BATCH_HEADER);
+ - - + ]
259 : 14666 : batch_writes.clear();
260 : 14666 : batch_erases.clear();
261 [ + - + - ]: 14666 : fill();
262 : : }
263 [ + - ]: 11264 : drain_work();
264 [ + - + - ]: 26501 : dbw->WriteBatch(batch, /*fSync=*/provider.ConsumeBool());
265 [ + - + + : 122335 : for (const auto& [k, v] : batch_writes) oracle[k] = v;
+ - + + ]
266 [ + + + + ]: 64374 : for (const auto& k : batch_erases) oracle.erase(k);
267 : 26501 : },
268 : 285834 : [&] {
269 : 75316 : drain_work();
270 [ + - + - ]: 142917 : dbw.reset();
271 : 142917 : DBOptions options{};
272 [ + - + + : 142917 : if (allow_force_compact && provider.ConsumeBool()) {
- + - - ]
273 : 46886 : options.force_compact = true;
274 : : }
275 : 142917 : dbw = make_db(options);
276 : 142917 : VerifyIterator(*dbw, oracle, obfuscate);
277 : : },
278 : : // --- Reads ---
279 : 25280 : [&] {
280 : 12640 : const auto key{ConsumeKey(provider)};
281 : 12640 : std::vector<uint8_t> value;
282 [ + - + - ]: 12640 : const bool found{dbw->Read(key, value)};
283 [ + + + + ]: 12640 : if (const auto it{oracle.find(key)}; it != oracle.end()) {
284 : 13056 : assert(found && value == MakeValue(key, it->second));
[ + - + -
- + + - +
- - + ]
285 : : } else {
286 [ - + - + ]: 6112 : assert(!found);
287 : : }
288 : 12640 : },
289 : 57556 : [&] {
290 : 28778 : const auto key{ConsumeKey(provider)};
291 [ - + - + ]: 28778 : assert(dbw->Exists(key) == oracle.contains(key));
292 : : },
293 : 8524 : [&] {
294 : 4262 : uint16_t key{};
295 [ + + + + : 4262 : if (!oracle.empty() && provider.ConsumeBool()) {
+ + + + ]
296 : 2787 : auto it{oracle.begin()};
297 : 2787 : std::advance(it, provider.ConsumeIntegralInRange<size_t>(0, oracle.size() - 1));
298 : 2787 : key = it->first;
299 : : } else {
300 : 1475 : key = ConsumeKey(provider);
301 : : }
302 : : FailUnserialize wrong_type;
303 [ - + - + ]: 4262 : assert(!dbw->Read(key, wrong_type));
304 : : },
305 : 58428 : [&] {
306 : 58428 : const auto seek_key{provider.ConsumeBool()
307 [ + + + + ]: 29214 : ? std::optional<uint16_t>{ConsumeKey(provider)}
308 : : : std::nullopt};
309 : 29214 : VerifyIterator(*dbw, oracle, obfuscate, seek_key);
310 : : },
311 : : // --- Stats ---
312 : 11848 : [&] {
313 : 11597 : assert(dbw->IsEmpty() == (oracle.empty() && !obfuscate));
[ + + + +
- + + + +
+ - + ]
314 : : },
315 : 16540 : [&] {
316 : 8270 : const auto [k1, k2]{std::minmax({ConsumeKey(provider), ConsumeKey(provider)}, LevelDBBytewiseU16Cmp{})};
317 : 8270 : const size_t estimate_size{dbw->EstimateSize(k1, k2)};
318 [ + + - + : 8270 : if (k1 == k2) assert(estimate_size == 0);
+ + - + ]
319 : : },
320 : 16662 : [&] {
321 : 16662 : (void)dbw->DynamicMemoryUsage();
322 : : },
323 : : // --- Compaction control (no-op when run_one is no-op) ---
324 : 7779 : [&] {
325 : 7779 : run_one();
326 : : });
327 : : }
328 : :
329 [ + - ][ + - ]: 1697 : VerifyIterator(*dbw, oracle, obfuscate);
330 [ + - ]: 1697 : drain_work();
331 : 1697 : }
332 : :
333 : : } // namespace
334 : :
335 [ + - ][ + - : 1263 : FUZZ_TARGET(dbwrapper, .init = [] { static auto setup{MakeNoLogFileContext<>()}; })
+ - + - ]
336 : : {
337 : 784 : FuzzedDataProvider provider{buffer.data(), buffer.size()};
338 : :
339 [ + - ]: 784 : const auto memenv{std::unique_ptr<leveldb::Env>{leveldb::NewMemEnv(leveldb::Env::Default())}};
340 [ + - ]: 784 : DeterministicEnv det_env{memenv.get()};
341 [ + - ]: 784 : TestDbWrapper(
342 : : provider, &det_env,
343 : 170642 : [&] { det_env.DrainWork(); },
344 : 7779 : [&] { return det_env.RunOne(); },
345 : : /*allow_force_compact=*/false);
346 : 784 : }
347 : :
348 [ + - ][ + - : 1391 : FUZZ_TARGET(dbwrapper_threaded, .init = [] { static auto setup{MakeNoLogFileContext<>()}; })
+ - + - ]
349 : : {
350 : 913 : FuzzedDataProvider provider{buffer.data(), buffer.size()};
351 : :
352 [ + - ]: 913 : const auto memenv{std::unique_ptr<leveldb::Env>{leveldb::NewMemEnv(leveldb::Env::Default())}};
353 [ + - ]: 913 : TestDbWrapper(
354 : : provider, memenv.get(),
355 : : /*drain_work=*/[] {},
356 : : /*run_one=*/[] { return false; },
357 : : /*allow_force_compact=*/true);
358 : 913 : }
359 : :
360 [ + - ][ + - : 1333 : FUZZ_TARGET(dbwrapper_concurrent_reads, .init = [] { static auto setup{MakeNoLogFileContext<>()}; })
+ - + - ]
361 : : {
362 : 855 : StartReadPoolIfNeeded();
363 : 855 : SeedRandomStateForTest(SeedRand::ZEROS);
364 : :
365 : 855 : FuzzedDataProvider provider{buffer.data(), buffer.size()};
366 : :
367 [ + - ]: 855 : const auto memenv{std::unique_ptr<leveldb::Env>{leveldb::NewMemEnv(leveldb::Env::Default())}};
368 [ + - ]: 855 : DeterministicEnv det_env{memenv.get()};
369 : :
370 [ + - + - ]: 855 : CDBWrapper db{ConsumeDBParams(provider, &det_env, /*obfuscate=*/provider.ConsumeBool())};
371 : :
372 : : // Seed the DB. Drain work after small batches so we don't deadlock on a
373 : : // scheduled compaction.
374 : 855 : const size_t num_entries{provider.ConsumeIntegralInRange<size_t>(100, 5'000)};
375 : 855 : std::vector<uint16_t> keys;
376 [ + - ]: 855 : keys.reserve(num_entries);
377 : 855 : Oracle oracle;
378 : 855 : constexpr size_t SEED_BATCH_SIZE{400};
379 [ + + ]: 5649 : for (size_t start{0}; start < num_entries; start += SEED_BATCH_SIZE) {
380 [ + - ]: 4794 : CDBBatch batch{db};
381 [ + + ]: 4794 : const size_t end{std::min(start + SEED_BATCH_SIZE, num_entries)};
382 [ + + ]: 1710491 : for (size_t i{start}; i < end; ++i) {
383 : 1705697 : const auto k{ConsumeKey(provider)};
384 : 1705697 : const auto size{ConsumeValueSize(provider)};
385 [ + - + - ]: 1705697 : batch.Write(k, MakeValue(k, size));
386 [ + - ]: 1705697 : keys.push_back(k);
387 [ + - ]: 1705697 : oracle[k] = size;
388 : : }
389 : : det_env.DrainWork();
390 [ + - ]: 4794 : db.WriteBatch(batch, /*fSync=*/true);
391 : 4794 : }
392 : :
393 [ + + + - : 1366 : while (provider.ConsumeBool() && det_env.RunOne()) {}
+ + + + ]
394 : :
395 : : // Build query list from seeded and random keys.
396 : 855 : const size_t num_queries{provider.ConsumeIntegralInRange<size_t>(1, 2'000)};
397 : 855 : enum class ReadOp { Read, Exists, IteratorSeek };
398 : 855 : std::vector<std::tuple<ReadOp, uint16_t>> queries;
399 [ + - ]: 855 : queries.reserve(num_queries);
400 [ + + ]: 333671 : for (size_t i{0}; i < num_queries; ++i) {
401 : 332816 : const auto op{provider.PickValueInArray({ReadOp::Read, ReadOp::Exists, ReadOp::IteratorSeek})};
402 : 332816 : const uint16_t key{provider.ConsumeBool()
403 [ + + ]: 381999 : ? keys[provider.ConsumeIntegralInRange<size_t>(0, keys.size() - 1)]
404 : 283633 : : ConsumeKey(provider)};
405 [ + - ]: 332816 : queries.emplace_back(op, key);
406 : : }
407 : :
408 : :
409 : : // Workers + main thread synchronize on the latch so all reads start together.
410 : 855 : std::latch start_latch{static_cast<ptrdiff_t>(MAX_READ_WORKERS + 1)};
411 [ + - ]: 855 : std::vector<std::function<void()>> tasks(MAX_READ_WORKERS);
412 : 855 : FastRandomContext rng{ConsumeUInt256(provider)};
413 [ + - ]: 7695 : std::ranges::generate(tasks, [&] {
414 : 6840 : return [&, seed = rng.rand256()] {
415 : 6840 : FastRandomContext thread_rng{seed};
416 [ - + + - ]: 6840 : std::vector<size_t> order(queries.size());
417 : 6840 : std::iota(order.begin(), order.end(), size_t{0});
418 : 6840 : std::ranges::shuffle(order, thread_rng);
419 [ - + + + ]: 6840 : const size_t queries_to_run{std::min(queries.size(), MAX_READ_QUERIES_PER_WORKER)};
420 : 6840 : std::vector<uint8_t> v;
421 [ + + ]: 6840 : std::string key_str;
422 [ + + ]: 6840 : start_latch.arrive_and_wait();
423 [ + - - + ]: 6840 : const std::unique_ptr<CDBIterator> it{db.NewIterator()};
424 : : // Every read must agree with the oracle, the source of truth.
425 [ - + + + ]: 405712 : for (const auto i : std::span{order}.first(queries_to_run)) {
426 [ + + + - ]: 398872 : const auto& [op, key] = queries[i];
427 [ + + + - ]: 398872 : switch (op) {
428 : 310418 : case ReadOp::Read:
429 [ + + ]: 310418 : if (const auto oit{oracle.find(key)}; oit != oracle.end()) {
430 [ + - + - : 562932 : assert(db.Read(key, v) && v == MakeValue(key, oit->second));
+ - - + ]
431 : : } else {
432 [ + - - + ]: 28952 : assert(!db.Read(key, v));
433 : : }
434 : : break;
435 : 28944 : case ReadOp::Exists:
436 [ + - - + ]: 28944 : assert(db.Exists(key) == oracle.contains(key));
437 : : break;
438 : 59510 : case ReadOp::IteratorSeek:
439 [ + - ]: 59510 : it->Seek(key);
440 : : // Skip the obfuscation metadata entry (a non-uint16_t key) if we land
441 : : // on it, so the result matches the oracle, which only tracks user keys.
442 : 59510 : if (it->Valid() && it->GetKey(key_str) && key_str == OBFUSCATION_KEY) it->Next();
[ + - + +
+ - + + +
+ + - ]
443 [ + + ]: 59510 : if (const auto oit{oracle.lower_bound(key)}; oit != oracle.end()) {
444 [ + - - + ]: 58265 : assert(it->Valid());
445 : 58265 : uint16_t actual_key;
446 [ + - + - : 58265 : assert(it->GetKey(actual_key) && actual_key == oit->first);
- + ]
447 [ + - + - : 116530 : assert(it->GetValue(v) && v == MakeValue(actual_key, oit->second));
+ - - + ]
448 : : } else {
449 [ + - - + ]: 1245 : assert(!it->Valid());
450 : : }
451 : : break;
452 : : }
453 : : }
454 : 13680 : };
455 : : });
456 [ + - ]: 855 : auto futures{*Assert(g_read_pool.Submit(std::move(tasks)))};
457 : :
458 : : // Release the workers and immediately run the queued compaction on this
459 : : // thread, so compaction races against the concurrent reads.
460 [ + + ]: 855 : start_latch.arrive_and_wait();
461 : 855 : det_env.DrainWork();
462 : :
463 [ + - + + ]: 7695 : for (auto& fut : futures) fut.get();
464 : : det_env.DrainWork();
465 : 855 : }
|