MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / _prepare_all_queries

Method _prepare_all_queries

cassandra/cluster.py:2275–2311  ·  view source on GitHub ↗
(self, host)

Source from the content-addressed store, hash-verified

2273 "statement on host %s: %r", host, response)
2274
2275 def _prepare_all_queries(self, host):
2276 if not self._prepared_statements or not self.reprepare_on_up:
2277 return
2278
2279 log.debug("Preparing all known prepared statements against host %s", host)
2280 connection = None
2281 try:
2282 connection = self.connection_factory(host.endpoint)
2283 statements = list(self._prepared_statements.values())
2284 if ProtocolVersion.uses_keyspace_flag(self.protocol_version):
2285 # V5 protocol and higher, no need to set the keyspace
2286 chunks = []
2287 for i in range(0, len(statements), 10):
2288 chunks.append(statements[i:i + 10])
2289 self._send_chunks(connection, host, chunks, True)
2290 else:
2291 for keyspace, ks_statements in groupby(statements, lambda s: s.keyspace):
2292 if keyspace is not None:
2293 connection.set_keyspace_blocking(keyspace)
2294
2295 # prepare 10 statements at a time
2296 ks_statements = list(ks_statements)
2297 chunks = []
2298 for i in range(0, len(ks_statements), 10):
2299 chunks.append(ks_statements[i:i + 10])
2300 self._send_chunks(connection, host, chunks)
2301
2302 log.debug("Done preparing all known prepared statements against host %s", host)
2303 except OperationTimedOut as timeout:
2304 log.warning("Timed out trying to prepare all statements on host %s: %s", host, timeout)
2305 except (ConnectionException, socket.error) as exc:
2306 log.warning("Error trying to prepare all statements on host %s: %r", host, exc)
2307 except Exception:
2308 log.exception("Error trying to prepare all statements on host %s", host)
2309 finally:
2310 if connection:
2311 connection.close()
2312
2313 def add_prepared(self, query_id, prepared_statement):
2314 with self._prepared_statement_lock:

Callers 2

on_upMethod · 0.95
on_addMethod · 0.95

Calls 6

connection_factoryMethod · 0.95
_send_chunksMethod · 0.95
uses_keyspace_flagMethod · 0.80
set_keyspace_blockingMethod · 0.80
valuesMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected