worryg0d commented on issue #1947: URL: https://github.com/apache/cassandra-gocql-driver/issues/1947#issuecomment-4396104360
Before that commit, the driver was creating a replicaMap only for a session-level keyspace, so it didn't panic. With the change, it now computes a replica map for all available keyspaces in the cluster. The problem is that `networkTopology.replicaMap` doesn't take into account that `tokenRing` might not have hosts of DC on which the keyspace is not replicated. For example, we have a 2-DCS C* cluster: **dc1** and **dc2**. Here, it counts the number of DCs with replicas of the keyspace. In keyspace metadata, we have only a single replicated **dc1**, but the driver established connections to **dc2** so the `tokenRing` contains hosts of **dc2**. Later, the amount of dcs with replicas `dcsWithReplicas == len(dcRacks)` with the amount of dcs in `tokenRing`. Keyspace is only replicated to a single **dc1**, and `tokenRing` has hosts of `dc2`, so it passes that check. https://github.com/apache/cassandra-gocql-driver/blob/c65c762b83eccdb6a6a083c123a5935c4302745c/topology.go#L383-L392 However, `replicaRing` is empty because it skipped all hosts in `tokenRing` as none of them is a replica https://github.com/apache/cassandra-gocql-driver/blob/c65c762b83eccdb6a6a083c123a5935c4302745c/topology.go#L292-L296 So it passes the check `len(replicaRing) != len(tokens)` and we see a panic. To fix this, we can make it count DCS with replicas only for those DCS the driver is aware of: ``` dcsWithReplicas := 0 for dc, rf := range n.dcs { // We should count only DCs that driver is aware of and have a replication factor > 0 if _, knownDc := dcRacks[dc]; knownDc && rf > 0 { dcsWithReplicas++ } } ``` So it will return an empty `replicaRing` which should be safe: https://github.com/apache/cassandra-gocql-driver/blob/c65c762b83eccdb6a6a083c123a5935c4302745c/policies.go#L710-L714 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
