Altober
Altober

Reputation: 966

Cassandra - Set write timeout with Java API

I am trying to set the write timeout in Cassandra with the Java drive. SocketOptions allows me to set a read and connect timeout but not a write timeout. Does anyone knows the way to do this without changing the cassandra.yaml?

thanks

Altober

Upvotes: 4

Views: 3280

Answers (1)

Andy Tolbert
Andy Tolbert

Reputation: 11638

The name is misleading, but SocketOptions.getReadTimeoutMillis() applies to all requests from the driver to cassandra. You can think of it as a client-level timeout. If a response hasn't been returned by a cassandra node in that period of time an OperationTimeoutException will be raised and another node will be tried. Refer to the javadoc link above for more nuanced information about when the exception is raised to the client. Generally, you will want this timeout to be greater than your timeouts in cassandra.yaml, which is why 12 seconds is the default.

If you want to effectively manage timeouts at the client level, you can control this on a per query basis by using executeAsync along with a timed get on the ResultSetFuture to give up on the request after a period of time, i.e.:

ResultSet result = session.executeAsync("your query").get(300, TimeUnit.MILLISECONDS);

This will throw a TimeoutException if the request hasn't been completed in 300 ms.

Upvotes: 2

Related Questions