caipengbo commented on code in PR #1414:
URL:
https://github.com/apache/incubator-kvrocks/pull/1414#discussion_r1185741503
##########
src/cluster/cluster.cc:
##########
@@ -135,23 +120,29 @@ Status Cluster::SetSlot(int slot, const std::string
&node_id, int64_t new_versio
// 1. Remove the slot from old node if existing
// 2. Add the slot into to-assign node
// 3. Update the map of slots to nodes.
- std::shared_ptr<ClusterNode> old_node = slots_nodes_[slot];
- if (old_node != nullptr) {
- old_node->slots[slot] = false;
- }
- to_assign_node->slots[slot] = true;
- slots_nodes_[slot] = to_assign_node;
-
- // Clear data of migrated slot or record of imported slot
- if (old_node == myself_ && old_node != to_assign_node) {
- // If slot is migrated from this node
- if (migrated_slots_.count(slot) > 0) {
- svr_->slot_migrator->ClearKeysOfSlot(kDefaultNamespace, slot);
- migrated_slots_.erase(slot);
- }
- // If slot is imported into this node
- if (imported_slots_.count(slot) > 0) {
- imported_slots_.erase(slot);
+ // remember: The atomicity of the process is based on
+ // the transactionality of ClearKeysOfSlot().
+ for (auto [s_start, s_end] : slot_ranges) {
+ for (int slot = s_start; slot <= s_end; slot++) {
+ std::shared_ptr<ClusterNode> old_node = slots_nodes_[slot];
+ if (old_node != nullptr) {
+ old_node->slots[slot] = false;
+ }
+ to_assign_node->slots[slot] = true;
+ slots_nodes_[slot] = to_assign_node;
+
+ // Clear data of migrated slot or record of imported slot
+ if (old_node == myself_ && old_node != to_assign_node) {
+ // If slot is migrated from this node
+ if (migrated_slots_.count(slot) > 0) {
+ svr_->slot_migrator->ClearKeysOfSlot(kDefaultNamespace, slot);
Review Comment:
After we merge this PR, you can ask an issue and I will solve this problem,
which I have solved in production environment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]