From 67b1175fde196c5724869b70111642f3061b4fc3 Mon Sep 17 00:00:00 2001 From: Mario Splivalo Date: Wed, 28 Feb 2018 19:56:10 +0100 Subject: Fix replicaset initialization for Bionic, use leader-election. Fixes-bug: LP #1748214 --- hooks/hooks.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'hooks') diff --git a/hooks/hooks.py b/hooks/hooks.py index 30fc460..f7fd85f 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -58,7 +58,7 @@ from charmhelpers.core.hookenv import ( Hooks, DEBUG, WARNING, -) + is_leader) from charmhelpers.core.hookenv import log as juju_log @@ -504,10 +504,11 @@ def init_replset(): retVal = False break except OperationFailure as e: - juju_log('init_replset: OperationFailure: %s' % e) + juju_log('init_replset: OperationFailure: %s' % e, DEBUG) if 'Received replSetInitiate' in str(e): continue else: + juju_log('init_replset: Unhandled OperationFailure %s' % e) raise finally: time.sleep(INIT_CHECK_DELAY) @@ -1174,6 +1175,9 @@ def am_i_primary(): elif 'EMPTYCONFIG' in str(e): # replication not initialized yet return False + elif 'no replset config has been received' in str(e): + # replication not initialized yet (Mongo3.4+) + return False elif 'not running with --replSet' in str(e): # replicaset not configured return False @@ -1200,12 +1204,8 @@ def replica_set_relation_changed(): juju_log('Joiner not ready yet... bailing out') return - # Initialize the replicaset - we do this only on the oldest unit in replset - # TODO: figure a way how to avoid race conditions - when unit/1 actually - # comes up before unit/0 does - happens rarely, but can happen - # quickfix - deploy replset with only two units, use 'add-unit' to - # add the rest - if oldest_peer(peer_units('replica-set')): + # Initialize the replicaset - we do this only on the leader! + if is_leader(): juju_log('Initializing replicaset') init_replset() -- cgit v1.2.3