Skip to content

Commit 58b0bf9

Browse files
DISTMYSQL-243 - Orchestrator uses inefficient subquery in REPLACE to update cluster aliases
Problem: -------- Orchestrator has backend table cluster_alias to store aliases. At certain intervals, orchestrator will update the aliases or insert new host aliases. To do this, it uses the below query in UpdateClusterAliases(): ``` replace into cluster_alias (alias, cluster_name, last_registered) select suggested_cluster_alias, cluster_name, now() from database_instance left join database_instance_downtime using (hostname, port) where suggested_cluster_alias!='' /* exclude newly demoted, downtimed masters */ and ifnull( database_instance_downtime.downtime_active = 1 and database_instance_downtime.end_timestamp > now() and database_instance_downtime.reason = ? , 0) = 0 order by ifnull(last_checked <= last_seen, 0) asc, read_only desc, num_slave_hosts asc ``` The problem with the select query is it will generated the same alias,cluster_name multiple times. REPLACE does this operation by doing DELETE+INSERT. REPLACE repeatedly does the same work for all the duplicated records. This creates un-necessary work for two sub systems in InnoDB 1. Purge 2. SELECTS (ReadView) All those delete marked records create stress on Purge. SELECTs, when they have to build a older version of record, they have to build a long chain of old version records (using undo log). So the un-necessary REPLACE work will create a long chain of records to be built. Fix: ---- Use GROUPBY to filter duplicate records in subquery in REPLACE.
1 parent 22cfcd4 commit 58b0bf9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

go/inst/cluster_alias_dao.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,15 @@ func UpdateClusterAliases() error {
126126
left join database_instance_downtime using (hostname, port)
127127
where
128128
suggested_cluster_alias!=''
129+
and cluster_name != ''
129130
/* exclude newly demoted, downtimed masters */
130131
and ifnull(
131132
database_instance_downtime.downtime_active = 1
132133
and database_instance_downtime.end_timestamp > now()
133134
and database_instance_downtime.reason = ?
134135
, 0) = 0
135-
order by
136-
ifnull(last_checked <= last_seen, 0) asc,
137-
read_only desc,
138-
num_slave_hosts asc
136+
group by
137+
suggested_cluster_alias, cluster_name
139138
`, DowntimeLostInRecoveryMessage)
140139
return log.Errore(err)
141140
}

0 commit comments

Comments
 (0)