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

Method SsdCache

bolt/common/caching/SsdCache.cpp:46–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44namespace bytedance::bolt::cache {
45
46SsdCache::SsdCache(
47 std::string_view filePrefix,
48 uint64_t maxBytes,
49 int32_t numShards,
50 folly::Executor* executor,
51 int64_t checkpointIntervalBytes,
52 bool disableFileCow)
53 : filePrefix_(filePrefix),
54 numShards_(numShards),
55 groupStats_(std::make_unique<FileGroupStats>()),
56 executor_(executor) {
57 // Make sure the given path of Ssd files has the prefix for local file system.
58 // Local file system would be derived based on the prefix.
59 BOLT_CHECK(
60 filePrefix_.find("/") == 0,
61 "Ssd path '{}' does not start with '/' that points to local file system.",
62 filePrefix_);
63 filesystems::getFileSystem(filePrefix_, nullptr)
64 ->mkdir(std::filesystem::path(filePrefix).parent_path().string());
65
66 files_.reserve(numShards_);
67 // Cache size must be a multiple of this so that each shard has the same max
68 // size.
69 uint64_t sizeQuantum = numShards_ * SsdFile::kRegionSize;
70 int32_t fileMaxRegions = bits::roundUp(maxBytes, sizeQuantum) / sizeQuantum;
71 for (auto i = 0; i < numShards_; ++i) {
72 files_.push_back(std::make_unique<SsdFile>(
73 fmt::format("{}{}", filePrefix_, i),
74 i,
75 fileMaxRegions,
76 checkpointIntervalBytes / numShards,
77 disableFileCow));
78 }
79}
80
81SsdFile& SsdCache::file(uint64_t fileId) {
82 const auto index = fileId % numShards_;

Callers

nothing calls this directly

Calls 7

getFileSystemFunction · 0.85
roundUpFunction · 0.85
stringMethod · 0.80
findMethod · 0.45
mkdirMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected