5

When I was using cassandra-driver version 3.x everything worked fine. Now that I have upgraded I get the following message...

Error: ArgumentError: 'localDataCenter' is not defined in Client options and also was not specified in constructor. At least one is required.

My client declaration looks like this...

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
        }
});

What should I use for the localDataCenter property?

JGleason
  • 3,067
  • 6
  • 20
  • 54

4 Answers4

5

To find your datacenter name, check in your node's cassandra-rackdc.properties file:

$ cat cassandra-rackdc.properties
dc=HoldYourFire
rack=force10

Or, run a 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

If you have multiple data centers, you should pick the same one that your application is deployed in.

Aaron
  • 55,518
  • 11
  • 116
  • 132
2

Since v4.0 localDataCenter is now a required Client option When using DCAwareRoundRobinPolicy, which is used by default, a local data center must now be provided to the Client options parameter as localDataCenter. This is necessary to prevent routing requests to nodes in remote data centers.

Refer upgrade guide here.

GAK
  • 1,018
  • 1
  • 14
  • 33
1

I'm using the Azure CosmosDB Emulator in Cassandra API mode. I could not find any documentation on the proper localDataCenter property, so I just tried datacenter1 to see what would happen.

const client = new cassandra.Client({
  contactPoints: ['localhost'],
  localDataCenter: 'dataCenter1',
  authProvider: new cassandra.auth.PlainTextAuthProvider('localhost', 'key provided during emulator startup'),
  protocolOptions: {
    port: 10350
  },
  sslOptions: {
    rejectUnauthorized: true
  }
});

client.connect()
  .then(r => console.log(r))
  .catch(e => console.error(e))

This gave me a very helpful error message:

innerErrors: {
  '127.0.0.1:10350': ArgumentError: localDataCenter was configured as 'datacenter1', but only found hosts in data centers: [South Central US]

Once I changed my data center to "South Central US" my connection was successful.

sfuqua
  • 5,797
  • 1
  • 32
  • 33
0

It should be the datacenter where the application is running or the one that is close. Example copied from the datastax nodejs documentation

  const client = new cassandra.Client({ 
  contactPoints: ['host1', 'host2'],
  localDataCenter: 'datacenter1'
});
  • That really wasn't the point the point was where do I find my data center name and when I have multiple which should I use. Also why was this not an issue in 3.3? – JGleason Dec 17 '19 at 20:38