57
57
CtlSwitchToSlaveKwargs ,
58
58
DropSpiderRoutingKwargs ,
59
59
)
60
+ from backend .flow .utils .spider .spider_bk_config import get_spider_version_and_charset
60
61
from backend .flow .utils .spider .spider_db_meta import SpiderDBMeta
61
62
62
63
"""
@@ -72,6 +73,8 @@ def add_spider_slaves_sub_flow(
72
73
parent_global_data : dict ,
73
74
is_clone_user : bool = True ,
74
75
slave_domain : str = None ,
76
+ new_pkg_id : int = 0 ,
77
+ new_db_module_id : int = 0 ,
75
78
):
76
79
"""
77
80
定义对原有的TenDB cluster集群添加spider slave节点的公共子流程
@@ -82,7 +85,9 @@ def add_spider_slaves_sub_flow(
82
85
@param root_id: flow流程的root_id
83
86
@param parent_global_data: 本次子流程的对应上层流程的全局只读上下文
84
87
@param uid: 单据id
85
- @param is_clone_user 是否克隆权限
88
+ @param is_clone_user 是否克隆权限, 区分一些单据场景。
89
+ @param new_pkg_id 如果是做升级部署,需要传新版本的介质包,默认为0,表示不升级部署
90
+ @param new_db_module_id 如果是做升级部署,需要传新的DB模块ID,默认为0,表示不升级部署
86
91
"""
87
92
tdbctl_pass = get_random_string (length = 10 )
88
93
@@ -99,7 +104,15 @@ def add_spider_slaves_sub_flow(
99
104
)[0 ]
100
105
101
106
parent_global_data ["spider_ports" ] = [tmp_spider .port ]
102
- parent_global_data ["db_module_id" ] = cluster .db_module_id
107
+ # 获取版本和字符集信息
108
+ parent_global_data ["db_module_id" ] = new_db_module_id if new_db_module_id else cluster .db_module_id
109
+ parent_global_data ["spider_charset" ], parent_global_data ["spider_version" ] = get_spider_version_and_charset (
110
+ bk_biz_id = cluster .bk_biz_id , db_module_id = parent_global_data ["db_module_id" ]
111
+ )
112
+ # spider slave 不安装备份程序,只解压
113
+ parent_global_data ["untar_only" ] = True
114
+
115
+ # 声明子流程
103
116
sub_pipeline = SubBuilder (root_id = root_id , data = parent_global_data )
104
117
105
118
# 拼接执行原子任务活动节点需要的通用的私有参数结构体, 减少代码重复率,但引用时注意内部参数值传递的问题
@@ -125,20 +138,21 @@ def add_spider_slaves_sub_flow(
125
138
)
126
139
127
140
# 阶段1 下发spider安装介质包
128
- if parent_global_data . get ( "pkg_id" ) :
129
- pkg_id = parent_global_data [ "pkg_id" ]
141
+ if new_pkg_id :
142
+ # 代表升级部署,根据新的pkg_id下发介质包
130
143
sub_pipeline .add_act (
131
144
act_name = _ ("下发spider安装介质" ),
132
145
act_component_code = TransFileComponent .code ,
133
146
kwargs = asdict (
134
147
DownloadMediaKwargs (
135
148
bk_cloud_id = cluster .bk_cloud_id ,
136
149
exec_ip = [ip_info ["ip" ] for ip_info in add_spider_slaves ],
137
- file_list = GetFileList (db_type = DBType .MySQL ).spider_upgrade_package (pkg_id = pkg_id ),
150
+ file_list = GetFileList (db_type = DBType .MySQL ).spider_upgrade_package (pkg_id = new_pkg_id ),
138
151
)
139
152
),
140
153
)
141
154
else :
155
+ # 根据继承的版本名称,或者介质包
142
156
sub_pipeline .add_act (
143
157
act_name = _ ("下发spider安装介质" ),
144
158
act_component_code = TransFileComponent .code ,
@@ -260,6 +274,8 @@ def add_spider_masters_sub_flow(
260
274
uid : str ,
261
275
parent_global_data : dict ,
262
276
is_add_spider_mnt : bool ,
277
+ new_pkg_id : int = 0 ,
278
+ new_db_module_id : int = 0 ,
263
279
):
264
280
"""
265
281
定义对原有的TenDB cluster集群添加spider master节点的公共子流程
@@ -271,14 +287,24 @@ def add_spider_masters_sub_flow(
271
287
@param parent_global_data: 本次子流程的对应上层流程的全局只读上下文
272
288
@param is_add_spider_mnt: 表示这次添加spider 运维节点,如果是则True,不是则False
273
289
@param uid: 单据uid
290
+ @param new_pkg_id 如果是做升级部署,需要传新版本的介质包,默认为0,表示不升级部署
291
+ @param new_db_module_id 如果是做升级部署,需要传新的DB模块ID,默认为0,表示不升级部署
274
292
"""
275
293
tag = "mnt"
276
294
tdbctl_pass = get_random_string (length = 10 )
277
295
278
296
# 获取到集群对应的spider端口,作为这次的安装
279
297
parent_global_data ["spider_ports" ] = [cluster .proxyinstance_set .first ().port ]
280
298
parent_global_data ["ctl_port" ] = cluster .proxyinstance_set .first ().admin_port
281
- parent_global_data ["db_module_id" ] = cluster .db_module_id
299
+
300
+ # 获取版本和字符集信息
301
+ parent_global_data ["db_module_id" ] = new_db_module_id if new_db_module_id else cluster .db_module_id
302
+ parent_global_data ["spider_charset" ], parent_global_data ["spider_version" ] = get_spider_version_and_charset (
303
+ bk_biz_id = cluster .bk_biz_id , db_module_id = parent_global_data ["db_module_id" ]
304
+ )
305
+ parent_global_data ["ctl_charset" ] = parent_global_data ["spider_charset" ]
306
+
307
+ # 声明子流程
282
308
sub_pipeline = SubBuilder (root_id = root_id , data = parent_global_data )
283
309
284
310
# 拼接执行原子任务活动节点需要的通用的私有参数结构体, 减少代码重复率,但引用时注意内部参数值传递的问题
@@ -303,16 +329,15 @@ def add_spider_masters_sub_flow(
303
329
)
304
330
)
305
331
# 阶段1 下发spider安装介质包
306
- if parent_global_data .get ("pkg_id" ):
307
- pkg_id = parent_global_data ["pkg_id" ]
332
+ if new_pkg_id :
308
333
sub_pipeline .add_act (
309
334
act_name = _ ("下发spider安装介质" ),
310
335
act_component_code = TransFileComponent .code ,
311
336
kwargs = asdict (
312
337
DownloadMediaKwargs (
313
338
bk_cloud_id = cluster .bk_cloud_id ,
314
339
exec_ip = [ip_info ["ip" ] for ip_info in add_spider_masters ],
315
- file_list = GetFileList (db_type = DBType .MySQL ).spider_upgrade_package (pkg_id = pkg_id ),
340
+ file_list = GetFileList (db_type = DBType .MySQL ).spider_upgrade_package (pkg_id = new_pkg_id ),
316
341
)
317
342
),
318
343
)
@@ -344,17 +369,11 @@ def add_spider_masters_sub_flow(
344
369
acts_list = []
345
370
for spider in get_spider_master_incr (cluster , add_spider_masters ):
346
371
exec_act_kwargs .exec_ip = spider ["ip" ]
347
- if parent_global_data .get ("pkg_id" ):
348
- exec_act_kwargs .cluster = {
349
- "immutable_domain" : cluster .immute_domain ,
350
- "auto_incr_value" : spider ["incr_number" ],
351
- "pkg_id" : parent_global_data ["pkg_id" ],
352
- }
353
- else :
354
- exec_act_kwargs .cluster = {
355
- "immutable_domain" : cluster .immute_domain ,
356
- "auto_incr_value" : spider ["incr_number" ],
357
- }
372
+ exec_act_kwargs .cluster = {
373
+ "immutable_domain" : cluster .immute_domain ,
374
+ "auto_incr_value" : spider ["incr_number" ],
375
+ "pkg_id" : new_pkg_id ,
376
+ }
358
377
exec_act_kwargs .get_mysql_payload_func = MysqlActPayload .get_install_spider_payload .__name__
359
378
acts_list .append (
360
379
{
@@ -797,21 +816,14 @@ def reduce_ctls_routing(root_id: str, parent_global_data: dict, cluster: Cluster
797
816
798
817
if reduce_ctl_primary :
799
818
# 选择新节点作为primary,过滤待回收的节点
800
- all_ctl = cluster .proxyinstance_set .filter (
801
- tendbclusterspiderext__spider_role = TenDBClusterSpiderRole .SPIDER_MASTER
802
- )
803
-
804
- # 因为ctl集群是采用GTID+半同步数据同步,所以理论上选择任意一个从节点作为主,数据不会丢失
805
- new_ctl_primary = all_ctl .exclude (machine__ip__in = [ip_info .machine .ip for ip_info in reduce_ctls ]).first ()
806
-
807
819
sub_pipeline .add_act (
808
820
act_name = _ ("切换ctl中控集群" ),
809
821
act_component_code = CtlSwitchToSlaveComponent .code ,
810
822
kwargs = asdict (
811
823
CtlSwitchToSlaveKwargs (
812
824
cluster_id = cluster .id ,
813
825
reduce_ctl_primary = reduce_ctl_primary ,
814
- new_ctl_primary = f" { new_ctl_primary . machine . ip } { IP_PORT_DIVIDER } { new_ctl_primary . admin_port } " ,
826
+ reduce_ctl_secondary_list = reduce_ctl_secondary_list ,
815
827
)
816
828
),
817
829
)
0 commit comments