Update all clients once and only once

This change solves two problmes. First, one off problems waiting
for the cluster to complete. Second, running update_shared_db_rels
too often.

Update clients will get executed only once as soon as
leader_node_is_ready() or client_node_is_ready() returns True.
Subsequent client requests will be handled by normal
*db-relation-changed hooks.

Co-Authored-By: Liam Young <liam.young@canonical.com>

Partial-Bug: #1717590
Change-Id: I7004218fe4750427bb0d3a957c13c4acfa02e1cd
This commit is contained in:
David Ames 2017-09-25 15:59:31 +00:00
parent ce78dd4dcf
commit fb95b22add
2 changed files with 13 additions and 1 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ __pycache__
*.sw[nop]
.testrepository
.tox
.stestr
func-results.json

View File

@ -108,6 +108,7 @@ from percona_utils import (
update_root_password,
)
from charmhelpers.core.unitdata import kv
hooks = Hooks()
@ -119,6 +120,8 @@ RES_MONITOR_PARAMS = ('params user="sstuser" password="%(sstpass)s" '
'op monitor interval="1s" timeout="30s" '
'OCF_CHECK_LEVEL="1"')
INITIAL_CLIENT_UPDATE_KEY = 'initial_client_update_done'
def install_percona_xtradb_cluster():
'''Attempt PXC install based on seeding of passwords for users'''
@ -261,6 +264,11 @@ def update_shared_db_rels():
for r_id in relation_ids('shared-db'):
for unit in related_units(r_id):
shared_db_changed(r_id, unit)
kvstore = kv()
update_done = kvstore.get(INITIAL_CLIENT_UPDATE_KEY, False)
if not update_done:
kvstore.set(key=INITIAL_CLIENT_UPDATE_KEY, value=True)
kvstore.flush()
@hooks.hook('upgrade-charm')
@ -759,7 +767,9 @@ def main():
hooks.execute(sys.argv)
except UnregisteredHookError as e:
log('Unknown hook {} - skipping.'.format(e))
update_shared_db_rels()
kvstore = kv()
if not kvstore.get(INITIAL_CLIENT_UPDATE_KEY, False):
update_shared_db_rels()
assess_status(register_configs())