| 1347 | } |
| 1348 | |
| 1349 | std::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 | |
| 1379 | Status Storage::ReplDataManager::SwapTmpFile(Storage *storage, const std::string &dir, const std::string &repl_file) { |
| 1380 | if (auto s = ValidateReplFileName(repl_file); !s.IsOK()) { |
nothing calls this directly
no test coverage detected