Raj Kumar Gupta
Raj Kumar Gupta

Reputation: 91

Cassandra select query giving timeout error with Gocql driver

I am getting timeout error when executing more than 2000 SELECT queries simultaneously. I am using gocql client for Cassandra 3.7 (JAVA version 8).

"error":"gocql: no response received from cassandra within timeout period"...

I am having following table as schema,

CREATE TABLE my_db.my_message (
    id text,
    message_id uuid,
    message text,   
    version text,
    status  tinyint,
    PRIMARY KEY (id, message_id)
)

CREATE INDEX IF NOT EXISTS ON my_db.my_message(status);

Below is my query that gives timeout error when executing more than 2000 queries simultaneously.

"SELECT * FROM my_db.my_message WHERE id=? AND status = ?"

'id' is primary key and 'status' is secondary index in where clause. 'message_id' is also primary key but not used in this select query.

Any help would be appreciated. Thanks in advance.

Upvotes: 1

Views: 750

Answers (1)

Ashraful Islam
Ashraful Islam

Reputation: 12840

Do not use index on frequently updated or deleted column

Remember when not to use an index

  • On high-cardinality columns for a query of a huge volume of records for a small number of results
  • In tables that use a counter column.
  • On a frequently updated or deleted column
  • To look for a row in a large partition unless narrowly queried

I think your column status has low cardinality and frequently updated. Since you are narrowing your search by providing partition key id, So low cardinality is not a problem for you. The main problem is you frequently update indexed column status. Every time you update cassandra store a tombstone.

Cassandra stores tombstones in the index until the tombstone limit reaches 100K cells. After exceeding the tombstone limit, the query that uses the indexed value will fail.

So you should filter data by status column value in the application layer.

Upvotes: 1

Related Questions