Add server name to Bolt
Reviewers: buda, teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2021
This commit is contained in:
parent
1fb5d14751
commit
b7a5532cc2
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
@ -64,6 +65,10 @@ class Session {
|
|||||||
virtual bool Authenticate(const std::string &username,
|
virtual bool Authenticate(const std::string &username,
|
||||||
const std::string &password) = 0;
|
const std::string &password) = 0;
|
||||||
|
|
||||||
|
/** Return the name of the server that should be used for the Bolt INIT
|
||||||
|
* message. */
|
||||||
|
virtual std::optional<std::string> GetServerNameForInit() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the session after data has been read into the buffer.
|
* Executes the session after data has been read into the buffer.
|
||||||
* Goes through the bolt states in order to execute commands from the client.
|
* Goes through the bolt states in order to execute commands from the client.
|
||||||
|
@ -93,9 +93,19 @@ State StateInitRun(Session &session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return success.
|
// Return success.
|
||||||
if (!session.encoder_.MessageSuccess()) {
|
{
|
||||||
DLOG(WARNING) << "Couldn't send success message to the client!";
|
bool success_sent = false;
|
||||||
return State::Close;
|
auto server_name = session.GetServerNameForInit();
|
||||||
|
if (server_name) {
|
||||||
|
success_sent =
|
||||||
|
session.encoder_.MessageSuccess({{"server", *server_name}});
|
||||||
|
} else {
|
||||||
|
success_sent = session.encoder_.MessageSuccess();
|
||||||
|
}
|
||||||
|
if (!success_sent) {
|
||||||
|
DLOG(WARNING) << "Couldn't send success message to the client!";
|
||||||
|
return State::Close;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return State::Idle;
|
return State::Idle;
|
||||||
|
@ -21,6 +21,9 @@ DEFINE_uint64(memory_warning_threshold, 1024,
|
|||||||
"Memory warning threshold, in MB. If Memgraph detects there is "
|
"Memory warning threshold, in MB. If Memgraph detects there is "
|
||||||
"less available RAM it will log a warning. Set to 0 to "
|
"less available RAM it will log a warning. Set to 0 to "
|
||||||
"disable.");
|
"disable.");
|
||||||
|
DEFINE_string(bolt_server_name_for_init, "",
|
||||||
|
"Server name which the database should send to the client in the "
|
||||||
|
"Bolt INIT message.");
|
||||||
|
|
||||||
BoltSession::BoltSession(SessionData *data,
|
BoltSession::BoltSession(SessionData *data,
|
||||||
const io::network::Endpoint &endpoint,
|
const io::network::Endpoint &endpoint,
|
||||||
@ -130,6 +133,11 @@ bool BoltSession::Authenticate(const std::string &username,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> BoltSession::GetServerNameForInit() {
|
||||||
|
if (FLAGS_bolt_server_name_for_init.empty()) return std::nullopt;
|
||||||
|
return FLAGS_bolt_server_name_for_init;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef MG_SINGLE_NODE_V2
|
#ifdef MG_SINGLE_NODE_V2
|
||||||
BoltSession::TypedValueResultStream::TypedValueResultStream(
|
BoltSession::TypedValueResultStream::TypedValueResultStream(
|
||||||
TEncoder *encoder, const storage::Storage *db)
|
TEncoder *encoder, const storage::Storage *db)
|
||||||
|
@ -66,6 +66,8 @@ class BoltSession final
|
|||||||
bool Authenticate(const std::string &username,
|
bool Authenticate(const std::string &username,
|
||||||
const std::string &password) override;
|
const std::string &password) override;
|
||||||
|
|
||||||
|
std::optional<std::string> GetServerNameForInit() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Wrapper around TEncoder which converts TypedValue to Value
|
/// Wrapper around TEncoder which converts TypedValue to Value
|
||||||
/// before forwarding the calls to original TEncoder.
|
/// before forwarding the calls to original TEncoder.
|
||||||
|
@ -107,6 +107,10 @@ class BoltSession final
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> GetServerNameForInit() override {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SessionData *session_data_;
|
SessionData *session_data_;
|
||||||
io::network::Endpoint endpoint_;
|
io::network::Endpoint endpoint_;
|
||||||
|
@ -55,6 +55,10 @@ class TestSession : public Session<TestInputStream, TestOutputStream> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> GetServerNameForInit() override {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string query_;
|
std::string query_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user