gocql: I think TokenAwareHostPolicy never works on my use-case

Please answer these questions before submitting your issue. Thanks!

What version of Cassandra are you using?

Cassandra 3.7

What version of Gocql are you using?

Latest from go get

What did you do?

I put a bunch of logger to determine if I am actually using TokenAware policy or not.

What did you expect to see?

I expect the app to utilize TokenAwareHostPolicy.

What did you see instead?

Actually, I always ended up using the fallback: DCAwareRoundRobinPolicy because I always hit this if block: } else if routingKey == nil { https://github.com/gocql/gocql/blob/master/policies.go#L528.

Further logging reveals that I am hitting this block on boot: info.request.colCount == 0 https://github.com/gocql/gocql/blob/master/session.go#L495

On subsequent queries, I am always hitting this block: routingKeyInfo.indexes[keyIndex] == -1 https://github.com/gocql/gocql/blob/master/session.go#L560

Finally, that’s because the partition key column name is never equal to bound column name: https://github.com/gocql/gocql/blob/master/session.go#L552.

partitionKey[0] is correctly pointing to metric column while info.request.columns has 2 items and both of them are the same thing: [time, time], shouldn’t it be [metric, time]?

See my create table below:

CREATE TABLE mykeyspace.mytable (
    metric text,
    time bigint,
    value double,
    PRIMARY KEY (metric, time)
) WITH CLUSTERING ORDER BY (time ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'NONE', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'com.jeffjirsa.cassandra.db.compaction.TimeWindowCompactionStrategy', 'compaction_window_size': '15', 'compaction_window_unit': 'DAYS', 'max_threshold': '32', 'min_sstable_size': '134217728', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 0.0
    AND dclocal_read_repair_chance = 0.0
    AND default_time_to_live = 0
    AND gc_grace_seconds = 0
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
// initialization code. cassandraConf is config struct.
cluster := gocql.NewCluster(cassandraConf.Clusters...)
cluster.Keyspace = cassandraConf.Keyspace
cluster.Port = cassandraConf.CQLPort
cluster.ProtoVersion = cassandraConf.ProtoVersion
cluster.NumConns = cassandraConf.NumConns
cluster.Timeout = cassandraConf.GetTimeout()
cluster.PageSize = cassandraConf.PageSize
cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: cassandraConf.MaxRetries}
cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.RoundRobinHostPolicy())

// If DC is defined, apply DataCentreHostFilter
if cassandraConf.DC != "" {
    cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.DCAwareRoundRobinPolicy(cassandraConf.DC))
    cluster.HostFilter = gocql.DataCentreHostFilter(cassandraConf.DC)
}

The Cassandra is on 2 DCs.

The table has 2 Replication Factor on each DC.

The SELECT query I am running is using LOCAL_QUORUM.

SELECT * FROM mykeyspace.mytable where metric IN (?) AND time >= ? AND time <= ?

// first ? value is a slice of string.

If you are having connectivity related issues please share the following additional information

Describe your Cassandra cluster

please provide the following information

  • output of nodetool status
  • output of SELECT peer, rpc_address FROM system.peers
  • rebuild your application with the gocql_debug tag and post the output

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@beltran Thank you!