Cassandra Hector:如何验证行更新的成功/失败(错误处理)

发布于 2024-12-20 01:20:19 字数 477 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高速公鹿 2024-12-27 01:20:19

看起来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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文