Skip to content

Commit

Permalink
Add use_super_read_only back for v15->v19 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjinx committed Oct 14, 2024
1 parent 9885ab0 commit 5671fa2
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions go/vt/vttablet/tabletmanager/rpc_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"
"time"

"github.com/spf13/pflag"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/mysql/sqlerror"
"vitess.io/vitess/go/protoutil"
Expand All @@ -30,13 +31,24 @@ import (
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/mysqlctl"
"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vterrors"

replicationdatapb "vitess.io/vitess/go/vt/proto/replicationdata"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
)

var setSuperReadOnly bool

func registerReplicationFlags(fs *pflag.FlagSet) {
fs.BoolVar(&setSuperReadOnly, "use_super_read_only", setSuperReadOnly, "Set super_read_only flag when performing planned failover.")
}

func init() {
servenv.OnParseFor("vttablet", registerReplicationFlags)
}

// ReplicationStatus returns the replication status
func (tm *TabletManager) ReplicationStatus(ctx context.Context) (*replicationdatapb.Status, error) {
if err := tm.waitForGrantsToHaveApplied(ctx); err != nil {
Expand Down Expand Up @@ -528,10 +540,16 @@ func (tm *TabletManager) demotePrimary(ctx context.Context, revertPartialFailure
// set MySQL to super_read_only mode. If we are already super_read_only because of a
// previous demotion, or because we are not primary anyway, this should be
// idempotent.
if _, err := tm.MysqlDaemon.SetSuperReadOnly(true); err != nil {
if sqlErr, ok := err.(*sqlerror.SQLError); ok && sqlErr.Number() == sqlerror.ERUnknownSystemVariable {
log.Warningf("server does not know about super_read_only, continuing anyway...")
} else {
if setSuperReadOnly {
if _, err := tm.MysqlDaemon.SetSuperReadOnly(true); err != nil {
if sqlErr, ok := err.(*sqlerror.SQLError); ok && sqlErr.Number() == sqlerror.ERUnknownSystemVariable {
log.Warningf("server does not know about super_read_only, continuing anyway...")
} else {
return nil, err
}
}
} else {
if err := tm.MysqlDaemon.SetReadOnly(true); err != nil {
return nil, err
}
}
Expand Down

0 comments on commit 5671fa2

Please sign in to comment.