Dump cleanup

Summary:
`dump()` awesome Memgraph function is removed.
`mg_dump` executable now uses "dump database" command instead of "return dump()"
and dumps database to standard output instead of a file.

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2122
This commit is contained in:
Tonko Sabolcec 2019-06-10 16:03:35 +02:00
parent 485592eb48
commit eb45ed09df
2 changed files with 5 additions and 49 deletions

View File

@ -953,22 +953,6 @@ TypedValue Substring(TypedValue *args, int64_t nargs, const EvaluationContext &,
return TypedValue(utils::Substr(str, start, len), memory);
}
#if MG_SINGLE_NODE
TypedValue Dump(TypedValue *args, int64_t nargs, const EvaluationContext &,
database::GraphDbAccessor *dba) {
if (nargs != 0) {
throw QueryRuntimeException("'dump' does not expect any arguments.");
}
std::vector<TypedValue> queries;
database::CypherDumpGenerator dump(dba);
for (std::ostringstream oss; dump.NextQuery(&oss); oss.str("")) {
queries.emplace_back(oss.str());
}
return queries;
}
#endif // MG_SINGLE_NODE
} // namespace
std::function<TypedValue(TypedValue *, int64_t, const EvaluationContext &,
@ -1047,9 +1031,6 @@ NameToFunction(const std::string &function_name) {
#if defined(MG_SINGLE_NODE) || defined(MG_SINGLE_NODE_HA)
if (function_name == "COUNTER") return Counter;
#endif
#ifdef MG_SINGLE_NODE
if (function_name == "DUMP") return Dump;
#endif
#ifdef MG_DISTRIBUTED
if (function_name == "WORKERID") return WorkerId;
#endif

View File

@ -23,7 +23,6 @@ DEFINE_int32(port, 7687, "Server port");
DEFINE_string(username, "", "Username for the database");
DEFINE_string(password, "", "Password for the database");
DEFINE_bool(use_ssl, true, "Use SSL when connecting to the server");
DEFINE_string(output, "", "Output target file path");
DECLARE_int32(min_log_level);
@ -46,13 +45,6 @@ int main(int argc, char **argv) {
communication::ClientContext context(FLAGS_use_ssl);
communication::bolt::Client client(&context);
if (FLAGS_output.empty()) {
std::cerr << "Output file not specified. Please run mg_dump --help for "
"more instructions."
<< std::endl;
return 1;
}
try {
const std::string bolt_client_version =
fmt::format("mg_dump/{}", gflags::VersionString());
@ -63,37 +55,20 @@ int main(int argc, char **argv) {
return 1;
}
// TODO(tsabolcec): Consider using the standard output instead of a file.
// That way we could use pipe for importing data at the same time, eg.
// `mg_dump --server=S1 | mg_client --server=S2`.
std::ofstream out(FLAGS_output, std::fstream::out);
if (!out.is_open()) {
std::cerr << "Error: couldn't open file \"" << FLAGS_output
<< "\" for writing" << std::endl;
return 1;
}
try {
auto ret = client.Execute("RETURN DUMP()", {});
if (ret.records.size() != 1 || ret.records[0].size() != 1) {
auto ret = client.Execute("DUMP DATABASE", {});
if (ret.fields.size() != 1) {
std::cerr << "Error: client received response in unexpected format"
<< std::endl;
out.close();
CHECK(fs::remove(FLAGS_output)) << "Failed to remove output target file "
<< FLAGS_output;
return 1;
}
const auto &list = ret.records[0][0];
for (const auto &query : list.ValueList()) {
out << query.ValueString() << std::endl;
for (const auto &row : ret.records) {
CHECK(row.size() == 1U) << "Unexpected number of columns in a row";
std::cout << row[0].ValueString() << std::endl;
}
out.close();
} catch (const communication::bolt::ClientFatalException &e) {
std::cerr << "Client received exception: " << e.what() << std::endl;
out.close();
CHECK(fs::remove(FLAGS_output)) << "Failed to remove output target file "
<< FLAGS_output;
return 1;
}