1

Problem

I would like to set a timeout for a specific readonly query using the dotnet driver.

Context

I have a query likeselect count(*) from TABLE where ID=value

I am aware that:

  • count(*) queries are not efficient
  • there is no guarantee that that query will return correct results
  • it will make full cluster scan

Despite all this, I still want to run that query once every 3-4 months.

Requirements:

  • specify the timeout from the dotnet driver
  • do not touch any cassandra server yml configuration

What I have tries I have big database locally on a single node. When I set a timeout to the query it is respected and everything works. In several minutes I got results. However, when I have a cluster of 5 nodes, a coordinator node gets the query and executes it against the other nodes and it hits 5 seconds timeout. Any timeouts which I have configured throught the driver for the socket or for the query are ignored. I also tried with all possible consistency levels. Also tried to use retry policy which ignores the errors.

Elders/Cronus.Persistence.Cassandra

Question Is it possible to set a timeout for a readonly query through the dotnet driver when cassandra is configured in a cluster?

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
mynkow
  • 4,408
  • 4
  • 38
  • 65

2 Answers2

1

The client-side read timeout is configured with SocketOptions.SetReadTimeoutMillis() which by default is set to 12000 ms (12s).

You can override the timeout for a specific operation by calling Statement.SetReadTimeoutMillis() which is shared with all other statement types.

As a side note, a COUNT() is perfectly fine when the query is restricted to a single partition since it will simply count the rows within that partition. It won't cause a full table scan and doesn't suffer from the problems I discussed in Why COUNT() is bad in Cassandra. Cheers!

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
  • I have tried this but this works when the query is executed against single node cassandra setup. In a cluster it timesout after 5 sec. https://github.com/Elders/Cronus.Persistence.Cassandra/blob/preview/src/Elders.Cronus.Persistence.Cassandra/CassandraProvider.cs#L77 – mynkow Mar 02 '23 at 12:11
0

If I had to guess, the 5-second timeout sounds like the default value of read_request_timeout. So I would bet that this is getting cut off at the cluster level, regardless of what gets set for the driver config.

Have a look at your Cassandra nodes in the cassandra.yaml file for this value: read_request_timeout. It should be set to 5000ms.

Be careful in raising that too high. That value was picked for a reason, and ultimately is there to protect the cluster from queries that consume too many resources.

Aaron
  • 55,518
  • 11
  • 116
  • 132
  • Exactly, however, I do not want to touch the cassandra.yaml file and control this through the driver only when executing that query. – mynkow Mar 02 '23 at 17:29