apache / cassandra-gocql-driver

GoCQL Driver for Apache Cassandra®
https://cassandra.apache.org/
Apache License 2.0
2.58k stars 621 forks source link

fix: set useSystemSchema before policy setup #1797

Open dipeshhkc opened 2 months ago

dipeshhkc commented 2 months ago

During NewSession followed by init,

AddHosts is called in the policy before useSystemSchema is set.

if v, ok := s.policy.(bulkAddHosts); ok {
        v.AddHosts(hosts)
    }

So, getKeyspaceMetadata called by updateReplicas during AddHosts will take useSystemSchema=false and so 2nd query system.schema_keyspaces is called instead of system_schema.keyspaces.

 func getKeyspaceMetadata(session *Session, keyspaceName string) (*KeyspaceMetadata, error) {
    keyspace := &KeyspaceMetadata{Name: keyspaceName}

    if session.useSystemSchema { // Cassandra 3.x+
        const stmt = `
        SELECT durable_writes, replication
        FROM system_schema.keyspaces
        WHERE keyspace_name = ?`
        .......................
        } else {
        const stmt = `
        SELECT durable_writes, strategy_class, strategy_options
        FROM system.schema_keyspaces
        WHERE keyspace_name = ?`    
                .......................
         } 

so was getting following issue

control: error executing "In\t\tSELECT durable_writes, strategy_class, strategy-options\n
It\tFROM system.schema_keyspaces\n\t\tWHERE keyspace_name = ?": table system. schema_keyspa
ces does not exist