-
Couldn't load subscription status.
- Fork 579
feat(cluster): disconnect replication connections to orphan slaves #2850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Changes from 2 commits
de4272b
41ddd7b
b5bb943
8af6476
a1bd734
1f77f03
2ede94c
7cc4315
bf7d6f8
eaec818
9c4db61
7f11538
19e81f3
14a7750
23a1fa8
05e8a58
37c8cae
b2c0d9b
9571ac8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,24 +23,33 @@ | |||||||||||||||||||||||||
| #include <config/config_util.h> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #include <array> | ||||||||||||||||||||||||||
| #include <cstdint> | ||||||||||||||||||||||||||
| #include <cstring> | ||||||||||||||||||||||||||
| #include <fstream> | ||||||||||||||||||||||||||
| #include <memory> | ||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||
| #include <string_view> | ||||||||||||||||||||||||||
| #include <vector> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #include "cluster/cluster_defs.h" | ||||||||||||||||||||||||||
| #include "commands/commander.h" | ||||||||||||||||||||||||||
| #include "common/io_util.h" | ||||||||||||||||||||||||||
| #include "fmt/base.h" | ||||||||||||||||||||||||||
| #include "fmt/format.h" | ||||||||||||||||||||||||||
| #include "parse_util.h" | ||||||||||||||||||||||||||
| #include "replication.h" | ||||||||||||||||||||||||||
| #include "server/server.h" | ||||||||||||||||||||||||||
| #include "string_util.h" | ||||||||||||||||||||||||||
| #include "time_util.h" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ClusterNode::ClusterNode(std::string id, std::string host, int port, int role, std::string master_id, | ||||||||||||||||||||||||||
| const std::bitset<kClusterSlots> &slots) | ||||||||||||||||||||||||||
| : id(std::move(id)), host(std::move(host)), port(port), role(role), master_id(std::move(master_id)), slots(slots) {} | ||||||||||||||||||||||||||
| ClusterNode::ClusterNode(std::string &&id, std::string &&host, int port, int role, std::string &&master_id, | ||||||||||||||||||||||||||
| std::bitset<kClusterSlots> &&slots) | ||||||||||||||||||||||||||
| : id(std::move(id)), | ||||||||||||||||||||||||||
| host(std::move(host)), | ||||||||||||||||||||||||||
| port(port), | ||||||||||||||||||||||||||
| role(role), | ||||||||||||||||||||||||||
| master_id(std::move(master_id)), | ||||||||||||||||||||||||||
| slots(std::move(slots)) {} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Cluster::Cluster(Server *srv, std::vector<std::string> binds, int port) | ||||||||||||||||||||||||||
| : srv_(srv), binds_(std::move(binds)), port_(port) { | ||||||||||||||||||||||||||
|
|
@@ -68,8 +77,8 @@ Status Cluster::SetNodeId(const std::string &node_id) { | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| myid_ = node_id; | ||||||||||||||||||||||||||
| // Already has cluster topology | ||||||||||||||||||||||||||
| if (version_ >= 0 && nodes_.find(node_id) != nodes_.end()) { | ||||||||||||||||||||||||||
| myself_ = nodes_[myid_]; | ||||||||||||||||||||||||||
| if (version_ >= 0 && nodes_->count(node_id) > 0) { | ||||||||||||||||||||||||||
| myself_ = nodes_->at(node_id); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| myself_ = nullptr; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
@@ -96,11 +105,13 @@ Status Cluster::SetSlotRanges(const std::vector<SlotRange> &slot_ranges, const s | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Get the node which we want to assign slots into it | ||||||||||||||||||||||||||
| std::shared_ptr<ClusterNode> to_assign_node = nodes_[node_id]; | ||||||||||||||||||||||||||
| if (to_assign_node == nullptr) { | ||||||||||||||||||||||||||
| auto it = nodes_->find(node_id); | ||||||||||||||||||||||||||
| if (it == nodes_->end()) { | ||||||||||||||||||||||||||
| return {Status::NotOK, "No this node in the cluster"}; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| auto to_assign_node = it->second; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| auto it = nodes_->find(node_id); | |
| if (it == nodes_->end()) { | |
| return {Status::NotOK, "No this node in the cluster"}; | |
| } | |
| auto to_assign_node = it->second; | |
| std::shared_ptr<ClusterNode> to_assign_node; | |
| if (auto it = nodes_.find(); it != nodes_.end()) { | |
| to_assign_node = .. | |
| } else { | |
| return {Status::NotOK, "No this node in the cluster"}; | |
| } |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(auto it = ;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is what this patch actually does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why these are changed?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes:
std::bitset, in most impl it is stored on the stack memory instead heap so move ctor has no difference from the copy ctor. usually you don't need to move it.ClassA(std::string x) : x(x) {}, you can pass either lval or rval to it. for rval, it involves two move ctors. And forClassA(std::string &&x) : x(x) {}, you can only pass rval to it, and also the performance difference is quite little or none.So these changes are not so useful.