From 7924a94e77534766ab51be3a05054bd60219402f Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Thu, 21 Jun 2018 14:22:16 +0200 Subject: [PATCH] Add overwrite flag to mg_import_csv Reviewers: teon.banek, buda Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1442 --- docs/user_technical/import-tools.md | 3 ++- tools/src/mg_import_csv/main.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/user_technical/import-tools.md b/docs/user_technical/import-tools.md index f9ab72afb..786d145aa 100644 --- a/docs/user_technical/import-tools.md +++ b/docs/user_technical/import-tools.md @@ -94,7 +94,7 @@ will load the new dataset. Use the following command: ```bash -mg_import_csv --nodes=comment_nodes.csv --nodes=forum_nodes.csv --relationships=relationships.csv +mg_import_csv --overwrite --nodes=comment_nodes.csv --nodes=forum_nodes.csv --relationships=relationships.csv ``` If using Docker, things are a bit more complicated. First you need to move the @@ -110,6 +110,7 @@ Then, run the importer with the following: ```bash docker run -v mg_lib:/var/lib/memgraph -v mg_etc:/etc/memgraph -v mg_import:/import-data \ --entrypoint=mg_import_csv memgraph \ + --overwrite \ --nodes=/import-data/comment_nodes.csv --nodes=/import-data/forum_nodes.csv \ --relationships=/import-data/relationships.csv ``` diff --git a/tools/src/mg_import_csv/main.cpp b/tools/src/mg_import_csv/main.cpp index d6776a382..abfa7a0c3 100644 --- a/tools/src/mg_import_csv/main.cpp +++ b/tools/src/mg_import_csv/main.cpp @@ -470,6 +470,26 @@ std::string GetOutputPath() { } catch (const std::experimental::filesystem::filesystem_error &error) { LOG(FATAL) << error.what(); } + // TODO: Remove this stupid hack which deletes WAL files just to make snapshot + // recovery work. Newest snapshot without accompanying WAL files should be + // detected in memgraph and correctly recovered (or error reported). + try { + auto wal_dir = durability_dir + "/wal"; + if (std::experimental::filesystem::exists(wal_dir)) { + for (const auto &wal_file : + std::experimental::filesystem::directory_iterator(wal_dir)) { + if (!FLAGS_overwrite) { + LOG(FATAL) << "Durability directory isn't empty. Pass --overwrite to " + "remove the old recovery data"; + } + break; + } + LOG(WARNING) << "Removing old recovery data!"; + std::experimental::filesystem::remove_all(wal_dir); + } + } catch (const std::experimental::filesystem::filesystem_error &error) { + LOG(FATAL) << error.what(); + } int worker_id = 0; // TODO(dgleich): Remove this transaction id hack return std::string(