Cassandra Select Count(*) Request TimeOut

Cassandra is a very powerful and robust database, which provides very high availability. However, often the limitations of Cassandra can prove very painful.

One major issue which beginners face on Cassandra is when trying to count records inserted into a table and get a timeout error.

For example, running below query on a table with 10M records:

select count(*) from KeySpce.User_Table;

We get error as below:

OperationTimedOut: errors={}, last_host=

The error comes out because the client timeout in Cassandra defaults to 10 seconds. As the above query would take longer, the client gets a timeout exception. Even the “Allow Filtering” option proves futile.

Mostly the select count(*), type of queries are one time requests, making any node level changes like as suggested to modify “cqlshrc” file is not always feasible.

To work around the same problem, I would suggest to close the cqlsh utility and restart the same by using below command:

$cqlsh --request-timeout=1000;

That is starting cqlsh client, double dash then “request” single dash “timeout” followed by time in seconds.

This sets the client request timeout to 1000 seconds and would be more than sufficient. After that we can run the select count(*) without any issues.

I hope this post helps many people.