summaryrefslogtreecommitdiff
diff options
authorMario Splivalo <mario.splivalo@canonical.com>2018-02-28 19:56:10 +0100
committerMario Splivalo <mario.splivalo@canonical.com>2018-03-02 14:53:06 +0100
commit67b1175fde196c5724869b70111642f3061b4fc3 (patch)
tree23c90332bf6d4de20113988e8fd17512a37bbcaf
parentf7aa97a7357ff6d10b31ec818d1b786e07a2cb4a (diff)
Fix replicaset initialization for Bionic, use leader-election.
Fixes-bug: LP #1748214
-rwxr-xr-xhooks/hooks.py16
1 files changed, 8 insertions, 8 deletions
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()