4

TLDR; A table is still inaccessible while system_schema.tables already contains a record respective the table

I'm trying to use Cassandra concurrently. Cassandra version: [cqlsh 5.0.1 | Cassandra 3.11.3 | CQL spec 3.4.4 | Native protocol v4]

I have two Python scripts using cassandra-driver==3.16.0 for Consumer and Producer running in different processes.

While Producer creates and fills table, Consumer waits until table is created with Python script running CQL statement:

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)

After the statement results with at least one record I make a conclusion that table has been created and try to read it with SELECT:

SELECT * FROM test_keyspace.test_table WHERE ...

But sometimes, I get really annoying error:

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"

According to the information I discovered that error happens when SELECT statement executes with a table that has not been created yet. So while system_schema.tables already contains a record about the table, the table is not yet accessible.

Maybe there is a more reliable way to check table accessibility? Or common workaround?

Symon
  • 1,626
  • 1
  • 23
  • 31

2 Answers2

4

With single node Cassandra setups, I have witnessed structural changes not to propagate immediately. I.e. creating a table, then inserting into it, and the insert fails because the table does not exist. Then you check if the table exists, and it is there. And then, since some time has passed, inserts work.

The only way I managed to make Single Node Cassandras behave consistently is to introduce a one-second-wait after every structural change. This was fine by me, since Single Node Cassandras are only used in local development scenarios. In productive environments, I simply disable the wait.

Jan Dörrenhaus
  • 6,581
  • 2
  • 34
  • 45
  • So, do you want to say that in multi-node Cassandra cluster such an error disappears? – Symon May 17 '19 at 13:00
  • Quite an ugly hack btw. Is there a way to contact Cassandra dev-team or report a bug at least? – Symon May 17 '19 at 13:20
  • Yes, in a multi-node Cassandra setup, I have never witnessed this kind of error. And yes, you can of course report a bug in their JIRA. I didn't, because this 1) is difficult to reproduce and 2) only occurs in very unusual (single-node) setups. So I wouldn't hold my breath for a fix from their side. – Jan Dörrenhaus May 18 '19 at 21:40
0

In my case, it was searching for table on another keyspace.

ERROR:

cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="unconfigured table <table_name>"

I made sure it __keyspace__ points to right keyspace and then it worked.

Shakeel
  • 1,869
  • 15
  • 23