From 1d2bb2cda6d2d4920dbce0456f124dfc91258016 Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Wed, 1 Apr 2020 11:23:02 +0200 Subject: [PATCH] Remove leftover traces of HA from query Reviewers: llugovic Reviewed By: llugovic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2743 --- src/memgraph.cpp | 12 ---- src/query/frontend/ast/ast.lcp | 2 +- .../frontend/ast/cypher_main_visitor.cpp | 3 - .../frontend/opencypher/grammar/Cypher.g4 | 4 +- .../opencypher/grammar/CypherLexer.g4 | 1 - .../frontend/semantic/required_privileges.cpp | 5 -- src/query/interpreter.cpp | 59 ------------------- src/query/interpreter.hpp | 7 --- 8 files changed, 2 insertions(+), 91 deletions(-) diff --git a/src/memgraph.cpp b/src/memgraph.cpp index 152fa4855..1245f1c59 100644 --- a/src/memgraph.cpp +++ b/src/memgraph.cpp @@ -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 user_; audit::Log *audit_log_; -#endif #endif io::network::Endpoint endpoint_; }; diff --git a/src/query/frontend/ast/ast.lcp b/src/query/frontend/ast/ast.lcp index 82b3c84f0..238bc1d7b 100644 --- a/src/query/frontend/ast/ast.lcp +++ b/src/query/frontend/ast/ast.lcp @@ -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 diff --git a/src/query/frontend/ast/cypher_main_visitor.cpp b/src/query/frontend/ast/cypher_main_visitor.cpp index fd4f8b626..023ac2448 100644 --- a/src/query/frontend/ast/cypher_main_visitor.cpp +++ b/src/query/frontend/ast/cypher_main_visitor.cpp @@ -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()); } diff --git a/src/query/frontend/opencypher/grammar/Cypher.g4 b/src/query/frontend/opencypher/grammar/Cypher.g4 index 152c9fc29..c26a331c2 100644 --- a/src/query/frontend/opencypher/grammar/Cypher.g4 +++ b/src/query/frontend/opencypher/grammar/Cypher.g4 @@ -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 ; diff --git a/src/query/frontend/opencypher/grammar/CypherLexer.g4 b/src/query/frontend/opencypher/grammar/CypherLexer.g4 index 37e7beeb2..c36114c61 100644 --- a/src/query/frontend/opencypher/grammar/CypherLexer.g4 +++ b/src/query/frontend/opencypher/grammar/CypherLexer.g4 @@ -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 ; diff --git a/src/query/frontend/semantic/required_privileges.cpp b/src/query/frontend/semantic/required_privileges.cpp index 1f5097095..d2d13ad81 100644 --- a/src/query/frontend/semantic/required_privileges.cpp +++ b/src/query/frontend/semantic/required_privileges.cpp @@ -41,11 +41,6 @@ class PrivilegeExtractor : public QueryVisitor, // 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; } } diff --git a/src/query/interpreter.cpp b/src/query/interpreter.cpp index f871d4e3c..11e480ade 100644 --- a/src/query/interpreter.cpp +++ b/src/query/interpreter.cpp @@ -5,9 +5,7 @@ #include #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 *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 *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(info.disk_usage))}}; return std::pair{results, QueryHandlerResult::COMMIT}; }; -#else - header = {"server id", "storage info", "value"}; - handler = [dba] { - auto info = dba->StorageInfo(); - std::vector> 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> results( - {{TypedValue("is_leader"), TypedValue(dba->raft()->IsLeader())}, - {TypedValue("term_id"), - TypedValue(static_cast(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(parsed_query.query)) || - info_query->info_type_ != InfoQuery::InfoType::RAFT)) { - throw raft::CantExecuteQueries(); - } - } -#endif - utils::Timer planning_timer; PreparedQuery prepared_query; diff --git a/src/query/interpreter.hpp b/src/query/interpreter.hpp index 242a05228..ef1692e18 100644 --- a/src/query/interpreter.hpp +++ b/src/query/interpreter.hpp @@ -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> @@ -316,11 +314,6 @@ std::map 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;