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

[release-17.0] CI: Address data races on memorytopo Conn.closed (#15365) #15369

Merged
merged 3 commits into from
Feb 27, 2024
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
8 changes: 4 additions & 4 deletions go/vt/topo/memorytopo/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// NewLeaderParticipation is part of the topo.Server interface
func (c *Conn) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error) {
if c.closed {
if c.closed.Load() {
return nil, ErrConnectionClosed
}

Expand Down Expand Up @@ -72,7 +72,7 @@ type cLeaderParticipation struct {

// WaitForLeadership is part of the topo.LeaderParticipation interface.
func (mp *cLeaderParticipation) WaitForLeadership() (context.Context, error) {
if mp.c.closed {
if mp.c.closed.Load() {
return nil, ErrConnectionClosed
}

Expand Down Expand Up @@ -120,7 +120,7 @@ func (mp *cLeaderParticipation) Stop() {

// GetCurrentLeaderID is part of the topo.LeaderParticipation interface
func (mp *cLeaderParticipation) GetCurrentLeaderID(ctx context.Context) (string, error) {
if mp.c.closed {
if mp.c.closed.Load() {
return "", ErrConnectionClosed
}

Expand All @@ -139,7 +139,7 @@ func (mp *cLeaderParticipation) GetCurrentLeaderID(ctx context.Context) (string,

// WaitForNewLeader is part of the topo.LeaderParticipation interface
func (mp *cLeaderParticipation) WaitForNewLeader(ctx context.Context) (<-chan string, error) {
if mp.c.closed {
if mp.c.closed.Load() {
return nil, ErrConnectionClosed
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/topo/memorytopo/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (ld *memoryTopoLockDescriptor) Unlock(ctx context.Context) error {
}

func (c *Conn) unlock(ctx context.Context, dirPath string) error {
if c.closed {
if c.closed.Load() {
return ErrConnectionClosed
}

Expand Down
7 changes: 4 additions & 3 deletions go/vt/topo/memorytopo/memorytopo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"math/rand"
"strings"
"sync"
"sync/atomic"
"time"

"vitess.io/vitess/go/vt/log"
Expand Down Expand Up @@ -124,14 +125,14 @@ type Conn struct {
factory *Factory
cell string
serverAddr string
closed bool
closed atomic.Bool
}

// dial returns immediately, unless the Conn points to the sentinel
// UnreachableServerAddr, in which case it will block until the context expires
// and return the context's error.
func (c *Conn) dial(ctx context.Context) error {
if c.closed {
if c.closed.Load() {
return ErrConnectionClosed
}
if c.serverAddr == UnreachableServerAddr {
Expand All @@ -144,7 +145,7 @@ func (c *Conn) dial(ctx context.Context) error {

// Close is part of the topo.Conn interface.
func (c *Conn) Close() {
c.closed = true
c.closed.Store(true)
}

type watch struct {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/topo/memorytopo/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

// Watch is part of the topo.Conn interface.
func (c *Conn) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, error) {
if c.closed {
if c.closed.Load() {
return nil, nil, ErrConnectionClosed
}

Expand Down Expand Up @@ -75,7 +75,7 @@ func (c *Conn) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-c

// WatchRecursive is part of the topo.Conn interface.
func (c *Conn) WatchRecursive(ctx context.Context, dirpath string) ([]*topo.WatchDataRecursive, <-chan *topo.WatchDataRecursive, error) {
if c.closed {
if c.closed.Load() {
return nil, nil, ErrConnectionClosed
}

Expand Down
Loading