Compare commits

...

4 Commits

Author SHA1 Message Date
Andreja Tonev
f103aa12db Declared var as static 2023-05-30 10:53:29 +02:00
Andreja Tonev
f23c977433 Merge branch 'master' into MG-add-default-server-name 2023-05-30 09:58:23 +02:00
Andreja Tonev
ba90ce3db9 Added server name to settings 2023-05-29 18:38:47 +02:00
Andreja Tonev
9f36ea6a83 Added a default server name 2023-05-25 16:01:17 +02:00
2 changed files with 34 additions and 3 deletions

View File

@@ -106,6 +106,10 @@ constexpr const char *kMgUser = "MEMGRAPH_USER";
constexpr const char *kMgPassword = "MEMGRAPH_PASSWORD";
constexpr const char *kMgPassfile = "MEMGRAPH_PASSFILE";
constexpr const char *kServerNameSettingKey = "server.name";
static const auto kMgDefaultName = std::string("Memgraph/") + version_string;
static memgraph::utils::Synchronized<std::string, memgraph::utils::ReadPrioritizedRWLock> bolt_server_name_;
// Short help flag.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
DEFINE_HIDDEN_bool(h, false, "Print usage and exit.");
@@ -609,8 +613,9 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
}
std::optional<std::string> GetServerNameForInit() override {
if (FLAGS_bolt_server_name_for_init.empty()) return std::nullopt;
return FLAGS_bolt_server_name_for_init;
const auto locked_name = bolt_server_name_.ReadLock();
if (locked_name->empty()) return std::nullopt;
return *locked_name;
}
private:
@@ -852,6 +857,26 @@ int main(int argc, char **argv) {
memgraph::license::global_license_checker.StartBackgroundLicenseChecker(memgraph::utils::global_settings);
// register bolt server name settings
// set to the current name if not present
memgraph::utils::global_settings.RegisterSetting(std::string{kServerNameSettingKey}, "", [&] {
const auto server_name = memgraph::utils::global_settings.GetValue(std::string{kServerNameSettingKey});
MG_ASSERT(server_name, "Bolt server name is missing from the settings");
*(bolt_server_name_.Lock()) = *server_name;
});
// TODO: Figure out the exact logic here. Do we want to override the settings using the gflag, or just use the gflag
// as a temp value?
if (!FLAGS_bolt_server_name_for_init.empty()) {
memgraph::utils::global_settings.SetValue(std::string{kServerNameSettingKey}, FLAGS_bolt_server_name_for_init);
} else {
const auto server_name = memgraph::utils::global_settings.GetValue(std::string{kServerNameSettingKey});
if (server_name && !server_name->empty()) {
*(bolt_server_name_.Lock()) = *server_name;
} else { // Default value
memgraph::utils::global_settings.SetValue(std::string{kServerNameSettingKey}, kMgDefaultName);
}
}
// All enterprise features should be constructed before the main database
// storage. This will cause them to be destructed *after* the main database
// storage. That way any errors that happen during enterprise features

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Memgraph Ltd.
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@@ -126,4 +126,10 @@ class WritePrioritizedRWLock final : public RWLock {
WritePrioritizedRWLock() : RWLock{Priority::WRITE} {};
};
// TODO: Double check why this didn't exist before
class ReadPrioritizedRWLock final : public RWLock {
public:
ReadPrioritizedRWLock() : RWLock{Priority::READ} {};
};
} // namespace memgraph::utils