Skip to content

Commit cd20217

Browse files
xfwdukezhangzhw8
authored andcommitted
fix(mysql): 标准化流程优化, crontab 安装保留业务自定义任务 #7509
1 parent 5d368bc commit cd20217

File tree

8 files changed

+36
-9
lines changed

8 files changed

+36
-9
lines changed

dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/standardize_mysql.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ func (c *StandardizeMySQLComp) Init() error {
9898
}
9999

100100
func (c *StandardizeMySQLComp) ClearOldCrontab() error {
101-
err := osutil.RemoveUserCrontab("mysql")
101+
err := osutil.CleanLocalCrontab()
102102
if err != nil {
103103
logger.Error("clear mysql crontab failed: %s", err.Error())
104+
return err
104105
} else {
105106
logger.Info("clear mysql crontab success")
106107
}

dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/standardize_proxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ type StandardizeProxyComp struct {
1111
}
1212

1313
func (c *StandardizeProxyComp) ClearOldCrontab() error {
14-
err := osutil.RemoveUserCrontab("mysql")
14+
err := osutil.CleanLocalCrontab()
1515
if err != nil {
1616
logger.Error("clear mysql crontab failed: %s", err.Error())
17+
return err
1718
} else {
1819
logger.Info("clear mysql crontab success")
1920
}

dbm-services/mysql/db-tools/dbactuator/pkg/util/osutil/crontab.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,18 @@ func CleanLocalCrontab() error {
202202
slaveSync = "/home/mysql/monitor/master_slave_sync_check.pl"
203203
tbinlodumperStatus = "tbinlogdumper_status.pl"
204204
prometheus = "prometheus"
205+
filebeatWatcher = "/home/mysql/filebeat-deploy/monitor_filebeat_watcher"
205206
)
206207
cleanCrontabs := []string{
207208
getStatusPL, dbBackupOld, dbBackupNew, dbBackupMulti, dbBackupXtrabackup, rotateLog,
208-
proxyStatus, slaveSync, tbinlodumperStatus, prometheus, rotateLogGo, dbBackupMultiGo,
209+
proxyStatus, slaveSync, tbinlodumperStatus, prometheus, rotateLogGo, dbBackupMultiGo, filebeatWatcher,
209210
}
210211

211212
existCrontabs, err := CrontabsExist(cleanCrontabs)
212213
if err != nil {
213214
return err
214215
}
216+
logger.Info("find crontabs %s", existCrontabs)
215217
// 如果不存在需要清理的crontab 直接返回成功
216218
if len(existCrontabs) <= 0 {
217219
return nil

dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_ha_standardize_flow.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def standardize(self):
6767

6868
cluster_objects = Cluster.objects.filter(
6969
pk__in=cluster_ids, bk_biz_id=bk_biz_id, cluster_type=ClusterType.TenDBHA.value
70+
).prefetch_related(
71+
"proxyinstance_set", "storageinstance_set", "proxyinstance_set__machine", "storageinstance_set__machine"
7072
)
7173
if cluster_objects.count() != len(cluster_ids):
7274
raise DBMetaException(
@@ -78,7 +80,7 @@ def standardize(self):
7880
data=self.data,
7981
need_random_pass_cluster_ids=list(set(self.data["infos"]["cluster_ids"])),
8082
)
81-
standardize_pipe.add_sub_pipeline(self._build_trans_module_sub(clusters=cluster_objects))
83+
8284
standardize_pipe.add_sub_pipeline(self._build_instantiate_mysql_config_sub(clusters=cluster_objects))
8385

8486
# 为了代码方便这里稍微特殊点
@@ -111,6 +113,9 @@ def standardize(self):
111113
self._build_storage_sub(ips=storage_ips),
112114
]
113115
)
116+
117+
standardize_pipe.add_sub_pipeline(self._build_trans_module_sub(clusters=cluster_objects))
118+
114119
logger.info(_("构建TenDBHA集群标准化流程成功"))
115120
standardize_pipe.run_pipeline(is_drop_random_user=True)
116121

dbm-ui/backend/flow/engine/bamboo/scene/spider/spider_cluster_standardize_flow.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ def standardize(self):
6565

6666
cluster_objects = Cluster.objects.filter(
6767
pk__in=cluster_ids, bk_biz_id=bk_biz_id, cluster_type=ClusterType.TenDBCluster.value
68+
).prefetch_related(
69+
"proxyinstance_set",
70+
"storageinstance_set",
71+
"proxyinstance_set__machine",
72+
"storageinstance_set__machine",
73+
"proxyinstance_set__tendbclusterspiderext",
6874
)
6975
if cluster_objects.count() != len(cluster_ids):
7076
raise DBMetaException(
@@ -77,7 +83,6 @@ def standardize(self):
7783
need_random_pass_cluster_ids=list(set(self.data["infos"]["cluster_ids"])),
7884
)
7985

80-
standardize_pipe.add_sub_pipeline(self._build_trans_module_sub(clusters=cluster_objects))
8186
standardize_pipe.add_sub_pipeline(self._build_instantiate_config_sub(clusters=cluster_objects))
8287

8388
spider_master_ips = {}
@@ -123,6 +128,8 @@ def standardize(self):
123128
if spider_mnt_ips:
124129
standardize_pipe.add_sub_pipeline(self._build_spider_mnt_sub(ips=spider_mnt_ips))
125130

131+
standardize_pipe.add_sub_pipeline(self._build_trans_module_sub(clusters=cluster_objects))
132+
126133
logger.info(_("构建TenDBCluster集群标准化流程成功"))
127134
standardize_pipe.run_pipeline(is_drop_random_user=True)
128135

dbm-ui/backend/flow/engine/bamboo/scene/tendbsingle/standardize.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def standardize(self):
5454

5555
cluster_objects = Cluster.objects.filter(
5656
pk__in=cluster_ids, bk_biz_id=bk_biz_id, cluster_type=ClusterType.TenDBSingle.value
57-
)
57+
).prefetch_related("storageinstance_set", "storageinstance_set__machine")
5858
if cluster_objects.count() != len(cluster_ids):
5959
raise DBMetaException(
6060
message="input {} clusters, but found {}".format(len(cluster_ids), cluster_objects.count())
@@ -65,7 +65,7 @@ def standardize(self):
6565
data=self.data,
6666
need_random_pass_cluster_ids=list(set(self.data["infos"]["cluster_ids"])),
6767
)
68-
standardize_pipe.add_sub_pipeline(self._build_trans_module_sub(clusters=cluster_objects))
68+
6969
standardize_pipe.add_sub_pipeline(self._build_instantiate_mysql_config_sub(clusters=cluster_objects))
7070

