OrientDB:如何连接到分布式集群中的多个远程主机?

OrientDB: how to connect to multiple remote hosts in a distributed cluster?

假设我有 3 个分布式模式的 OrientDB 主机 运行,在这些地址:

使用 Java 客户端,获取数据库引用的典型方法是:

 this.graphFactory = new OrientGraphFactory(
            "remote:[host]/[database]",
            "username",
            "password")
            .setupPool([...], [...]);

在连接字符串参数中,如何指示有多个主机?我的第一直觉是在一个单独的 IP 上手动设置一个 TCP 负载平衡器(即 HAProxy),并让它在我的 3 个主机之间分配它。

有没有办法告诉 API 有多个 IP 可供选择,或者我应该在我的实例前面设置一个负载平衡器?

您可以使用所有以分号分隔的地址:

remote:192.168.10.4/db;remote:192.168.10.5/db;remote:192.168.10.6/db

OrientDB 将尝试连接到第一个,但如果无法连接,它将依次尝试其他连接。

以上连接数据库的方式对我不起作用。

我试过远程:host1/host2/host3/{databsename}

示例:remote:192.168.10.4;192.168.10.5;192.168.10.6/db

这有效。

2019-07-01 上海

对于 v3.0.x,多节点连接如下所示:

remote:{ip_1},{ip_2},{ip_3}/{database_name}

OrientDB JavaApi 演示:

String url = "remote:{ip_1},{ip_2},{ip_3}/{database_name}";
String username = "username";
String password = "password";

// FIXME: I'm not sure the pool configuration is suit for you, may be you can use the default config.

OrientDBConfigBuilder poolCfg = OrientDBConfig.builder();
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MIN, 1);
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MAX, 100);
poolCfg.addConfig(OGlobalConfiguration.CLIENT_CONNECTION_STRATEGY, OStorageRemote.CONNECTION_STRATEGY.ROUND_ROBIN_CONNECT);

ODatabasePool pool = new ODatabasePool(url, userName, password, poolCfg.build());
ODatabaseSession session = pool.acquire();
session.begin();
....

OrientDB source code

  public OrientDB(String url, String serverUser, String serverPassword, OrientDBConfig configuration) {
    int pos;
    String what;
    if ((pos = url.indexOf(':')) > 0) {
      what = url.substring(0, pos);
    } else {
      what = url;
    }
    if ("embedded".equals(what) || "memory".equals(what) || "plocal".equals(what))
      internal = OrientDBInternal.embedded(url.substring(url.indexOf(':') + 1), configuration);

=========================== HERE =========================
    else if ("remote".equals(what))
      internal = OrientDBInternal.remote(url.substring(url.indexOf(':') + 1).split(","), configuration);
=========================== HERE =========================

    else
      throw new IllegalArgumentException("Wrong url:`" + url + "`");

    this.serverUser = serverUser;
    this.serverPassword = serverPassword;
  }