You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Rikkuru (via GitHub)" <gi...@apache.org> on 2024/09/02 15:50:11 UTC
Re: [I] gocql RetryPolicies still don't use query idempotence [cassandra-gocql-driver]
Rikkuru commented on issue #1803:
URL: https://github.com/apache/cassandra-gocql-driver/issues/1803#issuecomment-2325019139
> Please share an exec query you are using to reproduce the issue, if you tried multiple queries provide them as well.
Hi I have an axample
main.go (go 1.21.11 , github.com/gocql/gocql v1.6.0)
there is a loop to wait for scylladb start and second loop to have time to down one of the nodes
```
package main
import (
"context"
"fmt"
"time"
"github.com/gocql/gocql"
)
type MyRetryPolicy struct {
}
func (*MyRetryPolicy) Attempt(q gocql.RetryableQuery) bool {
if q.Attempts() > 2 {
return false
}
return true
}
func (*MyRetryPolicy) GetRetryType(error) gocql.RetryType {
return gocql.Retry
}
type LoggingObserver struct{}
func (*LoggingObserver) ObserveQuery(ctx context.Context, q gocql.ObservedQuery) {
fmt.Printf("observer attempt: %d err: %s\n", q.Attempt, q.Err)
}
func main() {
cluster := gocql.NewCluster("some-scylla", "some-scylla3", "some-scylla2")
var err error
var s *gocql.Session
for i := 1; i <= 100; i++ {
fmt.Printf("%d attempt\n", i)
s, err = gocql.NewSession(*cluster)
if err == nil {
break
}
time.Sleep(1 * time.Second)
}
if err != nil {
fmt.Printf("session err: %s\n", err)
return
}
defer s.Close()
fmt.Printf("CONNECTED!")
time.Sleep(60 * time.Second)
for i := 1; i <= 100; i++ {
q := s.Query("INSERT INTO mykeyspace.events(event_id, time, args) VALUES (?,?,?)", 1, gocql.UUIDFromTime(time.Now()), "test")
q.RetryPolicy(&MyRetryPolicy{})
q.Observer(&LoggingObserver{})
q.Consistency(gocql.All)
fmt.Printf("%d QUERY IsIdempotent: %v\n", i, q.IsIdempotent())
err = q.Exec()
if err != nil {
fmt.Printf("exec err: %s\n", err)
}
time.Sleep(1 * time.Second)
}
}
```
cql init for scylla
```
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': '3'} AND durable_writes = true;
CREATE TABLE mykeyspace.events (event_id int, time timeuuid, args text, PRIMARY KEY ((event_id), time));
```
docker-compose for nodes and main.go
```
version: '3'
services:
some-scylla:
image: scylladb/scylla:5.1
container_name: some-scylla
command: --overprovisioned 1 --smp 1
ports:
- 9042:9042
some-scylla2:
image: scylladb/scylla:5.1
container_name: some-scylla2
command: --seeds=some-scylla --overprovisioned 1 --smp 1
some-scylla3:
image: scylladb/scylla:5.1
container_name: some-scylla3
command: --seeds=some-scylla --overprovisioned 1 --smp 1
myapp2:
image: golang:1.21.11
container_name: myapp2
command: go run /app/main.go
working_dir: /app
volumes:
- ./:/app
```
I can see in log that query is retried
```
2024-09-02 18:40:30 90 QUERY IsIdempotent: false
2024-09-02 18:40:30 observer attempt: 0 err: Cannot achieve consistency level for cl ALL. Requires 3, alive 2
2024-09-02 18:40:30 observer attempt: 1 err: Cannot achieve consistency level for cl ALL. Requires 3, alive 2
2024-09-02 18:40:30 observer attempt: 2 err: Cannot achieve consistency level for cl ALL. Requires 3, alive 2
2024-09-02 18:40:30 exec err: Cannot achieve consistency level for cl ALL. Requires 3, alive 2
```
--
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: commits-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org