MCPcopy Create free account
hub / github.com/bytedance/bolt / TEST_F

Function TEST_F

bolt/common/caching/tests/SsdFileTest.cpp:254–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252};
253
254TEST_F(SsdFileTest, writeAndRead) {
255 constexpr int64_t kSsdSize = 16 * SsdFile::kRegionSize;
256 std::vector<TestEntry> allEntries;
257 initializeCache(128 * kMB, kSsdSize);
258 FLAGS_bolt_ssd_verify_write = true;
259 for (auto startOffset = 0; startOffset <= kSsdSize - SsdFile::kRegionSize;
260 startOffset += SsdFile::kRegionSize) {
261 auto pins =
262 makePins(fileName_.id(), startOffset, 4096, 2048 * 1025, 62 * kMB);
263 ssdFile_->write(pins);
264 for (auto& pin : pins) {
265 EXPECT_EQ(ssdFile_.get(), pin.entry()->ssdFile());
266 allEntries.emplace_back(
267 pin.entry()->key(), pin.entry()->ssdOffset(), pin.entry()->size());
268 };
269 }
270
271 // The SsdFile is almost full and the memory cache has the last batch written
272 // and a few entries from the batch before that.
273 // We read back the same batches and check
274 // contents.
275 for (auto startOffset = 0; startOffset <= kSsdSize - SsdFile::kRegionSize;
276 startOffset += SsdFile::kRegionSize) {
277 auto pins =
278 makePins(fileName_.id(), startOffset, 4096, 2048 * 1025, 62 * kMB);
279 readAndCheckPins(pins);
280 }
281 checkEvictionBlocked(allEntries, kSsdSize);
282 // We rewrite the cache with new entries.
283
284 for (auto startOffset = kSsdSize + SsdFile::kRegionSize;
285 startOffset <= kSsdSize * 2;
286 startOffset += SsdFile::kRegionSize) {
287 auto pins =
288 makePins(fileName_.id(), startOffset, 4096, 2048 * 1025, 62 * kMB);
289 ssdFile_->write(pins);
290 for (auto& pin : pins) {
291 EXPECT_EQ(ssdFile_.get(), pin.entry()->ssdFile());
292 allEntries.emplace_back(
293 pin.entry()->key(), pin.entry()->ssdOffset(), pin.entry()->size());
294 }
295 }
296
297 // We check howmany entries are found. The earliest writes will have been
298 // evicted. We read back the found entries and check their contents.
299 int32_t numFound = 0;
300 for (auto& entry : allEntries) {
301 std::vector<CachePin> pins;
302
303 pins.push_back(cache_->findOrCreate(
304 RawFileCacheKey{fileName_.id(), entry.key.offset},
305 entry.size,
306 nullptr));
307 if (pins.back().entry()->isExclusive()) {
308 std::vector<SsdPin> ssdPins;
309
310 ssdPins.push_back(
311 ssdFile_->find(RawFileCacheKey{fileName_.id(), entry.key.offset}));

Callers

nothing calls this directly

Calls 15

ssdFileMethod · 0.80
entryMethod · 0.80
keyMethod · 0.80
ssdOffsetMethod · 0.80
findOrCreateMethod · 0.80
isExclusiveMethod · 0.80
backMethod · 0.80
testingIsCowDisabledMethod · 0.80
idMethod · 0.45
writeMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected