From 987e2a6cd8a86c764ac02b7088c419c430482ed3 Mon Sep 17 00:00:00 2001 From: Tanjin Xu <109303790+tanjinx@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:03:48 -0700 Subject: [PATCH] Disable super_read_only during PRS for v15->v19 migration (#535) * Add use_super_read_only back for v15->v19 migration --- go/flags/endtoend/vttablet.txt | 1 + .../vttablet/tabletmanager/rpc_replication.go | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/go/flags/endtoend/vttablet.txt b/go/flags/endtoend/vttablet.txt index 85f8c3d741c..b887be36e63 100644 --- a/go/flags/endtoend/vttablet.txt +++ b/go/flags/endtoend/vttablet.txt @@ -402,6 +402,7 @@ Flags: --tx_throttler_config string The configuration of the transaction throttler as a text-formatted throttlerdata.Configuration protocol buffer message. (default "target_replication_lag_sec:2 max_replication_lag_sec:10 initial_rate:100 max_increase:1 emergency_decrease:0.5 min_duration_between_increases_sec:40 max_duration_between_increases_sec:62 min_duration_between_decreases_sec:20 spread_backlog_across_sec:20 age_bad_rate_after_sec:180 bad_rate_increase:0.1 max_rate_approach_threshold:0.9") --tx_throttler_healthcheck_cells strings A comma-separated list of cells. Only tabletservers running in these cells will be monitored for replication lag by the transaction throttler. --unhealthy_threshold duration replication lag after which a replica is considered unhealthy (default 2h0m0s) + --use_super_read_only Set super_read_only flag when performing planned failover. --v Level log level for V logs -v, --version print binary version --vmodule vModuleFlag comma-separated list of pattern=N settings for file-filtered logging diff --git a/go/vt/vttablet/tabletmanager/rpc_replication.go b/go/vt/vttablet/tabletmanager/rpc_replication.go index ff8cb3a9b57..7265b10faad 100644 --- a/go/vt/vttablet/tabletmanager/rpc_replication.go +++ b/go/vt/vttablet/tabletmanager/rpc_replication.go @@ -22,6 +22,8 @@ import ( "strings" "time" + "github.com/spf13/pflag" + "vitess.io/vitess/go/mysql/replication" "vitess.io/vitess/go/mysql/sqlerror" "vitess.io/vitess/go/protoutil" @@ -30,6 +32,7 @@ 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" @@ -37,6 +40,16 @@ import ( 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 { @@ -528,10 +541,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 } }