如何在 spark 数据帧中配置多节点连接?

How to configure multiple node connection in spark dataframe?

我在集群上设置了 vertica,有 5 个节点。我正在使用下面的代码将数据帧写入 vertica table:

    Map<String, String> opts = new HashMap<>();
    opts.put("table", tableName);
    opts.put("db", verticaDB);
    opts.put("dbschema", dashboardSchema);

    opts.put("user", verticaUserName);
    opts.put("password", options.verticaPassword);

    opts.put("host", verticaHost);
    opts.put("hdfs_url",hdfs url);
    opts.put("web_hdfs_url",web_hdfs_url);
    String SPARK_VERTICA_SOURCE = "com.vertica.spark.datasource.DefaultSource";
    dataFrame.write().format(SPARK_VERTICA_SOURCE).options(opts).
                                                mode(saveMode).save();

以上代码运行良好,但它是连接到vertica的单个主节点。

我试图将主机作为多集群节点的连接url

 master_node_ip:5433/schema?Connectionloadbalance=1&backupservernode=node2_ip,node3_ip 

我是 spark 的新手,如何使用负载平衡从 Spark 连接 vertica?

提前致谢。

如果您以这种方式连接到 Vertica,ConnectionLoadBalance 的效果就是将连接请求发送到 master_node_ip(奇怪的名称,因为 Vertica 没有主节点)。简而言之:集群中接收到连接请求的节点"asks"集群中所有节点,即当前连接数负载最低的节点。然后该节点将响应连接请求,您将与该节点连接。

如果您想要更多,您的客户端(在本例中为 Spark)将必须实例化与您拥有的 Vertica 节点一样多的线程;每个都连接到不同的 Vertica 节点,具有 ConnectionLoadBalance=False,因此它们在 "wanted" 到的位置保持连接。

希望这对您有所帮助 - Marco