Automatically create a Python table + Cassandra 1.2

Introduction

I am writing a Python application using a Cassandra 1.2 cluster (7 nodes, replication ratio 3), and I am accessing Cassandra with Python using the cql library (CQL 3.0).

Problem

The application is built in such a way that when you try to run the cql statement against an unconfigured column family, it automatically creates a table and repeats the cql statement. For example, if I try to run this:

SELECT * FROM table1 

And table1 does not exist, then the application will run the corresponding CREATE TABLE for table1 and will repeat the previous selection. The problem is that after creating the table, the SELECT (repeat) error fails with this error:

 Request did not complete within rpc_timeout 

Question

I assume the cluster needs some time to spread the creation of the table or something like that? If I wait a few seconds between creating the table and repeating the select statement, everything works, but I want to know exactly why and if there is a better way to do this. Perhaps the creation of the creation table expected changes to be propagated before they are returned ?, is there any way to do this?

Thank you in advance

+4
source share
1 answer

I assume you are using cqlsh. The default consistency level for cqlsh is a single value that will be returned after the completion of the first node, but not necessary, before all nodes are completed. If you are reading, you are not guaranteed to read from a node that has a populated table. You can verify this by enabling tracing, but this will affect performance.

You can provide consistency , which should make it create wait until a table is created on all nodes.

 CREATE TABLE ... USING CONSISTENCY ALL 
+1
source

Source: https://habr.com/ru/post/1483432/


All Articles