Skip to content

Commit f3eed40

Browse files
author
Robert Gartman
committed
Automate _cluster_setup
1 parent 00d1954 commit f3eed40

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

mem3_helper.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def discover_peers(service_record):
3131
# Erlang requires that we drop the trailing period from the absolute DNS
3232
# name to form the hostname used for the Erlang node. This feels hacky
3333
# but not sure of a more official answer
34-
return [rdata.target.to_text()[:-1] for rdata in answers]
34+
result = [rdata.target.to_text()[:-1] for rdata in answers]
35+
print("\tGot the following peers' fqdm from DNS lookup:",result,flush=True)
36+
return result
3537

3638
@backoff.on_exception(
3739
backoff.expo,
@@ -135,20 +137,23 @@ def are_nodes_in_sync(names):
135137
# are fully primed with nodes data before progressing with
136138
# _cluster_setup
137139
if (remote_resp.status_code == 200) and (local_resp.status_code == 200):
138-
if len(local_resp.json()['cluster_nodes']) < 2:
139-
# Minimum 2 nodes to form cluster!
140-
not_ready = True
141-
print("\tNeed at least 2 cluster nodes in the _membership of pod",os.getenv("HOSTNAME"))
142-
if ordered(local_resp.json()) != ordered(remote_resp.json()):
140+
if ordered(local_resp.json()) == ordered(remote_resp.json()):
141+
print ("\tIn sync!")
142+
else:
143143
not_ready = True
144-
145-
# For logging only...
144+
# Rest is for logging only...
146145
records_in_local_but_not_in_remote = set(local_resp.json()['cluster_nodes']) - set(remote_resp.json()['cluster_nodes'])
147146
if records_in_local_but_not_in_remote:
148147
print ("\tCluster members in {0} not yet present in {1}: {2}".format(os.getenv("HOSTNAME"), name.split(".",1)[0], records_in_local_but_not_in_remote))
149148
records_in_remote_but_not_in_local = set(remote_resp.json()['cluster_nodes']) - set(local_resp.json()['cluster_nodes'])
150149
if records_in_remote_but_not_in_local:
151150
print ("\tCluster members in {0} not yet present in {1}: {2}".format(name.split(".",1)[0], os.getenv("HOSTNAME"), records_in_remote_but_not_in_local))
151+
152+
# Cover the case where local pod has 1 record only
153+
if len(local_resp.json()['cluster_nodes']) < 2:
154+
# Minimum 2 nodes to form cluster!
155+
not_ready = True
156+
print("\tNeed at least 2 cluster nodes in the _membership of pod",os.getenv("HOSTNAME"))
152157
else:
153158
not_ready = True
154159
return not not_ready
@@ -160,7 +165,6 @@ def sleep_forever():
160165
if __name__ == '__main__':
161166
peer_names = discover_peers(construct_service_record())
162167
connect_the_dots(peer_names)
163-
print("Got the following peers' fqdm from DNS lookup:",peer_names,flush=True)
164168

165169
# loop until all CouchDB nodes discovered
166170
while not are_nodes_in_sync(peer_names):

0 commit comments

Comments
 (0)