| 44 | namespace bytedance::bolt::cache { |
| 45 | |
| 46 | SsdCache::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 | |
| 81 | SsdFile& SsdCache::file(uint64_t fileId) { |
| 82 | const auto index = fileId % numShards_; |