Skip to content

Commit 23a6e85

Browse files
committed
Make schema agreement waiting code renew connection on each iteration
When schema agreement is started it could happen that control connection is getting disconnected/reconnected, when it happens schema agreement code used to use disconnected connection to run all the queries. As result, it could lead to schema agreement timeout, even if all nodes got schema updated long time ago.
1 parent a401409 commit 23a6e85

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cassandra/cluster.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4206,7 +4206,7 @@ def _handle_schema_change(self, event):
42064206
delay = self._delay_for_event_type('schema_change', self._schema_event_refresh_window)
42074207
self._cluster.scheduler.schedule_unique(delay, self.refresh_schema, **event)
42084208

4209-
def wait_for_schema_agreement(self, connection=None, preloaded_results=None, wait_time=None):
4209+
def wait_for_schema_agreement(self, target_connection=None, preloaded_results=None, wait_time=None):
42104210

42114211
total_timeout = wait_time if wait_time is not None else self._cluster.max_schema_agreement_wait
42124212
if total_timeout <= 0:
@@ -4220,8 +4220,7 @@ def wait_for_schema_agreement(self, connection=None, preloaded_results=None, wai
42204220
if self._is_shutdown:
42214221
return
42224222

4223-
if not connection:
4224-
connection = self._connection
4223+
connection = target_connection or self._connection
42254224

42264225
if preloaded_results:
42274226
log.debug("[control connection] Attempting to use preloaded results for schema agreement")
@@ -4240,6 +4239,8 @@ def wait_for_schema_agreement(self, connection=None, preloaded_results=None, wai
42404239
select_peers_query = self._get_peers_query(self.PeersQueryType.PEERS_SCHEMA, connection)
42414240

42424241
while elapsed < total_timeout:
4242+
connection = target_connection or self._connection
4243+
42434244
peers_query = QueryMessage(query=maybe_add_timeout_to_query(select_peers_query, self._metadata_request_timeout),
42444245
consistency_level=cl)
42454246
local_query = QueryMessage(query=maybe_add_timeout_to_query(self._SELECT_SCHEMA_LOCAL, self._metadata_request_timeout),

0 commit comments

Comments
 (0)