Remove leftover traces of HA from query

Reviewers: llugovic

Reviewed By: llugovic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2743
This commit is contained in:
Matej Ferencevic 2020-04-01 11:23:02 +02:00
parent 8fb3a53b78
commit 1d2bb2cda6
8 changed files with 2 additions and 91 deletions

View File

@ -192,10 +192,8 @@ class BoltSession final
db_(data->db),
interpreter_(data->interpreter_context),
#ifdef MG_ENTERPRISE
#ifndef MG_SINGLE_NODE_HA
auth_(data->auth),
audit_log_(data->audit_log),
#endif
#endif
endpoint_(endpoint) {
}
@ -211,15 +209,12 @@ class BoltSession final
for (const auto &kv : params)
params_pv.emplace(kv.first, glue::ToPropertyValue(kv.second));
#ifdef MG_ENTERPRISE
#ifndef MG_SINGLE_NODE_HA
audit_log_->Record(endpoint_.address(), user_ ? user_->username() : "",
query, storage::PropertyValue(params_pv));
#endif
#endif
try {
auto result = interpreter_.Prepare(query, params_pv);
#ifdef MG_ENTERPRISE
#ifndef MG_SINGLE_NODE_HA
if (user_) {
const auto &permissions = user_->GetPermissions();
for (const auto &privilege : result.second) {
@ -232,7 +227,6 @@ class BoltSession final
}
}
}
#endif
#endif
return result.first;
@ -278,13 +272,9 @@ class BoltSession final
bool Authenticate(const std::string &username,
const std::string &password) override {
#ifdef MG_ENTERPRISE
#ifdef MG_SINGLE_NODE_HA
return true;
#else
if (!auth_->HasUsers()) return true;
user_ = auth_->Authenticate(username, password);
return !!user_;
#endif
#else
return true;
#endif
@ -338,11 +328,9 @@ class BoltSession final
const storage::Storage *db_;
query::Interpreter interpreter_;
#ifdef MG_ENTERPRISE
#ifndef MG_SINGLE_NODE_HA
auth::Auth *auth_;
std::optional<auth::User> user_;
audit::Log *audit_log_;
#endif
#endif
io::network::Endpoint endpoint_;
};

View File

@ -2151,7 +2151,7 @@ cpp<#
((info-type "InfoType" :scope :public))
(:public
(lcp:define-enum info-type
(storage index constraint raft)
(storage index constraint)
(:serialize))
#>cpp

View File

@ -61,9 +61,6 @@ antlrcpp::Any CypherMainVisitor::visitInfoQuery(
} else if (ctx->constraintInfo()) {
info_query->info_type_ = InfoQuery::InfoType::CONSTRAINT;
return info_query;
} else if (ctx->raftInfo()) {
info_query->info_type_ = InfoQuery::InfoType::RAFT;
return info_query;
} else {
throw utils::NotYetImplemented("Info query: '{}'", ctx->getText());
}

View File

@ -46,9 +46,7 @@ indexInfo : INDEX INFO ;
constraintInfo : CONSTRAINT INFO ;
raftInfo : RAFT INFO ;
infoQuery : SHOW ( storageInfo | indexInfo | constraintInfo | raftInfo ) ;
infoQuery : SHOW ( storageInfo | indexInfo | constraintInfo ) ;
explainQuery : EXPLAIN cypherQuery ;

View File

@ -119,7 +119,6 @@ OPTIONAL : O P T I O N A L ;
OR : O R ;
ORDER : O R D E R ;
PROFILE : P R O F I L E ;
RAFT : R A F T ;
REDUCE : R E D U C E ;
REMOVE : R E M O V E ;
RETURN : R E T U R N ;

View File

@ -41,11 +41,6 @@ class PrivilegeExtractor : public QueryVisitor<void>,
// for *or* with privileges.
AddPrivilege(AuthQuery::Privilege::CONSTRAINT);
break;
case InfoQuery::InfoType::RAFT:
// This query should always be available to everyone. It is essential
// for correct operation of the HA cluster. Because of that we don't
// add any privileges here.
break;
}
}

View File

