Hello,
I noticed an issue in the method BasicLoadBalancingPolicy.maybeAddDcFailover of the java driver 4.13.0
Usecase: 2 datacenters -> dc1 (local), dc2(remote). In case my app starts while the local dc1 isn't up, liveNodes.dcs will only have dc2. This means that only 1 dc is detected but it isn't the local one.
Issue: the current code considers that if only 1 datacenter is detected, it won't be considered among the remote ones (BasicLoadBalancingPolicy line 326 -> dcs.length <= 1). In my case, no node from dc2 will be considered as remote.
Proposed solution: remove the nb of dcs check -> it will be done naturally through the loop just after. And BasicSize of remoteNodes should be dcs.length * maxNodesPerRemote. If a node is from the local dc, it will naturally by skipped. The list size will then be truncated to keep only the filled remote nodes (trimmedRemoteNodes at line 346)
Thus the code for the QueryPlan remote (line 325) would be as follow
Object[] dcs = liveNodes.dcs().toArray(); Object[] remoteNodes = new Object[dcs.length * maxNodesPerRemoteDc];
Instead of
Object[] dcs = liveNodes.dcs().toArray(); if (dcs.length <= 1) { return EMPTY_NODES; } Object[] remoteNodes = new Object[(dcs.length - 1) * maxNodesPerRemoteDc]; int remoteNodesLength = 0;
Could this be considered in some future version of the driver ?
Thx !