Crash with a meaningful message when the snapshot directory is a file.
Reviewers: buda, florijan Reviewed By: buda, florijan Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D728
This commit is contained in:
parent
75ccdc8dca
commit
9eac85c9fb
@ -10,6 +10,7 @@
|
||||
#include "database/graph_db.hpp"
|
||||
#include "database/graph_db_accessor.hpp"
|
||||
#include "durability/recovery.hpp"
|
||||
#include "utils/exceptions.hpp"
|
||||
|
||||
DECLARE_string(snapshot_directory);
|
||||
DECLARE_bool(recover_on_startup);
|
||||
@ -39,13 +40,22 @@ namespace fs = std::experimental::filesystem;
|
||||
class Dbms {
|
||||
public:
|
||||
Dbms() {
|
||||
auto snapshot_root_dir = fs::path(FLAGS_snapshot_directory);
|
||||
if (fs::exists(snapshot_root_dir) && !fs::is_directory(snapshot_root_dir)) {
|
||||
throw utils::BasicException("Specified snapshot directory is a file!");
|
||||
}
|
||||
|
||||
if (FLAGS_recover_on_startup) {
|
||||
if (fs::exists(fs::path(FLAGS_snapshot_directory))) {
|
||||
if (fs::exists(snapshot_root_dir)) {
|
||||
auto accessor = dbs.access();
|
||||
for (auto &snapshot_db :
|
||||
for (auto &snapshot_db_dir :
|
||||
fs::directory_iterator(FLAGS_snapshot_directory)) {
|
||||
// create db and set it active
|
||||
active(snapshot_db.path().filename(), snapshot_db);
|
||||
// The snapshot folder structure is:
|
||||
// snapshot_root_dir/database_name/[timestamp]
|
||||
if (fs::is_directory(snapshot_db_dir)) {
|
||||
// Create db and set it active
|
||||
active(snapshot_db_dir.path().filename(), snapshot_db_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,11 @@ void GraphDb::StartSnapshooting() {
|
||||
void GraphDb::RecoverDatabase(const fs::path &snapshot_db_dir) {
|
||||
if (snapshot_db_dir.empty()) return;
|
||||
std::vector<fs::path> snapshots;
|
||||
for (auto &snapshot_file : fs::directory_iterator(snapshot_db_dir))
|
||||
snapshots.push_back(snapshot_file);
|
||||
for (auto &snapshot_file : fs::directory_iterator(snapshot_db_dir)) {
|
||||
if (fs::is_regular_file(snapshot_file)) {
|
||||
snapshots.push_back(snapshot_file);
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(snapshots.rbegin(), snapshots.rend());
|
||||
Recovery recovery;
|
||||
|
Loading…
Reference in New Issue
Block a user