Skip to content
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
2 changes: 1 addition & 1 deletion pkg/owner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ go_test(
],
embed = [":owner"],
flaky = True,
shard_count = 8,
shard_count = 9,
deps = [
"//pkg/ddl",
"//pkg/infoschema",
Expand Down
8 changes: 4 additions & 4 deletions pkg/owner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ func (m *ownerManager) CampaignOwner(withTTL ...int) error {
}
m.sessionLease.Store(int64(session.Lease()))
m.wg.Add(1)
go m.campaignLoop(session)
var campaignContext context.Context
campaignContext, m.campaignCancel = context.WithCancel(m.ctx)
go m.campaignLoop(campaignContext, session)
return nil
}

Expand Down Expand Up @@ -241,9 +243,7 @@ func (m *ownerManager) CampaignCancel() {
m.wg.Wait()
}

func (m *ownerManager) campaignLoop(etcdSession *concurrency.Session) {
var campaignContext context.Context
campaignContext, m.campaignCancel = context.WithCancel(m.ctx)
func (m *ownerManager) campaignLoop(campaignContext context.Context, etcdSession *concurrency.Session) {
defer func() {
m.campaignCancel()
if r := recover(); r != nil {
Expand Down
17 changes: 17 additions & 0 deletions pkg/owner/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,23 @@ func deleteLeader(cli *clientv3.Client, prefixKey string) error {
return errors.Trace(err)
}

func TestImmediatelyCancel(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("integration.NewClusterV3 will create file contains a colon which is not allowed on Windows")
}
integration.BeforeTestExternal(t)

tInfo := newTestInfo(t)
d := tInfo.ddl
defer tInfo.Close(t)
ownerManager := d.OwnerManager()
for i := 0; i < 10; i++ {
err := ownerManager.CampaignOwner()
require.NoError(t, err)
ownerManager.CampaignCancel()
}
}

func TestAcquireDistributedLock(t *testing.T) {
const addrFmt = "http://127.0.0.1:%d"
cfg := embed.NewConfig()
Expand Down