Skip to content

Commit

Permalink
*: fix data race at the mockOwnerOpValue (#45107)
Browse files Browse the repository at this point in the history
close #45106
  • Loading branch information
hawkingrei authored Jul 3, 2023
1 parent b9671dc commit ab63aeb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion owner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func (m *ownerManager) SetOwnerOpValue(ctx context.Context, op OpType) error {
func GetOwnerOpValue(ctx context.Context, etcdCli *clientv3.Client, ownerPath, logPrefix string) (OpType, error) {
// It's using for testing.
if etcdCli == nil {
return mockOwnerOpValue, nil
return *mockOwnerOpValue.Load(), nil
}

logCtx := logutil.WithKeyValue(context.Background(), "owner info", logPrefix)
Expand Down
5 changes: 3 additions & 2 deletions owner/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package owner
import (
"context"
"sync"
"sync/atomic"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -105,10 +106,10 @@ func (m *mockManager) GetOwnerID(_ context.Context) (string, error) {
return "", errors.New("no owner")
}

var mockOwnerOpValue = OpNone
var mockOwnerOpValue atomic.Pointer[OpType]

func (*mockManager) SetOwnerOpValue(_ context.Context, op OpType) error {
mockOwnerOpValue = op
mockOwnerOpValue.Store(&op)
return nil
}

Expand Down

0 comments on commit ab63aeb

Please sign in to comment.