TLDR;表仍然无法访问,而表中system_schema.tables
已经包含相应的记录
我正在尝试同时使用 Cassandra。卡桑德拉版本:[cqlsh 5.0.1 | Cassandra 3.11.3 | CQL spec 3.4.4 | Native protocol v4]
我有两个 Python 脚本cassandra-driver==3.16.0
用于在不同进程中运行的消费者和生产者。
当生产者创建和填充表时,消费者等待直到使用运行 CQL 语句的 Python 脚本创建表:
table_exists = False
while not table_exists:
cql = SimpleStatement(
"SELECT table_name FROM system_schema.tables WHERE keyspace_name = 'test_keyspace' AND table_name = 'test_table'"
)
results = cassandra_session.execute(cql)
table_exists = bool(results.current_rows)
在语句产生至少一条记录后,我得出一个表已创建的结论,并尝试使用以下命令读取它SELECT
:
SELECT * FROM test_keyspace.test_table WHERE ...
但有时,我会遇到非常烦人的错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/stress.py", line 128, in runner
for r in select(TEST_KEYSPACE, table_name):
File "/stress.py", line 63, in select
results = cassandra_session.execute(statement)
File "cassandra/cluster.py", line 2171, in cassandra.cluster.Session.execute
File "cassandra/cluster.py", line 4062, in cassandra.cluster.ResponseFuture.result
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="unconfigured table test_table"
根据信息,我发现当 SELECT 语句使用尚未创建的表执行时会发生错误。因此,虽然system_schema.tables
已经包含有关该表的记录,但该表还不能访问。
也许有一种更可靠的方法来检查表的可访问性?还是常见的解决方法?