StorageClient连接超时,ip已经隐藏了,求各位大佬帮帮忙


需求:想使用StorageClient查某个tag记录,该tag记录上千万,连接不上,其他导入功能,nebulaSession功能能用。

        List<HostAddress> addresses = Arrays.asList(new HostAddress("100.91.**", 9599), new HostAddress("100.92**", 9599),
                new HostAddress("100.93**", 9599));
        StorageClient storageClient = new StorageClient(addresses);
        try{
           storageClient.connect();
            storageClient.scanVertex("test","Site",Arrays.asList("name","id"));
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            storageClient.close();
        }

端口错了,这里要写 9669,也就是你 graphd 的端口号。

不知道你的client的版本是多少哈,我这边就以3.6为例,

  1. StorageClient创建连接是可以指定timeout的,尝试设置长一点超时时间?
public StorageClient(List<HostAddress> addresses, int timeout) {
        this.connection = new GraphStorageConnection();
        this.addresses = addresses;
        this.timeout = timeout;
    }
  1. 确保你们9559 metad端口是否开放?本地telnet试试?
1 个赞

对不住,我看错了,我以为你要连 nebula 服务。如果是 storage 的话,是 9559。你看下 awang 的回复,你看下是不是端口没开放权限。

1 个赞

如群里讨论

可以试试这个 setStorageAddresses support to optionally override storage addresses by wey-gu · Pull Request #451 · vesoft-inc/nebula-java · GitHub

这个改变允许了设定 storage 地址列表,而不是依赖从 metad 读取。

@江一旺 此外也有做映射的实现

2 个赞

比较简单的映射代码demo

public class SpecialStorageHostMetaClientImpl extends MetaClientImpl {

    private Map<HostAndPort, HostAndPort> storageAddressMapping = new HashMap<>();

    public SpecialStorageHostMetaClientImpl(List<HostAndPort> addresses, int timeout, int connectionRetry, int executionRetry) {
        super(addresses, timeout, connectionRetry, executionRetry);
    }

    public SpecialStorageHostMetaClientImpl(List<HostAndPort> addresses) {
        super(addresses);
    }

    public SpecialStorageHostMetaClientImpl(String host, int port) {
        super(host, port);
    }


    public void setStorageHostMapping(Map<HostAndPort, HostAndPort> storageAddressMapping) {
        this.storageAddressMapping = storageAddressMapping;
    }

    @Override
    public Map<Integer, List<HostAndPort>> getPartsAlloc(String spaceName) {
        Map<Integer, List<HostAndPort>> partsAlloc = super.getPartsAlloc(spaceName);
        if (this.storageAddressMapping != null && !this.storageAddressMapping.isEmpty()) {
            for (Integer part : partsAlloc.keySet()) {
                partsAlloc.computeIfPresent(part, (pt, hosts) -> hosts.stream().map(host -> storageAddressMapping.getOrDefault(host, host)).collect(Collectors.toList()));
            }
        }
        return partsAlloc;
    }

    public static void main(String[] args) throws Exception {
        SpecialStorageHostMetaClientImpl metaClient = new SpecialStorageHostMetaClientImpl("10.xx.xx.220", 9559);
        Map<HostAndPort, HostAndPort> storageAddressMapping = Collections.singletonMap(HostAndPort.fromParts("192.xx.xx.123", 9559), HostAndPort.fromParts("10.xx.xx.220", 9559));
        metaClient.setStorageHostMapping(storageAddressMapping);
        metaClient.connect();
        StorageClientImpl storageClient = new StorageClientImpl(metaClient, 10000);
        storageClient.connect();
        Iterator<ScanEdgeResponse> iterator =
                storageClient.scanEdge("user", 1, Collections.emptyMap(), true, 1000, 0, Long.MAX_VALUE);
        System.out.println(iterator.next());
    }

}
2 个赞

我基于3.6的版本nebula-client重新编写demo,使用方法见SpecialStorageAddressExample示例
SpecialStorageAddressExample.java (975 字节)
SpecialStorageAddressMetaManager.java (3.2 KB)
SpecialStorageClient.java (3.4 KB)

2 个赞

感谢阿旺

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。