@ -5,9 +5,7 @@
#include <glog/logging.h>
#include "glue/communication.hpp"
#ifndef MG_SINGLE_NODE_HA
#include "query/dump.hpp"
#endif
#include "query/exceptions.hpp"
#include "query/frontend/ast/cypher_main_visitor.hpp"
#include "query/frontend/opencypher/parser.hpp"
@ -17,9 +15,6 @@
#include "query/plan/planner.hpp"
#include "query/plan/profile.hpp"
#include "query/plan/vertex_count_cache.hpp"
#ifdef MG_SINGLE_NODE_HA
#include "raft/exceptions.hpp"
#endif
#include "utils/algorithm.hpp"
#include "utils/exceptions.hpp"
#include "utils/flag_validation.hpp"
@ -658,7 +653,6 @@ PreparedQuery PrepareDumpQuery(
ParsedQuery parsed_query, std::map<std::string, TypedValue> *summary,
InterpreterContext *interpreter_context,
utils::MonotonicBufferResource *execution_memory) {
#ifndef MG_SINGLE_NODE_HA
return PreparedQuery{
{"QUERY"},
std::move(parsed_query.required_privileges),
@ -668,9 +662,6 @@ PreparedQuery PrepareDumpQuery(
DumpDatabaseToCypherQueries(&query_dba, stream);
return QueryHandlerResult::NOTHING;
}};
#else
throw utils::NotYetImplemented("Dump database");
#endif
}
PreparedQuery PrepareIndexQuery(
@ -746,11 +737,6 @@ PreparedQuery PrepareAuthQuery(
std::map<std::string, TypedValue> *summary,
InterpreterContext *interpreter_context, DbAccessor *dba,
utils::MonotonicBufferResource *execution_memory) {
#ifdef MG_SINGLE_NODE_HA
throw utils::NotYetImplemented(
"Managing user privileges is not yet supported in Memgraph HA "
"instance.");
#else
if (in_explicit_transaction) {
throw UserModificationInMulticommandTxException();
}
@ -784,7 +770,6 @@ PreparedQuery PrepareAuthQuery(
return callback.should_abort_query ? QueryHandlerResult::ABORT
: QueryHandlerResult::COMMIT;
}};
#endif
}
PreparedQuery PrepareInfoQuery(
@ -800,7 +785,6 @@ PreparedQuery PrepareInfoQuery(
switch (info_query->info_type_) {
case InfoQuery::InfoType::STORAGE:
#ifndef MG_SINGLE_NODE_HA
header = {"storage info", "value"};
handler = [db] {
auto info = db->GetInfo();
@ -816,22 +800,6 @@ PreparedQuery PrepareInfoQuery(
TypedValue(static_cast<int64_t>(info.disk_usage))}};
return std::pair{results, QueryHandlerResult::COMMIT};
};
#else
header = {"server id", "storage info", "value"};
handler = [dba] {
auto info = dba->StorageInfo();
std::vector<std::vector<TypedValue>> results;
results.reserve(info.size());
for (const auto &peer_info : info) {
for (const auto &pair : peer_info.second) {
results.push_back({TypedValue(peer_info.first),
TypedValue(pair.first),
TypedValue(pair.second)});
}
}
return std::pair{results, QueryHandlerResult::COMMIT};
};
#endif
break;
case InfoQuery::InfoType::INDEX:
header = {"index type", "label", "property"};
@ -877,22 +845,6 @@ PreparedQuery PrepareInfoQuery(
return std::pair{results, QueryHandlerResult::NOTHING};
};
break;
case InfoQuery::InfoType::RAFT:
#if defined(MG_SINGLE_NODE_HA)
header = {"info", "value"};
handler = [dba] {
std::vector<std::vector<TypedValue>> results(
{{TypedValue("is_leader"), TypedValue(dba->raft()->IsLeader())},
{TypedValue("term_id"),
TypedValue(static_cast<int64_t>(dba->raft()->TermId()))}});
// It is critical to abort this query because it can be executed on
// machines that aren't the leader.
return std::pair{results, QueryHandlerResult::ABORT};
};
#else
throw utils::NotYetImplemented("raft info");
#endif
break;
}
return PreparedQuery{std::move(header),
@ -1121,17 +1073,6 @@ Interpreter::Prepare(
execution_db_accessor_.emplace(&*db_accessor_);
}
#ifdef MG_SINGLE_NODE_HA
{
InfoQuery *info_query = nullptr;
if (!execution_db_accessor_->raft()->IsLeader() &&
(!(info_query = utils::Downcast<InfoQuery>(parsed_query.query)) ||
info_query->info_type_ != InfoQuery::InfoType::RAFT)) {
throw raft::CantExecuteQueries();
}
}
#endif
utils::Timer planning_timer;
PreparedQuery prepared_query;

View File

@ -234,8 +234,6 @@ class Interpreter final {
* the state of the `Interpreter` in such a way so that the next call to
* `PullAll` executes the query.
*
* @throw raft::CantExecuteQueries if the Memgraph instance is not a Raft
* leader and a query other than an Info Raft query was given
* @throw query::QueryException
*/
std::pair<std::vector<std::string>, std::vector<query::AuthQuery::Privilege>>
@ -316,11 +314,6 @@ std::map<std::string, TypedValue> Interpreter::PullAll(TStream *result_stream) {
// Just let the exception propagate for error reporting purposes, but don't
// abort the current command.
throw;
#ifdef MG_SINGLE_NODE_HA
} catch (const query::HintedAbortError &) {
AbortCommand();
throw utils::BasicException("Transaction was asked to abort.");
#endif
} catch (const utils::BasicException &) {
AbortCommand();
throw;