Search code examples
cassandrahector

Cassandra Hector: How to verify the success/failure of a row update (error handling)


I'm using Hector to interact with a cassandra database from a java application. (Hector 1.0-1)

In this example, it shows how to insert (or update) a field.

mutator.addInsertion("650222", "Npanxx", HFactory.createStringColumn("state", "CA"));                

MutationResult mr = mutator.execute();

However, there is not much information on the outcome of the operation. How can we verify if the operation was successful or not? The return value is a ResultStatus implementation and the 3 methods that can be called are:

mr.getHostUsed()
mr.getExecutionTimeNano()
mr.getExecutionTimeMicro()

Can I assume that if there were no exceptions calling the execute() method, that the operation succeeded?


Solution

  • It looks like the execute method doesn't declare any exceptions thrown because it will throw instances of HectorException which is a RuntimeException.

    So yes, if no exceptions are thrown, the insert succeeded. Otherwise you will get an instance of HectorException thrown (likely HTimedOutException/HUnavailableException for problems on the Cassandra side and something else for something on the Hector side).