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

TER should not demote current master if it is run with current master #5210

Merged
merged 1 commit into from
Sep 21, 2019
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
5 changes: 3 additions & 2 deletions go/vt/vttablet/tabletmanager/rpc_external_reparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ func (agent *ActionAgent) finalizeTabletExternallyReparented(ctx context.Context
}
}()

if !topoproto.TabletAliasIsZero(oldMasterAlias) {
// If TER is called twice, then oldMasterAlias is the same as agent.TabletAlias
if !topoproto.TabletAliasIsZero(oldMasterAlias) && !topoproto.TabletAliasEqual(oldMasterAlias, agent.TabletAlias) {
wg.Add(1)
go func() {
defer wg.Done()
Expand Down Expand Up @@ -237,7 +238,7 @@ func (agent *ActionAgent) finalizeTabletExternallyReparented(ctx context.Context

tmc := tmclient.NewTabletManagerClient()
defer tmc.Close()
if !topoproto.TabletAliasIsZero(oldMasterAlias) && oldMasterTablet != nil {
if !topoproto.TabletAliasIsZero(oldMasterAlias) && !topoproto.TabletAliasEqual(oldMasterAlias, agent.TabletAlias) && oldMasterTablet != nil {
wg.Add(1)
go func() {
defer wg.Done()
Expand Down
68 changes: 68 additions & 0 deletions go/vt/wrangler/testlib/reparent_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,74 @@ func TestTabletExternallyReparentedFailedImpostorMaster(t *testing.T) {
}
}

func TestTabletExternallyReparentedRerun(t *testing.T) {
tabletmanager.SetReparentFlags(time.Minute /* finalizeTimeout */)

ctx := context.Background()
ts := memorytopo.NewServer("cell1", "cell2")
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient())

// Create an old master, a new master, and a good slave.
oldMaster := NewFakeTablet(t, wr, "cell1", 0, topodatapb.TabletType_MASTER, nil)
newMaster := NewFakeTablet(t, wr, "cell1", 1, topodatapb.TabletType_REPLICA, nil)
goodSlave := NewFakeTablet(t, wr, "cell1", 2, topodatapb.TabletType_REPLICA, nil)

// Reparent to a replica, and pretend the old master is not responding.

// On the elected master, we will respond to
// TabletActionSlaveWasPromoted.
newMaster.StartActionLoop(t, wr)
defer newMaster.StopActionLoop(t)

// On the old master, we will only respond to
// TabletActionSlaveWasRestarted.
oldMaster.StartActionLoop(t, wr)
defer oldMaster.StopActionLoop(t)

// On the good slave, we will respond to
// TabletActionSlaveWasRestarted.
goodSlave.StartActionLoop(t, wr)
defer goodSlave.StopActionLoop(t)

// The reparent should work as expected here
tmc := tmclient.NewTabletManagerClient()
ti, err := ts.GetTablet(ctx, newMaster.Tablet.Alias)
if err != nil {
t.Fatalf("GetTablet failed: %v", err)
}
waitID := makeWaitID()
if err := tmc.TabletExternallyReparented(context.Background(), ti.Tablet, waitID); err != nil {
t.Fatalf("TabletExternallyReparented(replica) failed: %v", err)
}
waitForExternalReparent(t, "TestTabletExternallyReparentedFailedOldMaster: good case", waitID)

// check the old master was converted to replica
tablet, err := ts.GetTablet(ctx, oldMaster.Tablet.Alias)
if err != nil {
t.Fatalf("GetTablet(%v) failed: %v", oldMaster.Tablet.Alias, err)
}
if tablet.Type != topodatapb.TabletType_REPLICA {
t.Fatalf("old master should be replica but is: %v", tablet.Type)
}

// run TER again and make sure the master is still correct
waitID = makeWaitID()
if err := tmc.TabletExternallyReparented(context.Background(), ti.Tablet, waitID); err != nil {
t.Fatalf("TabletExternallyReparented(replica) failed: %v", err)
}
waitForExternalReparent(t, "TestTabletExternallyReparentedFailedOldMaster: good case", waitID)

// check the new master is still master
tablet, err = ts.GetTablet(ctx, newMaster.Tablet.Alias)
if err != nil {
t.Fatalf("GetTablet(%v) failed: %v", newMaster.Tablet.Alias, err)
}
if tablet.Type != topodatapb.TabletType_MASTER {
t.Fatalf("new master should be MASTER but is: %v", tablet.Type)
}

}

var (
externalReparents = make(map[string]chan struct{})
externalReparentsMutex sync.Mutex
Expand Down