Compare commits

...

8 Commits

Author SHA1 Message Date
Marko Budiselić
3c36fa61d4 Merge branch 'master' into Fix-wrong-index-recovery-path 2023-11-17 17:08:21 -05:00
gvolfing
77fbb9e3ab Merge branch 'master' into Fix-wrong-index-recovery-path 2023-10-27 11:20:26 +02:00
gvolfing
0bcdf21067 Merge branch 'master' into Fix-wrong-index-recovery-path 2023-10-27 07:38:08 +02:00
gvolfing
71347fed1f Merge branch 'master' into Fix-wrong-index-recovery-path 2023-10-25 12:45:50 +02:00
gvolfing
584815c7ce Merge branch 'master' into Fix-wrong-index-recovery-path 2023-10-24 14:46:20 +02:00
gvolfing
19b712cfdb Merge branch 'master' into Fix-wrong-index-recovery-path 2023-10-19 10:10:21 +02:00
gvolfing
6f56dcd97c Merge branch 'master' into Fix-wrong-index-recovery-path 2023-09-06 13:21:15 +02:00
gvolfing
4a9807d720 Fix
When adding on-disk storage to Memgraph, we started to enforce the
existence of the WAL and Snapshop directories, which is an issue,
because we make different decisions based on the existence of those
directories during recovery.
2023-08-29 15:31:26 +02:00
3 changed files with 14 additions and 6 deletions

View File

@@ -75,7 +75,7 @@ std::vector<SnapshotDurabilityInfo> GetSnapshotFiles(const std::filesystem::path
const std::string_view uuid) {
std::vector<SnapshotDurabilityInfo> snapshot_files;
std::error_code error_code;
if (utils::DirExists(snapshot_directory)) {
if (!utils::IsDirEmpty(snapshot_directory)) {
for (const auto &item : std::filesystem::directory_iterator(snapshot_directory, error_code)) {
if (!item.is_regular_file()) continue;
if (!utils::HasReadAccess(item.path())) {
@@ -102,7 +102,7 @@ std::vector<SnapshotDurabilityInfo> GetSnapshotFiles(const std::filesystem::path
std::optional<std::vector<WalDurabilityInfo>> GetWalFiles(const std::filesystem::path &wal_directory,
const std::string_view uuid,
const std::optional<size_t> current_seq_num) {
if (!utils::DirExists(wal_directory)) return std::nullopt;
if (utils::IsDirEmpty(wal_directory)) return std::nullopt;
std::vector<WalDurabilityInfo> wal_files;
std::error_code error_code;
@@ -230,8 +230,8 @@ std::optional<RecoveryInfo> RecoverData(const std::filesystem::path &snapshot_di
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
spdlog::info("Recovering persisted data using snapshot ({}) and WAL directory ({}).", snapshot_directory,
wal_directory);
if (!utils::DirExists(snapshot_directory) && !utils::DirExists(wal_directory)) {
spdlog::warn(utils::MessageWithLink("Snapshot or WAL directory don't exist, there is nothing to recover.",
if (utils::IsDirEmpty(snapshot_directory) && utils::IsDirEmpty(wal_directory)) {
spdlog::warn(utils::MessageWithLink("Snapshot and WAL directory are both empty, there is nothing to recover.",
"https://memgr.ph/durability"));
return std::nullopt;
}
@@ -277,7 +277,7 @@ std::optional<RecoveryInfo> RecoverData(const std::filesystem::path &snapshot_di
snapshot_timestamp = recovered_snapshot->snapshot_info.start_timestamp;
repl_storage_state.epoch_.SetEpoch(std::move(recovered_snapshot->snapshot_info.epoch_id));
if (!utils::DirExists(wal_directory)) {
if (utils::IsDirEmpty(wal_directory)) {
const auto par_exec_info = config.durability.allow_parallel_index_creation
? std::make_optional(std::make_pair(recovery_info.vertex_batches,
config.durability.recovery_thread_count))
@@ -288,7 +288,7 @@ std::optional<RecoveryInfo> RecoverData(const std::filesystem::path &snapshot_di
} else {
spdlog::info("No snapshot file was found, collecting information from WAL directory {}.", wal_directory);
std::error_code error_code;
if (!utils::DirExists(wal_directory)) return std::nullopt;
if (utils::IsDirEmpty(wal_directory)) return std::nullopt;
// We use this smaller struct that contains only a subset of information
// necessary for the rest of the recovery function.
// Also, the struct is sorted primarily on the path it contains.

View File

@@ -66,6 +66,11 @@ bool DeleteDir(const std::filesystem::path &dir) noexcept {
return std::filesystem::remove_all(dir, error_code) > 0;
}
bool IsDirEmpty(const std::filesystem::path &dir) noexcept {
std::filesystem::directory_iterator it(dir);
return it == std::filesystem::directory_iterator();
}
bool DeleteFile(const std::filesystem::path &file) noexcept {
std::error_code error_code; // For exception suppression.
return std::filesystem::remove(file, error_code);

View File

@@ -53,6 +53,9 @@ bool DirExists(const std::filesystem::path &dir);
/// Deletes everything from the given directory including the directory.
bool DeleteDir(const std::filesystem::path &dir) noexcept;
/// Checks if a given directory contains any files.
bool IsDirEmpty(const std::filesystem::path &dir) noexcept;
/// Deletes just the specified file. Symlinks are not followed.
bool DeleteFile(const std::filesystem::path &file) noexcept;