MCPcopy Create free account
hub / github.com/apache/kvrocks / NewTmpFile

Method NewTmpFile

src/storage/storage.cc:1349–1377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1347}
1348
1349std::unique_ptr<rocksdb::WritableFile> Storage::ReplDataManager::NewTmpFile(Storage *storage, const std::string &dir,
1350 const std::string &repl_file) {
1351 if (auto s = ValidateReplFileName(repl_file); !s.IsOK()) {
1352 ERROR("[storage] Invalid replication data file '{}': {}", repl_file, s.Msg());
1353 return nullptr;
1354 }
1355
1356 std::string tmp_file = dir + "/" + repl_file + ".tmp";
1357 auto s = storage->env_->FileExists(tmp_file);
1358 if (s.ok()) {
1359 ERROR("[storage] Data file exists, override");
1360 storage->env_->DeleteFile(tmp_file);
1361 }
1362
1363 // Create directory if missing
1364 auto abs_dir = tmp_file.substr(0, tmp_file.rfind('/'));
1365 if (!MkdirRecursively(storage->env_, abs_dir).IsOK()) {
1366 return nullptr;
1367 }
1368
1369 std::unique_ptr<rocksdb::WritableFile> wf;
1370 s = storage->env_->NewWritableFile(tmp_file, &wf, rocksdb::EnvOptions());
1371 if (!s.ok()) {
1372 ERROR("[storage] Failed to create data file '{}'. Error: {}", tmp_file, s.ToString());
1373 return nullptr;
1374 }
1375
1376 return wf;
1377}
1378
1379Status Storage::ReplDataManager::SwapTmpFile(Storage *storage, const std::string &dir, const std::string &repl_file) {
1380 if (auto s = ValidateReplFileName(repl_file); !s.IsOK()) {

Callers

nothing calls this directly

Calls 5

MkdirRecursivelyFunction · 0.85
FileExistsMethod · 0.80
IsOKMethod · 0.45
MsgMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected