Skip to content

Commit

Permalink
fix: mysql扩容单据元数据标志位处理 TencentBlueKing#8493
Browse files Browse the repository at this point in the history
  • Loading branch information
zfrendo committed Dec 9, 2024
1 parent 73f4cec commit 4c58dd2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from backend.configuration.constants import DBType
from backend.db_meta import api, request_validator
from backend.db_meta.api import common
from backend.db_meta.enums import ClusterType, InstanceRole, InstanceStatus, MachineType
from backend.db_meta.enums import ClusterType, InstancePhase, InstanceRole, InstanceStatus, MachineType
from backend.db_meta.models import Cluster, Machine, StorageInstance, StorageInstanceTuple, TenDBClusterStorageSet
from backend.db_package.models import Package
from backend.flow.consts import MediumEnum
Expand Down Expand Up @@ -64,6 +64,7 @@ def storage_create(
"instance_role": InstanceRole.REMOTE_MASTER.value,
"is_stand_by": True, # 标记实例属于切换组实例
"db_version": get_mysql_real_version(mysql_pkg.name), # 存储真正的版本号信息
"phase": InstancePhase.TRANS_STAGE.value,
},
)
if slave_ip is not None:
Expand All @@ -85,6 +86,7 @@ def storage_create(
"instance_role": InstanceRole.REMOTE_SLAVE.value,
"is_stand_by": True, # 标记实例属于切换组实例
"db_version": get_mysql_real_version(mysql_pkg.name), # 存储真正的版本号信息
"phase": InstancePhase.TRANS_STAGE.value,
},
)

Expand Down Expand Up @@ -129,6 +131,17 @@ def switch_remote_node(cls, cluster_id: int, source: dict, target: dict):
target_slave_obj.status = InstanceStatus.RUNNING
target_master_obj.instance_role = InstanceRole.REMOTE_MASTER
target_slave_obj.instance_role = InstanceRole.REMOTE_SLAVE
target_master_obj.phase = InstancePhase.ONLINE
target_slave_obj.phase = InstancePhase.ONLINE
# ip_port不相同实例表示裁撤替换。需要把源状态设置为UNAVAILABLE
if source_master_obj.ip_port != target_master_obj.ip_port:
source_master_obj.status = InstanceStatus.UNAVAILABLE
source_master_obj.phase = InstancePhase.OFFLINE
if source_slave_obj.ip_port != target_slave_obj.ip_port:
source_slave_obj.status = InstanceStatus.UNAVAILABLE
source_slave_obj.phase = InstancePhase.OFFLINE
source_master_obj.save()
source_slave_obj.save()
target_master_obj.save()
target_slave_obj.save()
source_tuple = StorageInstanceTuple.objects.get(ejector=source_master_obj, receiver=source_slave_obj)
Expand Down
10 changes: 5 additions & 5 deletions dbm-ui/backend/db_meta/api/cluster/tendbha/switch_slave.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from django.db import transaction

from backend.db_meta.enums import InstanceStatus
from backend.db_meta.enums import InstancePhase, InstanceStatus
from backend.db_meta.models import Cluster, StorageInstance

logger = logging.getLogger("root")
Expand All @@ -37,11 +37,11 @@ def switch_slave(cluster_id: int, target_slave_ip: str, source_slave_ip: str, sl
# target实例需要继承source实例的is_standby特性
target_storage_obj.is_stand_by = source_storage_obj.is_stand_by
target_storage_obj.status = InstanceStatus.RUNNING.value
target_storage_obj.phase = InstancePhase.ONLINE.value
target_storage_obj.save()

# cluster_entry = cluster.clusterentry_set.get(entry=slave_domain)
# cluster_entry.storageinstance_set.remove(source_storage_obj)
# cluster_entry.storageinstance_set.add(target_storage_obj)
source_storage_obj.status = InstanceStatus.UNAVAILABLE.value
source_storage_obj.status = InstancePhase.OFFLINE.value
source_storage_obj.save()
cluster_entry_list = cluster.clusterentry_set.filter(entry__in=slave_domain)
for cluster_entry in cluster_entry_list:
cluster_entry.storageinstance_set.remove(source_storage_obj)
Expand Down
6 changes: 5 additions & 1 deletion dbm-ui/backend/db_meta/api/cluster/tendbha/switch_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from django.db import transaction

from backend.db_meta.enums import InstanceRoleInstanceInnerRoleMap, InstanceStatus
from backend.db_meta.enums import InstancePhase, InstanceRoleInstanceInnerRoleMap, InstanceStatus
from backend.db_meta.models import Cluster, StorageInstance
from backend.flow.utils.mysql.mysql_module_operate import MysqlCCTopoOperator

Expand All @@ -34,6 +34,7 @@ def switch_storage(cluster_id: int, target_storage_ip: str, origin_storage_ip: s
)
cluster.storageinstance_set.remove(origin_storage)
target_storage.status = InstanceStatus.RUNNING.value
target_storage.phase = InstancePhase.ONLINE.value
# target实例需要继承source实例的is_standby特性
target_storage.is_stand_by = origin_storage.is_stand_by
if role:
Expand All @@ -47,6 +48,9 @@ def switch_storage(cluster_id: int, target_storage_ip: str, origin_storage_ip: s
cc_topo_operator.transfer_instances_to_cluster_module(instances=[target_storage], is_increment=True)
else:
target_storage.save()
origin_storage.status = InstanceStatus.UNAVAILABLE.value
origin_storage.phase = InstancePhase.OFFLINE.value
origin_storage.save()


def change_proxy_storage_entry(cluster_id: int, master_ip: str, new_master_ip: str):
Expand Down
3 changes: 3 additions & 0 deletions dbm-ui/backend/db_meta/api/storage_instance/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from backend.db_meta import request_validator
from backend.db_meta.enums import (
AccessLayer,
InstancePhase,
InstanceRoleInstanceInnerRoleMap,
InstanceStatus,
MachineTypeInstanceRoleMap,
Expand All @@ -40,6 +41,7 @@ def create(
name = ins.get("name", "")
version = ins.get("db_version", "")
is_stand_by = ins.get("is_stand_by", True)
phase = ins.get("phase", InstancePhase.ONLINE.value)

machine_obj = Machine.objects.get(ip=ip)
if machine_obj.access_layer != AccessLayer.STORAGE:
Expand Down Expand Up @@ -70,6 +72,7 @@ def create(
time_zone=time_zone,
version=version,
is_stand_by=is_stand_by,
phase=phase,
)
)
return storage_objs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def tendb_ha_restore_slave_flow(self):
cluster_model = Cluster.objects.get(id=cluster_id)
master = cluster_model.storageinstance_set.get(instance_inner_role=InstanceInnerRole.MASTER.value)
cluster = {
"add_slave_only": self.add_slave_only,
"mysql_port": master.port,
"cluster_id": cluster_model.id,
"cluster_type": cluster_class.cluster_type,
Expand Down
6 changes: 6 additions & 0 deletions dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
ClusterPhase,
ClusterType,
InstanceInnerRole,
InstancePhase,
InstanceRole,
InstanceStatus,
MachineType,
Expand Down Expand Up @@ -234,6 +235,8 @@ def mysql_add_slave_info(self):
port=self.cluster["master_port"],
)
slave_storage.status = InstanceStatus.RUNNING.value
if self.cluster.get("add_slave_only", False):
slave_storage.phase = InstancePhase.ONLINE.value
slave_storage.save()

def mysql_restore_slave_change_cluster_info(self):
Expand Down Expand Up @@ -735,6 +738,7 @@ def slave_recover_add_instance(self):
"instance_role": InstanceRole.BACKEND_SLAVE.value,
"is_stand_by": False, # 添加新建
"db_version": get_mysql_real_version(self.cluster["package"]), # 存储真正的版本号信息
"phase": InstancePhase.TRANS_STAGE.value,
}
)
clusters.append(
Expand Down Expand Up @@ -930,6 +934,7 @@ def migrate_cluster_add_instance(self):
"instance_role": InstanceRole.BACKEND_REPEATER.value,
"is_stand_by": False, # 添加新建
"db_version": get_mysql_real_version(mysql_pkg.name), # 存储真正的版本号信息
"phase": InstancePhase.TRANS_STAGE.value,
}
)
storage_instances.append(
Expand All @@ -939,6 +944,7 @@ def migrate_cluster_add_instance(self):
"instance_role": InstanceRole.BACKEND_SLAVE.value,
"is_stand_by": False, # 添加新建
"db_version": get_mysql_real_version(mysql_pkg.name), # 存储真正的版本号信息
"phase": InstancePhase.TRANS_STAGE.value,
}
)

Expand Down

0 comments on commit 4c58dd2

Please sign in to comment.