Cassandra Hector:如何验证行更新的成功/失败(错误处理)
我正在使用 Hector 从 java 应用程序与 cassandra 数据库进行交互。 (Hector 1.0-1)
在此示例中,它展示了如何插入(或更新)字段。
mutator.addInsertion("650222", "Npanxx", HFactory.createStringColumn("state", "CA"));
MutationResult mr = mutator.execute();
不过,关于手术结果的信息并不多。如何验证操作是否成功?返回值是 ResultStatus 实现,可以调用的 3 个方法是:
mr.getHostUsed()
mr.getExecutionTimeNano()
mr.getExecutionTimeMicro()
我是否可以假设,如果调用execute() 方法没有发生异常,则操作成功?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来execute方法没有声明抛出任何异常,因为它会抛出HectorException的实例,这是一个RuntimeException。
所以是的,如果没有抛出异常,则插入成功。否则,您将得到一个抛出 HectorException 的实例(对于 Cassandra 端的问题可能是 HTimedOutException/HUnavailableException ,对于 Hector 端的问题可能是其他问题)。
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).