[hopem,r=gnuoy] Fix single node percona bootstrap.

This commit is contained in:
Liam Young 2015-07-30 15:49:48 +01:00
commit a203030ad8
2 changed files with 18 additions and 10 deletions

View File

@ -154,11 +154,14 @@ def render_config_restart_on_changed(clustered, hosts, bootstrap=False):
"""
pre_hash = file_hash(MY_CNF)
render_config(clustered, hosts)
if file_hash(MY_CNF) != pre_hash:
update_db_rels = False
if file_hash(MY_CNF) != pre_hash or bootstrap:
if bootstrap:
service('bootstrap-pxc', 'mysql')
# NOTE(dosaboy): this will not actually do anything if no cluster
# relation id exists yet.
notify_bootstrapped()
update_shared_db_rels()
update_db_rels = True
else:
delay = 1
attempts = 0
@ -187,6 +190,11 @@ def render_config_restart_on_changed(clustered, hosts, bootstrap=False):
# in a restart.
mark_seeded()
if update_db_rels:
update_shared_db_rels()
else:
log("Config file '%s' unchanged", level=DEBUG)
def update_shared_db_rels():
for r_id in relation_ids('shared-db'):
@ -233,9 +241,7 @@ def config_changed():
if is_sufficient_peers():
try:
# NOTE(jamespage): try with leadership election
if not clustered:
render_config_restart_on_changed(clustered, hosts)
elif clustered and is_leader():
if is_leader():
log("Leader unit - bootstrap required=%s" % (not bootstrapped),
DEBUG)
render_config_restart_on_changed(clustered, hosts,
@ -250,9 +256,7 @@ def config_changed():
except NotImplementedError:
# NOTE(jamespage): fallback to legacy behaviour.
oldest = oldest_peer(peer_units())
if not clustered:
render_config_restart_on_changed(clustered, hosts)
elif clustered and oldest:
if oldest:
log("Leader unit - bootstrap required=%s" % (not bootstrapped),
DEBUG)
render_config_restart_on_changed(clustered, hosts,
@ -387,7 +391,7 @@ def configure_db_for_hosts(hosts, database, username, db_helper):
# TODO: This could be a hook common between mysql and percona-cluster
@hooks.hook('shared-db-relation-changed')
def shared_db_changed(relation_id=None, unit=None):
if not is_bootstrapped():
if not seeded():
log("Percona cluster not yet bootstrapped - deferring shared-db rel "
"until bootstrapped", DEBUG)
return

View File

@ -345,8 +345,10 @@ def notify_bootstrapped(cluster_rid=None, cluster_uuid=None):
rids = [cluster_rid]
else:
rids = relation_ids('cluster')
if not rids:
log("No relation ids found for 'cluster'", level=INFO)
return
log("Notifying peers that percona is bootstrapped", DEBUG)
if not cluster_uuid:
cluster_uuid = get_wsrep_value('wsrep_cluster_state_uuid')
if not cluster_uuid:
@ -354,5 +356,7 @@ def notify_bootstrapped(cluster_rid=None, cluster_uuid=None):
log("Could not determine cluster uuid so using '%s' instead" %
(cluster_uuid), INFO)
log("Notifying peers that percona is bootstrapped (uuid=%s)" %
(cluster_uuid), DEBUG)
for rid in rids:
relation_set(relation_id=rid, **{'bootstrap-uuid': cluster_uuid})