Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove locks for tablets flag on Conn #196

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ type Conn struct {
timeouts int64

logger StdLogger
tabletsRoutingV1 bool
tabletsRoutingV1 int32
}

// connect establishes a connection to a Cassandra node using session's connection config.
Expand Down Expand Up @@ -604,6 +604,18 @@ func (c *Conn) closeWithError(err error) {
}
}

func (c *Conn) isTabletSupported() bool {
return atomic.LoadInt32(&c.tabletsRoutingV1) == 1
}

func (c *Conn) setTabletSupported(val bool) {
intVal := int32(0)
if val {
intVal = 1
}
atomic.StoreInt32(&c.tabletsRoutingV1, intVal)
}

func (c *Conn) close() error {
return c.conn.Close()
}
Expand Down Expand Up @@ -725,9 +737,7 @@ func (c *Conn) recv(ctx context.Context) error {
} else if head.stream == -1 {
// TODO: handle cassandra event frames, we shouldnt get any currently
framer := newFramerWithExts(c.compressor, c.version, c.cqlProtoExts)
c.mu.Lock()
c.tabletsRoutingV1 = framer.tabletsRoutingV1
c.mu.Unlock()
c.setTabletSupported(framer.tabletsRoutingV1)
if err := framer.readFrame(c, &head); err != nil {
return err
}
Expand All @@ -737,9 +747,7 @@ func (c *Conn) recv(ctx context.Context) error {
// reserved stream that we dont use, probably due to a protocol error
// or a bug in Cassandra, this should be an error, parse it and return.
framer := newFramerWithExts(c.compressor, c.version, c.cqlProtoExts)
c.mu.Lock()
c.tabletsRoutingV1 = framer.tabletsRoutingV1
c.mu.Unlock()
c.setTabletSupported(framer.tabletsRoutingV1)
if err := framer.readFrame(c, &head); err != nil {
return err
}
Expand Down Expand Up @@ -1076,9 +1084,7 @@ func (c *Conn) exec(ctx context.Context, req frameBuilder, tracer Tracer) (*fram

// resp is basically a waiting semaphore protecting the framer
framer := newFramerWithExts(c.compressor, c.version, c.cqlProtoExts)
c.mu.Lock()
c.tabletsRoutingV1 = framer.tabletsRoutingV1
c.mu.Unlock()
c.setTabletSupported(framer.tabletsRoutingV1)

call := &callReq{
timeout: make(chan struct{}),
Expand Down
4 changes: 1 addition & 3 deletions scylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ func (p *scyllaConnPicker) Pick(t Token, keyspace string, table string) *Conn {
continue
}

conn.mu.Lock()
if conn.tabletsRoutingV1 {
if conn.isTabletSupported() {
tablets := conn.session.getTablets()

// Search for tablets with Keyspace and Table from the Query
Expand All @@ -392,7 +391,6 @@ func (p *scyllaConnPicker) Pick(t Token, keyspace string, table string) *Conn {
}
}
}
conn.mu.Unlock()

break
}
Expand Down
2 changes: 1 addition & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (s *Session) init() error {
return err
}
s.control.getConn().conn.mu.Lock()
s.tabletsRoutingV1 = s.control.getConn().conn.tabletsRoutingV1
s.tabletsRoutingV1 = s.control.getConn().conn.isTabletSupported()
s.control.getConn().conn.mu.Unlock()

if !s.cfg.DisableInitialHostLookup {
Expand Down
Loading