7171
storage_ips = {}
@@ -84,6 +84,7 @@ def standardize(self):
8484
self._build_storage_sub(ips=storage_ips),
8585
]
8686
)
87+
standardize_pipe.add_sub_pipeline(self._build_trans_module_sub(clusters=cluster_objects))
8788
logger.info(_("构建TenDBSingle集群标准化流程成功"))
8889
standardize_pipe.run_pipeline(is_drop_random_user=True)
8990

dbm-ui/backend/flow/plugins/components/collections/mysql/cluster_standardize_trans_module.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from django.utils.translation import ugettext as _
1212
from pipeline.component_framework.component import Component
1313

14+
from backend.db_meta.enums import TenDBClusterSpiderRole
1415
from backend.db_meta.models import Cluster
1516
from backend.flow.plugins.components.collections.common.base_service import BaseService
1617
from backend.flow.utils.mysql.mysql_module_operate import MysqlCCTopoOperator
@@ -28,8 +29,15 @@ def _execute(self, data, parent_data) -> bool:
2829
cluster_obj.storageinstance_set.all(), is_increment=True
2930
)
3031
MysqlCCTopoOperator(cluster_obj).transfer_instances_to_cluster_module(
31-
cluster_obj.proxyinstance_set.all(), is_increment=True
32+
cluster_obj.proxyinstance_set.exclude(
33+
tendbclusterspiderext__spider_role__in=[
34+
TenDBClusterSpiderRole.SPIDER_MNT,
35+
TenDBClusterSpiderRole.SPIDER_SLAVE_MNT,
36+
]
37+
),
38+
is_increment=True,
3239
)
40+
3341
self.log_info(_("[{}] CC 模块标准化完成".format(kwargs["node_name"])))
3442
return True
3543

dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,9 @@ def get_deploy_mysql_monitor_payload(self, **kwargs) -> dict:
16071607
)
16081608
# 增加对安装spider监控的适配
16091609
elif machine.machine_type == MachineType.SPIDER.value:
1610-
for instance in ProxyInstance.objects.filter(machine__ip=kwargs["ip"], cluster__id__in=cluster_ids):
1610+
for instance in ProxyInstance.objects.filter(
1611+
machine__ip=kwargs["ip"], cluster__id__in=cluster_ids
1612+
).prefetch_related("tendbclusterspiderext"):
16111613
cluster = instance.cluster.get()
16121614
instances_info.append(
16131615
{

0 commit comments

Comments
 (0)