|
11 | 11 | import time
|
12 | 12 | import aiohttp
|
13 | 13 | from typing import Optional, List
|
| 14 | +from cassandra import InvalidRequest # type: ignore |
14 | 15 | from cassandra.auth import PlainTextAuthProvider # type: ignore
|
15 | 16 | from cassandra.cluster import Cluster, NoHostAvailable # type: ignore
|
16 | 17 | from cassandra.cluster import ExecutionProfile, EXEC_PROFILE_DEFAULT # type: ignore
|
@@ -215,9 +216,18 @@ async def cql_is_up(self) -> bool:
|
215 | 216 | try:
|
216 | 217 | with Cluster(execution_profiles={EXEC_PROFILE_DEFAULT: profile},
|
217 | 218 | contact_points=[self.hostname], auth_provider=auth) as cluster:
|
218 |
| - with cluster.connect(): |
| 219 | + with cluster.connect() as session: |
| 220 | + # auth::standard_role_manager creates "cassandra" role in an |
| 221 | + # async loop auth::do_after_system_ready(), which retries |
| 222 | + # role creation with an exponential back-off. In other |
| 223 | + # words, even after CQL port is up, Scylla may still be |
| 224 | + # initializing. When the role is ready, queries begin to |
| 225 | + # work, so rely on this "side effect". |
| 226 | + session.execute("CREATE KEYSPACE k WITH REPLICATION = {" + |
| 227 | + "'class' : 'SimpleStrategy', 'replication_factor' : 1 }") |
| 228 | + session.execute("DROP KEYSPACE k") |
219 | 229 | return True
|
220 |
| - except NoHostAvailable: |
| 230 | + except (NoHostAvailable, InvalidRequest): |
221 | 231 | return False
|
222 | 232 | finally:
|
223 | 233 | caslog.setLevel(oldlevel)
|
|
0 commit comments