m0t9 commented on issue #812: URL: https://github.com/apache/cassandra-gocql-driver/issues/812#issuecomment-3346413147
We've also encountered this problem when implementing unlimited retries to Cassandra, required by our business logic. It is not enough to only enable retries due to the fact of single hosts traversal (e.g.,[here](https://github.com/apache/cassandra-gocql-driver/blob/trunk/policies.go#L750)). You can enable [retries without changing queried host](https://github.com/apache/cassandra-gocql-driver/blob/trunk/policies.go#L128). This way you will be limited by only your `RetryPolicy` options like number of attempts. But obviously this is not so reliable We've implemented a wrapper for `HostSelectionPolicy` in order to wait for available hosts forever (but, sure, you can change it). Not the best implementation, but suitable for any host selection policy. Can be used for instnace this way ```go HostSelectionPolicy: &EndlessHostSelectionPolicy{gocql.RoundRobinHostPolicy()} ``` And the implementation ```go type EndlessHostSelectionPolicy struct { HostPolicy gocql.HostSelectionPolicy } var _ gocql.HostSelectionPolicy = (*EndlessHostSelectionPolicy)(nil) func (p *EndlessHostSelectionPolicy) Pick(q gocql.ExecutableQuery) gocql.NextHost { hostIter := p.HostPolicy.Pick(q) return func() gocql.SelectedHost { host := hostIter() for host == nil { time.Sleep(time.Second) // without sleep this will become active waiting hostIter = p.HostPolicy.Pick(q) host = hostIter() } return host } } func (p *EndlessHostSelectionPolicy) IsLocal(host *gocql.HostInfo) bool { return p.HostPolicy.IsLocal(host) } func (p *EndlessHostSelectionPolicy) Init(session *gocql.Session) { p.HostPolicy.Init(session) } func (p *EndlessHostSelectionPolicy) KeyspaceChanged(ev gocql.KeyspaceUpdateEvent) { p.HostPolicy.KeyspaceChanged(ev) } func (p *EndlessHostSelectionPolicy) SetPartitioner(partitioner string) { p.HostPolicy.SetPartitioner(partitioner) } func (p *EndlessHostSelectionPolicy) AddHost(host *gocql.HostInfo) { p.HostPolicy.AddHost(host) } func (p *EndlessHostSelectionPolicy) RemoveHost(host *gocql.HostInfo) { p.HostPolicy.RemoveHost(host) } func (p *EndlessHostSelectionPolicy) HostUp(host *gocql.HostInfo) { p.HostPolicy.HostUp(host) } func (p *EndlessHostSelectionPolicy) HostDown(host *gocql.HostInfo) { p.HostPolicy.HostDown(host) } ``` -- 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]
