Skip to content

Commit 6f21ae4

Browse files
authored
[fix](cloud) Add predecessor instance id (#62276)
When a rollback exists, the predecessor instance is not the same as the source instance. This change separates the two semantics into distinct fields for clarity.
1 parent 3d75942 commit 6f21ae4

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

cloud/src/resource-manager/resource_manager.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,18 +1414,19 @@ std::pair<MetaServiceCode, std::string> ResourceManager::refresh_instance(
14141414
void ResourceManager::refresh_instance(const std::string& instance_id,
14151415
const InstanceInfoPB& instance) {
14161416
bool is_successor_instance = instance.has_original_instance_id();
1417-
std::string source_instance_id = is_successor_instance ? instance.source_instance_id() : "";
1417+
std::string predecessor_instance_id =
1418+
is_successor_instance ? instance.predecessor_instance_id() : "";
14181419

14191420
std::lock_guard l(mtx_);
14201421
for (auto i = node_info_.begin(); i != node_info_.end();) {
1421-
// erase all nodes not belong to this instance_id
1422-
if (i->second.instance_id != instance_id &&
1423-
// ... or, if is_successor_instance, erase nodes belong to source_instance_id
1424-
(!is_successor_instance || i->second.instance_id != source_instance_id)) {
1422+
// erase all nodes belong to this instance_id
1423+
if (i->second.instance_id == instance_id ||
1424+
// ... or, if is_successor_instance, erase nodes belong to predecessor_instance_id
1425+
(is_successor_instance && i->second.instance_id == predecessor_instance_id)) {
1426+
i = node_info_.erase(i);
1427+
} else {
14251428
++i;
1426-
continue;
14271429
}
1428-
i = node_info_.erase(i);
14291430
}
14301431

14311432
// If successor_instance_id is set, it means this instance has a successor instance,

gensrc/proto/cloud.proto

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ message InstanceInfoPB {
129129
// For snapshot
130130
optional MultiVersionStatus multi_version_status = 110;
131131
optional SnapshotSwitchStatus snapshot_switch_status = 111;
132-
optional string source_instance_id = 112; // The instance cloned from.
132+
optional string source_instance_id = 112; // The instance cloned from (the snapshot instance id).
133133
optional string source_snapshot_id = 113; // The snapshot cloned from.
134134

135135
// Inherited from which instance (only used during rollback, the earliest instance id).
@@ -147,6 +147,11 @@ message InstanceInfoPB {
147147
optional int64 snapshot_retained_data_size = 121;
148148
optional int64 snapshot_billable_data_size = 122;
149149
optional SnapshotCompactStatus snapshot_compact_status = 123;
150+
151+
// The instance that is being rolled back, only used during rollback.
152+
// It is not always same as source_instance_id, because the source instance may inherit from another
153+
// instance during rollback, and the predecessor instance is the real instance which to execute the rollback.
154+
optional string predecessor_instance_id = 124;
150155
}
151156

152157
message StagePB {

0 commit comments

Comments
 (0)