From fb95b22add55e0254523c9a6a6f84c832931c20c Mon Sep 17 00:00:00 2001 From: David Ames Date: Mon, 25 Sep 2017 15:59:31 +0000 Subject: [PATCH] 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 Partial-Bug: #1717590 Change-Id: I7004218fe4750427bb0d3a957c13c4acfa02e1cd --- .gitignore | 2 ++ hooks/percona_hooks.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 243cad5..b8b7216 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ __pycache__ *.sw[nop] .testrepository .tox +.stestr +func-results.json diff --git a/hooks/percona_hooks.py b/hooks/percona_hooks.py index c1280cf..abcc2cb 100755 --- a/hooks/percona_hooks.py +++ b/hooks/percona_hooks.py @@ -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())