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

tm: call setReadOnly inside ChangeTabletType #6762

Merged
merged 2 commits into from
Sep 22, 2020
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
10 changes: 3 additions & 7 deletions go/test/endtoend/tabletmanager/tablet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ func TestEnsureDB(t *testing.T) {
err = clusterInstance.VtctlclientProcess.ExecuteCommand("TabletExternallyReparented", tablet.Alias)
require.NoError(t, err)

// It will still fail because the db is read-only.
assert.Equal(t, "NOT_SERVING", tablet.VttabletProcess.GetTabletStatus())
// It goes SERVING because TER calls ChangeTabletType which will also set the database to read-write
assert.Equal(t, "SERVING", tablet.VttabletProcess.GetTabletStatus())
status := tablet.VttabletProcess.GetStatusDetails()
assert.Contains(t, status, "read-only")
assert.Contains(t, status, "Serving")

// Switch to read-write and verify that that we go serving.
_ = clusterInstance.VtctlclientProcess.ExecuteCommand("SetReadWrite", tablet.Alias)
err = tablet.VttabletProcess.WaitForTabletType("SERVING")
require.NoError(t, err)
killTablets(t, tablet)
}

Expand Down
10 changes: 0 additions & 10 deletions go/vt/vttablet/tabletmanager/rpc_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,6 @@ func (tm *TabletManager) InitMaster(ctx context.Context) (string, error) {
// Set the server read-write, from now on we can accept real
// client writes. Note that if semi-sync replication is enabled,
// we'll still need some replicas to be able to commit transactions.
if err := tm.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}

if err := tm.changeTypeLocked(ctx, topodatapb.TabletType_MASTER); err != nil {
return "", err
}
Expand Down Expand Up @@ -741,12 +737,6 @@ func (tm *TabletManager) PromoteReplica(ctx context.Context) (string, error) {
return "", err
}

// We call SetReadOnly only after the topo has been updated to avoid
// situations where two tablets are master at the DB level but not at the vitess level
if err := tm.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}

return mysql.EncodePosition(pos), nil
}

Expand Down
5 changes: 5 additions & 0 deletions go/vt/vttablet/tabletmanager/tm_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ func (ts *tmState) ChangeTabletType(ctx context.Context, tabletType topodatapb.T
if err != nil {
return err
}
// We call SetReadOnly only after the topo has been updated to avoid
// situations where two tablets are master at the DB level but not at the vitess level
if err := ts.tm.MysqlDaemon.SetReadOnly(false); err != nil {
return err
}

ts.tablet.Type = tabletType
ts.tablet.MasterTermStartTime = masterTermStartTime
Expand Down