如何从 gremlin NoHostAvailableException

问题描述

我使用 Gremlin Java 驱动程序连接到本地 gremlin 服务器。

简单的代码流程

创建客户端

Cluster cluster = Cluster.build().addContactPoint(<endp>).port(<port>).enableSsl(false).create()
Client client = cluster.connect();

提交脚本

client.submit("g.V().count()");

如果我第一次提交 Gremlin 服务器关闭时,在重新启动 gremlin 服务器后的后续重试中,连接仍然无法创建。

异常 Gremlin 服务器关闭时的第一次尝试:

org.apache.tinkerpop.gremlin.driver.exception.NoHostAvailableException: All hosts are considered unavailable due to prevIoUs exceptions. Check the error log to find the actual reason

Gremlin 服务器恢复后的异常:

tinkerpop.gremlin.driver.exception.NoHostAvailableException: All hosts are considered unavailable due to prevIoUs exceptions

需要注意的一件事是我不会在重试时创建客户端,只是这样做 提交脚本

client.submit("g.V().count()");

Gremlin 服务器很有可能随时宕机,在这种情况下如何恢复。基本上是

NoHostAvailableExceptio

可以恢复吗?

解决方法

通常,Client 应尝试重新连接到先前标记为不可用的主机。默认情况下,它应该以 1 秒的间隔重试主机,由以下配置管理:connectionPool.reconnectInterval。但是,在您的情况下,我认为您已经发现了一个错误,即重新连接尝试未开始,因为 Client 一开始就无法到达主机。从 3.4.11 开始,您只能通过重新创建您在评论中指出的 Client 来解决此问题。我在此处创建了一个问题来跟踪此问题:TINKERPOP-2569