Cassandra-Driver 4.x 中的 localDataCenter 我应该使用什么

JGl*_*son 5 cassandra cassandra-driver

当我使用cassandra-driver3.x 版本时,一切正常。现在我已经升级了,我收到以下消息...

错误:ArgumentError:“localDataCenter”未在客户端选项中定义,也未在构造函数中指定。至少需要一个。

我的客户声明看起来像这样......

const client = new Client({
        contactPoints: this.servers,
        keyspace: "keyspace",
        authProvider,
        sslOptions,
        pooling: {
            coreConnectionsPerHost: {
                [distance.local]: 1,
                [distance.remote]: 1
            }
        },
        // TODO: Needed because in spite of the documentation provided by DataStax the default value is not 0
        socketOptions: {
            readTimeout: 0
        }
});
Run Code Online (Sandbox Code Playgroud)

localDataCenter 属性应该使用什么?

Aar*_*ron 5

要查找您的数据中心名称,请签入节点的cassandra-rackdc.properties文件:

$ cat cassandra-rackdc.properties
dc=HoldYourFire
rack=force10
Run Code Online (Sandbox Code Playgroud)

或者,运行nodetool status:

$ bin/nodetool status
Datacenter: HoldYourFire
========================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns    Host ID                               Rack
UN  172.0.0.1  575.64 KiB  16           ?       5c5cfc93-2e61-472e-b69b-a4fc40f94876  force10
UN  172.0.0.2  575.64 KiB  16           ?       4f040fef-5a6c-4be1-ba13-c9edbeaff6e1  force10
UN  172.0.0.3  575.64 KiB  16           ?       96626294-0ea1-4775-a08e-45661dc84cfa  force10
Run Code Online (Sandbox Code Playgroud)

如果您有多个数据中心,您应该选择部署应用程序的同一个数据中心。


Pra*_*asu 0

它应该是运行应用程序的数据中心或附近的数据中心。从 datastax nodejs 文档复制的示例

  const client = new cassandra.Client({ 
  contactPoints: ['host1', 'host2'],
  localDataCenter: 'datacenter1'
});
Run Code Online (Sandbox Code Playgroud)