mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
feat(server): Use hashtags for sharding in emulated cluster mode. (#1602)
This PR would have been 1 line change instead of 11 files, but it required some plumbing and refactoring: * Now ClusterConfig is aware of emulated cluster mode * As a result, this API was moved from ClusterFamily * And so was the flag & its parsing * ClusterFamily doesn't need is_emulated_cluster_ member * ServerFamily no longer needs ClusterFamily* member (because the API is static) * I also changed `ClusterConfig::IsClusterEnabled()` to `ClusterConfig::IsEnabled()` to be shorter
This commit is contained in:
parent
723cc623c2
commit
ef55713dfc
11 changed files with 65 additions and 55 deletions
|
@ -8,14 +8,52 @@ extern "C" {
|
|||
#include <shared_mutex>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/flags.h"
|
||||
#include "base/logging.h"
|
||||
#include "cluster_config.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace dfly {
|
||||
ABSL_FLAG(string, cluster_mode, "", "Cluster mode supported. Default: \"\"");
|
||||
|
||||
bool ClusterConfig::cluster_enabled = false;
|
||||
namespace dfly {
|
||||
namespace {
|
||||
enum class ClusterMode {
|
||||
kUninitialized,
|
||||
kNoCluster,
|
||||
kEmulatedCluster,
|
||||
kRealCluster,
|
||||
};
|
||||
|
||||
ClusterMode cluster_mode = ClusterMode::kUninitialized;
|
||||
} // namespace
|
||||
|
||||
void ClusterConfig::Initialize() {
|
||||
string cluster_mode_str = absl::GetFlag(FLAGS_cluster_mode);
|
||||
|
||||
if (cluster_mode_str == "emulated") {
|
||||
cluster_mode = ClusterMode::kEmulatedCluster;
|
||||
} else if (cluster_mode_str == "yes") {
|
||||
cluster_mode = ClusterMode::kRealCluster;
|
||||
} else if (cluster_mode_str.empty()) {
|
||||
cluster_mode = ClusterMode::kNoCluster;
|
||||
} else {
|
||||
LOG(ERROR) << "Invalid value for flag --cluster_mode. Exiting...";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
bool ClusterConfig::IsEnabled() {
|
||||
return cluster_mode == ClusterMode::kRealCluster;
|
||||
}
|
||||
|
||||
bool ClusterConfig::IsEmulated() {
|
||||
return cluster_mode == ClusterMode::kEmulatedCluster;
|
||||
}
|
||||
|
||||
bool ClusterConfig::IsEnabledOrEmulated() {
|
||||
return IsEnabled() || IsEmulated();
|
||||
}
|
||||
|
||||
string_view ClusterConfig::KeyTag(string_view key) {
|
||||
size_t start = key.find('{');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue