Skip to content

Commit cf1d6fc

Browse files
committed
galera_bootstrap: Wait for initial bootstrap start prior creating users
The first start of galera can be a bit slow, so we're hitting a race with the initial sst user creation which in some cases might otherwise immediately die with "wsrep state not in Sync".
1 parent 6ea5a75 commit cf1d6fc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

chef/cookbooks/mysql/recipes/ha_galera.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
unless node[:database][:galera_bootstrapped]
4343
if CrowbarPacemakerHelper.is_cluster_founder?(node)
4444

45+
# mysql_install_db is blocking when mysql is running as
46+
# it wants an exclusive lock. This can happen if a
47+
# previous bootstrap ran into an error before stopping again
48+
49+
service "mysql-stop for install " do
50+
service_name mysql_service_name
51+
supports status: true, restart: true, reload: true
52+
action :stop
53+
end
54+
4555
execute "mysql_install_db" do
4656
command "mysql_install_db"
4757
action :run
@@ -90,6 +100,29 @@
90100
action :start
91101
end
92102

103+
ruby_block "wait mysql initialisation" do
104+
block do
105+
require "timeout"
106+
begin
107+
cmd = "mysql -u 'root' -N -B " \
108+
"-e \"SHOW STATUS WHERE Variable_name='wsrep_local_state_comment';\" | cut -f 2"
109+
sync_state = ""
110+
Timeout.timeout(30) do
111+
while sync_state != "Synced"
112+
sleep(1)
113+
get_state = Mixlib::ShellOut.new(cmd).run_command
114+
sync_state = get_state.stdout.chop
115+
end
116+
end
117+
rescue Timeout::Error
118+
message = "Galera cluster did not start after 30 seconds. " \
119+
"Check pacemaker and mysql log files manually for possible errors."
120+
Chef::Log.fatal(message)
121+
raise message
122+
end
123+
end
124+
end
125+
93126
database_user "create state snapshot transfer user" do
94127
connection db_connection
95128
username "sstuser"

0 commit comments

Comments
 (0)