MCPcopy Create free account
hub / github.com/ElementsProject/elements / DoReads

Method DoReads

src/leveldb/db/autocompact_test.cc:59–104  ·  view source on GitHub ↗

Read through the first n keys repeatedly and check that they get compacted (verified by checking the size of the key space).

Source from the content-addressed store, hash-verified

57// Read through the first n keys repeatedly and check that they get
58// compacted (verified by checking the size of the key space).
59void AutoCompactTest::DoReads(int n) {
60 std::string value(kValueSize, 'x');
61 DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
62
63 // Fill database
64 for (int i = 0; i < kCount; i++) {
65 ASSERT_OK(db_->Put(WriteOptions(), Key(i), value));
66 }
67 ASSERT_OK(dbi->TEST_CompactMemTable());
68
69 // Delete everything
70 for (int i = 0; i < kCount; i++) {
71 ASSERT_OK(db_->Delete(WriteOptions(), Key(i)));
72 }
73 ASSERT_OK(dbi->TEST_CompactMemTable());
74
75 // Get initial measurement of the space we will be reading.
76 const int64_t initial_size = Size(Key(0), Key(n));
77 const int64_t initial_other_size = Size(Key(n), Key(kCount));
78
79 // Read until size drops significantly.
80 std::string limit_key = Key(n);
81 for (int read = 0; true; read++) {
82 ASSERT_LT(read, 100) << "Taking too long to compact";
83 Iterator* iter = db_->NewIterator(ReadOptions());
84 for (iter->SeekToFirst();
85 iter->Valid() && iter->key().ToString() < limit_key; iter->Next()) {
86 // Drop data
87 }
88 delete iter;
89 // Wait a little bit to allow any triggered compactions to complete.
90 Env::Default()->SleepForMicroseconds(1000000);
91 uint64_t size = Size(Key(0), Key(n));
92 fprintf(stderr, "iter %3d => %7.3f MB [other %7.3f MB]\n", read + 1,
93 size / 1048576.0, Size(Key(n), Key(kCount)) / 1048576.0);
94 if (size <= initial_size / 10) {
95 break;
96 }
97 }
98
99 // Verify that the size of the key space not touched by the reads
100 // is pretty much unchanged.
101 const int64_t final_other_size = Size(Key(n), Key(kCount));
102 ASSERT_LE(final_other_size, initial_other_size + 1048576);
103 ASSERT_GE(final_other_size, initial_other_size / 5 - 1048576);
104}
105
106TEST(AutoCompactTest, ReadAll) { DoReads(kCount); }
107

Callers

nothing calls this directly

Calls 13

WriteOptionsClass · 0.85
TEST_CompactMemTableMethod · 0.80
KeyFunction · 0.70
ReadOptionsClass · 0.50
PutMethod · 0.45
DeleteMethod · 0.45
NewIteratorMethod · 0.45
SeekToFirstMethod · 0.45
ValidMethod · 0.45
ToStringMethod · 0.45
keyMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected