@@ -31,7 +31,9 @@ def discover_peers(service_record):
31
31
# Erlang requires that we drop the trailing period from the absolute DNS
32
32
# name to form the hostname used for the Erlang node. This feels hacky
33
33
# 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 ("\t Got the following peers' fqdm from DNS lookup:" ,result ,flush = True )
36
+ return result
35
37
36
38
@backoff .on_exception (
37
39
backoff .expo ,
@@ -135,20 +137,23 @@ def are_nodes_in_sync(names):
135
137
# are fully primed with nodes data before progressing with
136
138
# _cluster_setup
137
139
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 ("\t Need 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 ("\t In sync!" )
142
+ else :
143
143
not_ready = True
144
-
145
- # For logging only...
144
+ # Rest is for logging only...
146
145
records_in_local_but_not_in_remote = set (local_resp .json ()['cluster_nodes' ]) - set (remote_resp .json ()['cluster_nodes' ])
147
146
if records_in_local_but_not_in_remote :
148
147
print ("\t Cluster members in {0} not yet present in {1}: {2}" .format (os .getenv ("HOSTNAME" ), name .split ("." ,1 )[0 ], records_in_local_but_not_in_remote ))
149
148
records_in_remote_but_not_in_local = set (remote_resp .json ()['cluster_nodes' ]) - set (local_resp .json ()['cluster_nodes' ])
150
149
if records_in_remote_but_not_in_local :
151
150
print ("\t Cluster 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 ("\t Need at least 2 cluster nodes in the _membership of pod" ,os .getenv ("HOSTNAME" ))
152
157
else :
153
158
not_ready = True
154
159
return not not_ready
@@ -160,7 +165,6 @@ def sleep_forever():
160
165
if __name__ == '__main__' :
161
166
peer_names = discover_peers (construct_service_record ())
162
167
connect_the_dots (peer_names )
163
- print ("Got the following peers' fqdm from DNS lookup:" ,peer_names ,flush = True )
164
168
165
169
# loop until all CouchDB nodes discovered
166
170
while not are_nodes_in_sync (peer_names ):
0 commit comments