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

Deprecate twopc_enable flag and change input type for twopc_abandon_age to time.Duration #17279

Merged
merged 9 commits into from
Dec 9, 2024
8 changes: 8 additions & 0 deletions changelog/22.0/22.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
### Table of Contents

- **[Major Changes](#major-changes)**
- **[Deprecations and Deletions](#deprecations-and-deletions)**
- [Deprecated VTTablet Flags](#vttablet-flags)
- **[RPC Changes](#rpc-changes)**
- **[Prefer not promoting a replica that is currently taking a backup](#reparents-prefer-not-backing-up)**

Expand All @@ -15,6 +17,12 @@ These are the RPC changes made in this release -

1. `GetTransactionInfo` RPC has been added to both `VtctldServer`, and `TabletManagerClient` interface. These RPCs are used to fecilitate the users in reading the state of an unresolved distributed transaction. This can be useful in debugging what went wrong and how to fix the problem.

### <a id="deprecations-and-deletions"/>Deprecations and Deletions</a>

#### <a id="vttablet-flags"/>Deprecated VTTablet Flags</a>

- `twopc_enable` flag is deprecated, `twopc_abandonage` flag if set will be used to determine if 2PC is enabled or not.
Copy link
Member

@deepthi deepthi Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we really determining whether to allow 2PC based on twopc_abandonage? Ideally it should be controlled solely by transaction_mode on vtgate, and vttablets should be able to participate.
My suggestion would be to pick a reasonable default for twopc_abandonage and use that. Also we should be changing that to a Duration field instead of float which I assume is being interpreted as seconds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Deepthi. There is no reason to say explicitly whether twopc is enabled or not. If the transaction mode is twopc then we run it, otherwise not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For first part - I am aligned with it. Just did not do it in one go.

Changing from seconds to Duration, this would mean a breaking change otherwise would have to add a new flag.

Copy link
Member

@deepthi deepthi Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's some prior art on how to change this over 2 releases without changing the flag name. you should be able to find the relevant PRs in GH history.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done dfcd94c


### <a id="reparents-prefer-not-backing-up"/>Prefer not promoting a replica that is currently taking a backup

Emergency reparents now prefer not promoting replicas that are currently taking backups with a backup engine other than
Expand Down
1 change: 0 additions & 1 deletion go/flags/endtoend/vtcombo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ Flags:
--transaction_mode string SINGLE: disallow multi-db transactions, MULTI: allow multi-db transactions with best effort commit, TWOPC: allow multi-db transactions with 2pc commit (default "MULTI")
--truncate-error-len int truncate errors sent to client if they are longer than this value (0 means do not truncate)
--twopc_abandon_age float time in seconds. Any unresolved transaction older than this time will be sent to the coordinator to be resolved.
--twopc_enable if the flag is on, 2pc is enabled. Other 2pc flags must be supplied.
--tx-throttler-config string Synonym to -tx_throttler_config (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-default-priority int Default priority assigned to queries that lack priority information (default 100)
--tx-throttler-dry-run If present, the transaction throttler only records metrics about requests received and throttled, but does not actually throttle any requests.
Expand Down
1 change: 0 additions & 1 deletion go/flags/endtoend/vttablet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ Flags:
--transaction_limit_by_username Include VTGateCallerID.username when considering who the user is for the purpose of transaction limit. (default true)
--transaction_limit_per_user float Maximum number of transactions a single user is allowed to use at any time, represented as fraction of -transaction_cap. (default 0.4)
--twopc_abandon_age float time in seconds. Any unresolved transaction older than this time will be sent to the coordinator to be resolved.
--twopc_enable if the flag is on, 2pc is enabled. Other 2pc flags must be supplied.
--tx-throttler-config string Synonym to -tx_throttler_config (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-default-priority int Default priority assigned to queries that lack priority information (default 100)
--tx-throttler-dry-run If present, the transaction throttler only records metrics about requests received and throttled, but does not actually throttle any requests.
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/tabletmanager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func TestMain(m *testing.M) {
"--heartbeat_enable",
"--health_check_interval", tabletHealthcheckRefreshInterval.String(),
"--unhealthy_threshold", tabletUnhealthyThreshold.String(),
"--twopc_enable",
"--twopc_abandon_age", "200",
}

Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/transaction/twopc/fuzz/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func TestMain(m *testing.M) {
"--tablet_refresh_interval", "2s",
)
clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs,
"--twopc_enable",
"--twopc_abandon_age", "1",
"--migration_check_interval", "2s",
)
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/transaction/twopc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func TestMain(m *testing.M) {
"--grpc_use_effective_callerid",
)
clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs,
"--twopc_enable",
"--twopc_abandon_age", "1",
"--queryserver-config-transaction-cap", "3",
"--queryserver-config-transaction-timeout", "400s",
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/transaction/twopc/metric/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func TestMain(m *testing.M) {
"--grpc_use_effective_callerid",
)
clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs,
"--twopc_enable",
"--twopc_abandon_age", "1",
"--queryserver-config-transaction-cap", "100",
)
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/transaction/twopc/stress/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func TestMain(m *testing.M) {
"--tablet_refresh_interval", "2s",
)
clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs,
"--twopc_enable",
"--twopc_abandon_age", "1",
"--migration_check_interval", "2s",
"--onterm_timeout", "1s",
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/transaction/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func TestMain(m *testing.M) {
clusterInstance.VtgateGrpcPort = clusterInstance.GetAndReservePort()
// Set extra tablet args for twopc
clusterInstance.VtTabletExtraArgs = []string{
"--twopc_enable",
"--twopc_abandon_age", "3600",
}

Expand Down
1 change: 0 additions & 1 deletion go/vt/vtexplain/vtexplain_vttablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func (vte *VTExplain) newTablet(ctx context.Context, env *vtenv.Environment, opt
config.TrackSchemaVersions = false
if opts.ExecutionMode == ModeTwoPC {
config.TwoPCAbandonAge = 1.0
config.TwoPCEnable = true
}
config.EnableOnlineDDL = false
config.EnableTableGC = false
Expand Down
1 change: 0 additions & 1 deletion go/vt/vttablet/endtoend/connecttcp/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func TestMain(m *testing.M) {
defer cancel()

config := tabletenv.NewDefaultConfig()
config.TwoPCEnable = true
config.TwoPCAbandonAge = 1

if err := framework.StartCustomServer(ctx, connParams, connAppDebugParams, cluster.DbName(), config); err != nil {
Expand Down
1 change: 0 additions & 1 deletion go/vt/vttablet/endtoend/framework/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func StartCustomServer(ctx context.Context, connParams, connAppDebugParams mysql
func StartServer(ctx context.Context, connParams, connAppDebugParams mysql.ConnParams, dbName string) error {
config := tabletenv.NewDefaultConfig()
config.StrictTableACL = true
config.TwoPCEnable = true
config.TwoPCAbandonAge = 1
config.HotRowProtection.Mode = tabletenv.Enable
config.TrackSchemaVersions = true
Expand Down
1 change: 0 additions & 1 deletion go/vt/vttablet/endtoend/twopc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func TestMain(m *testing.M) {
defer cancel()

config := tabletenv.NewDefaultConfig()
config.TwoPCEnable = true
config.TwoPCAbandonAge = 1
err := framework.StartCustomServer(ctx, connParams, connAppDebugParams, cluster.DbName(), config)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions go/vt/vttablet/tabletserver/dt_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,10 @@ func TestNoTwopc(t *testing.T) {

want := "2pc is not enabled"
for _, tc := range testcases {
err := tc.fun()
require.EqualError(t, err, want)
t.Run(tc.desc, func(t *testing.T) {
err := tc.fun()
require.EqualError(t, err, want)
})
}
}

Expand Down
9 changes: 3 additions & 6 deletions go/vt/vttablet/tabletserver/query_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,17 +1514,14 @@ func newTestTabletServer(ctx context.Context, flags executorFlags, db *fakesqldb
} else {
cfg.StrictTableACL = false
}
if flags&noTwopc > 0 {
cfg.TwoPCEnable = false
} else {
cfg.TwoPCEnable = true
}
if flags&disableOnlineDDL > 0 {
cfg.EnableOnlineDDL = false
} else {
cfg.EnableOnlineDDL = true
}
if flags&shortTwopcAge > 0 {
if flags&noTwopc > 0 {
cfg.TwoPCAbandonAge = 0
} else if flags&shortTwopcAge > 0 {
cfg.TwoPCAbandonAge = 0.5
} else {
cfg.TwoPCAbandonAge = 10
Expand Down
8 changes: 6 additions & 2 deletions go/vt/vttablet/tabletserver/tabletenv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ func registerTabletEnvFlags(fs *pflag.FlagSet) {
fs.BoolVar(&currentConfig.WatchReplication, "watch_replication_stream", false, "When enabled, vttablet will stream the MySQL replication stream from the local server, and use it to update schema when it sees a DDL.")
fs.BoolVar(&currentConfig.TrackSchemaVersions, "track_schema_versions", false, "When enabled, vttablet will store versions of schemas at each position that a DDL is applied and allow retrieval of the schema corresponding to a position")
fs.Int64Var(&currentConfig.SchemaVersionMaxAgeSeconds, "schema-version-max-age-seconds", 0, "max age of schema version records to kept in memory by the vreplication historian")
fs.BoolVar(&currentConfig.TwoPCEnable, "twopc_enable", defaultConfig.TwoPCEnable, "if the flag is on, 2pc is enabled. Other 2pc flags must be supplied.")

_ = fs.Bool("twopc_enable", true, "TwoPC is enabled")
_ = fs.MarkDeprecated("twopc_enable", "TwoPC is always enabled, the transaction abandon age can be configured")
SecondsVar(fs, &currentConfig.TwoPCAbandonAge, "twopc_abandon_age", defaultConfig.TwoPCAbandonAge, "time in seconds. Any unresolved transaction older than this time will be sent to the coordinator to be resolved.")

// Tx throttler config
flagutil.DualFormatBoolVar(fs, &currentConfig.EnableTxThrottler, "enable_tx_throttler", defaultConfig.EnableTxThrottler, "If true replication-lag-based throttling on transactions will be enabled.")
flagutil.DualFormatVar(fs, currentConfig.TxThrottlerConfig, "tx_throttler_config", "The configuration of the transaction throttler as a text-formatted throttlerdata.Configuration protocol buffer message.")
Expand Down Expand Up @@ -335,7 +338,6 @@ type TabletConfig struct {
StrictTableACL bool `json:"-"`
EnableTableACLDryRun bool `json:"-"`
TableACLExemptACL string `json:"-"`
TwoPCEnable bool `json:"-"`
TwoPCAbandonAge Seconds `json:"-"`

EnableTxThrottler bool `json:"-"`
Expand Down Expand Up @@ -1054,6 +1056,8 @@ var defaultConfig = TabletConfig{
},

EnablePerWorkloadTableMetrics: false,

// TwoPCAbandonAge: Seconds((10 * time.Minute).Seconds()),
}

// defaultTxThrottlerConfig returns the default TxThrottlerConfigFlag object based on
Expand Down
13 changes: 6 additions & 7 deletions go/vt/vttablet/tabletserver/tx_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,18 @@ func NewTxEngine(env tabletenv.Env, dxNotifier func()) *TxEngine {
te.txPool = NewTxPool(env, limiter)
// We initially allow twoPC (handles vttablet restarts).
// We will disallow them for a few reasons -
// 1. when a new tablet is promoted if semi-sync is turned off.
// 1. When a new tablet is promoted if semi-sync is turned off.
// 2. TabletControls have been set by a Resharding workflow.
te.twopcAllowed = make([]bool, TwoPCAllowed_Len)
for idx := range te.twopcAllowed {
te.twopcAllowed[idx] = true
}
te.twopcEnabled = config.TwoPCEnable
if te.twopcEnabled {
if config.TwoPCAbandonAge <= 0 {
log.Error("2PC abandon age not specified: Disabling 2PC")
te.twopcEnabled = false
}
te.twopcEnabled = true
if config.TwoPCAbandonAge <= 0 {
log.Error("2PC abandon age not specified: Disabling 2PC")
te.twopcEnabled = false
}

te.abandonAge = config.TwoPCAbandonAge.Get()
te.ticks = timer.NewTimer(te.abandonAge / 2)

Expand Down
2 changes: 0 additions & 2 deletions go/vt/vttablet/tabletserver/tx_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ func TestCheckReceivedError(t *testing.T) {
cfg := tabletenv.NewDefaultConfig()
cfg.DB = newDBConfigs(db)
env := tabletenv.NewEnv(vtenv.NewTestEnv(), cfg, "TabletServerTest")
env.Config().TwoPCEnable = true
env.Config().TwoPCAbandonAge = 5
te := NewTxEngine(env, nil)
te.AcceptReadWrite()
Expand Down Expand Up @@ -791,7 +790,6 @@ func TestPrepareTx(t *testing.T) {
db.AddRejectedQuery("retryable query", sqlerror.NewSQLError(sqlerror.CRConnectionError, "", "Retryable error"))
cfg := tabletenv.NewDefaultConfig()
cfg.DB = newDBConfigs(db)
cfg.TwoPCEnable = true
cfg.TwoPCAbandonAge = 200
te := NewTxEngine(tabletenv.NewEnv(vtenv.NewTestEnv(), cfg, "TabletServerTest"), nil)
te.AcceptReadWrite()
Expand Down
Loading