Skip to content

Commit d1d1901

Browse files
Add unmanaged tablet flag at vttablet level (#14871)
Signed-off-by: Noble Mittal <[email protected]> Signed-off-by: Manan Gupta <[email protected]> Co-authored-by: Manan Gupta <[email protected]>
1 parent b7ef410 commit d1d1901

File tree

8 files changed

+111
-6
lines changed

8 files changed

+111
-6
lines changed

changelog/20.0/20.0.0/summary.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- **[Major Changes](#major-changes)**
66
- **[Breaking changes](#breaking-changes)**
77
- [`shutdown_grace_period` Default Change](#shutdown-grace-period-default)
8+
- [New `unmanaged` Flag and `disable_active_reparents` deprecation](#unmanaged-flag)
89
- **[Query Compatibility](#query-compatibility)**
910
- [Vindex Hints](#vindex-hints)
1011
- [Update with Limit Support](#update-limit)
@@ -31,6 +32,12 @@ This makes reparenting in Vitess resilient to client errors, and prevents Planne
3132

3233
In order to preserve the old behaviour, the users can set the flag back to `0 seconds` causing open transactions to never be shutdown, but in that case, they run the risk of PlannedReparentShard calls timing out.
3334

35+
#### <a id="unmanaged-tablet"/> New `unmanaged` Flag and `disable_active_reparents` deprecation
36+
37+
New flag `--unmanaged` has been introduced in this release to make it easier to flag unmanaged tablets. It also runs validations to make sure the unmanaged tablets are configured properly. `--disable_active_reparents` flag has been deprecated for `vttablet`, `vtcombo` and `vttestserver` binaries and will be removed in future releases. Specifying the `--unmanaged` flag will also block replication commands and replication repairs.
38+
39+
Starting this release, all unmanaged tablets should specify this flag.
40+
3441
### <a id="query-compatibility"/>Query Compatibility
3542

3643
#### <a id="vindex-hints"/> Vindex Hints

go/cmd/vttablet/cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ See "Unmanaged Tablet" for the full guide.
8282
Even if a MySQL is external, you can still make vttablet perform some management functions. They are as follows:
8383
8484
` +
85-
"* `--disable_active_reparents`: If this flag is set, then any reparent or replica commands will not be allowed. These are InitShardPrimary, PlannedReparentShard, EmergencyReparentShard, and ReparentTablet. In this mode, you should use the TabletExternallyReparented command to inform vitess of the current primary.\n" +
85+
"* `--unmanaged`: This flag indicates that this tablet is running in unmanaged mode. In this mode, any reparent or replica commands are not allowed. These are InitShardPrimary, PlannedReparentShard, EmergencyReparentShard, and ReparentTablet. You should use the TabletExternallyReparented command to inform vitess of the current primary.\n" +
8686
"* `--replication_connect_retry`: This value is give to mysql when it connects a replica to the primary as the retry duration parameter.\n" +
8787
"* `--heartbeat_enable` and `--heartbeat_interval duration`: cause vttablet to write heartbeats to the sidecar database. This information is also used by the replication reporter to assess replica lag.\n",
8888
Example: `

go/flags/endtoend/vtcombo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ Flags:
108108
--ddl_strategy string Set default strategy for DDL statements. Override with @@ddl_strategy session variable (default "direct")
109109
--default_tablet_type topodatapb.TabletType The default tablet type to set for queries, when one is not explicitly selected. (default PRIMARY)
110110
--degraded_threshold duration replication lag after which a replica is considered degraded (default 30s)
111-
--disable_active_reparents if set, do not allow active reparents. Use this to protect a cluster using external reparents.
112111
--emit_stats If set, emit stats to push-based monitoring and stats backends
113112
--enable-consolidator Synonym to -enable_consolidator (default true)
114113
--enable-consolidator-replicas Synonym to -enable_consolidator_replicas
@@ -397,6 +396,7 @@ Flags:
397396
--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")
398397
--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.
399398
--unhealthy_threshold duration replication lag after which a replica is considered unhealthy (default 2h0m0s)
399+
--unmanaged Indicates an unmanaged tablet, i.e. using an external mysql-compatible database
400400
--v Level log level for V logs
401401
-v, --version print binary version
402402
--vmodule vModuleFlag comma-separated list of pattern=N settings for file-filtered logging

go/flags/endtoend/vttablet.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See "Unmanaged Tablet" for the full guide.
1717

1818
Even if a MySQL is external, you can still make vttablet perform some management functions. They are as follows:
1919

20-
* `--disable_active_reparents`: If this flag is set, then any reparent or replica commands will not be allowed. These are InitShardPrimary, PlannedReparentShard, EmergencyReparentShard, and ReparentTablet. In this mode, you should use the TabletExternallyReparented command to inform vitess of the current primary.
20+
* `--unmanaged`: This flag indicates that this tablet is running in unmanaged mode. In this mode, any reparent or replica commands are not allowed. These are InitShardPrimary, PlannedReparentShard, EmergencyReparentShard, and ReparentTablet. You should use the TabletExternallyReparented command to inform vitess of the current primary.
2121
* `--replication_connect_retry`: This value is give to mysql when it connects a replica to the primary as the retry duration parameter.
2222
* `--heartbeat_enable` and `--heartbeat_interval duration`: cause vttablet to write heartbeats to the sidecar database. This information is also used by the replication reporter to assess replica lag.
2323

@@ -139,7 +139,6 @@ Flags:
139139
--dba_idle_timeout duration Idle timeout for dba connections (default 1m0s)
140140
--dba_pool_size int Size of the connection pool for dba connections (default 20)
141141
--degraded_threshold duration replication lag after which a replica is considered degraded (default 30s)
142-
--disable_active_reparents if set, do not allow active reparents. Use this to protect a cluster using external reparents.
143142
--emit_stats If set, emit stats to push-based monitoring and stats backends
144143
--enable-consolidator Synonym to -enable_consolidator (default true)
145144
--enable-consolidator-replicas Synonym to -enable_consolidator_replicas
@@ -398,6 +397,7 @@ Flags:
398397
--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")
399398
--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.
400399
--unhealthy_threshold duration replication lag after which a replica is considered unhealthy (default 2h0m0s)
400+
--unmanaged Indicates an unmanaged tablet, i.e. using an external mysql-compatible database
401401
--v Level log level for V logs
402402
-v, --version print binary version
403403
--vmodule vModuleFlag comma-separated list of pattern=N settings for file-filtered logging

go/flags/endtoend/vttestserver.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Flags:
3131
--dba_idle_timeout duration Idle timeout for dba connections (default 1m0s)
3232
--dba_pool_size int Size of the connection pool for dba connections (default 20)
3333
--default_schema_dir string Default directory for initial schema files. If no schema is found in schema_dir, default to this location.
34-
--disable_active_reparents if set, do not allow active reparents. Use this to protect a cluster using external reparents.
3534
--enable_direct_ddl Allow users to submit direct DDL statements (default true)
3635
--enable_online_ddl Allow users to submit, review and control Online DDL (default true)
3736
--enable_system_settings This will enable the system settings to be changed per session at the database connection level (default true)

go/vt/mysqlctl/mysqld.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ func init() {
122122
for _, cmd := range []string{"mysqlctl", "mysqlctld", "vtcombo", "vttablet", "vttestserver"} {
123123
servenv.OnParseFor(cmd, registerMySQLDFlags)
124124
}
125-
for _, cmd := range []string{"vtcombo", "vttablet", "vttestserver", "vtctld", "vtctldclient"} {
125+
for _, cmd := range []string{"vtctld", "vtctldclient"} {
126126
servenv.OnParseFor(cmd, registerReparentFlags)
127127
}
128+
for _, cmd := range []string{"vtcombo", "vttablet", "vttestserver"} {
129+
servenv.OnParseFor(cmd, registerDeprecatedReparentFlags)
130+
}
128131
for _, cmd := range []string{"mysqlctl", "mysqlctld", "vtcombo", "vttablet", "vttestserver"} {
129132
servenv.OnParseFor(cmd, registerPoolFlags)
130133
}
@@ -141,6 +144,11 @@ func registerReparentFlags(fs *pflag.FlagSet) {
141144
fs.BoolVar(&DisableActiveReparents, "disable_active_reparents", DisableActiveReparents, "if set, do not allow active reparents. Use this to protect a cluster using external reparents.")
142145
}
143146

147+
func registerDeprecatedReparentFlags(fs *pflag.FlagSet) {
148+
fs.BoolVar(&DisableActiveReparents, "disable_active_reparents", DisableActiveReparents, "if set, do not allow active reparents. Use this to protect a cluster using external reparents.")
149+
fs.MarkDeprecated("disable_active_reparents", "Use --unmanaged flag instead for unmanaged tablets.")
150+
}
151+
144152
func registerPoolFlags(fs *pflag.FlagSet) {
145153
fs.IntVar(&dbaPoolSize, "dba_pool_size", dbaPoolSize, "Size of the connection pool for dba connections")
146154
fs.DurationVar(&DbaIdleTimeout, "dba_idle_timeout", DbaIdleTimeout, "Idle timeout for dba connections")

go/vt/vttablet/tabletserver/tabletenv/config.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package tabletenv
1818

1919
import (
20+
"context"
2021
"encoding/json"
2122
"errors"
2223
"fmt"
@@ -27,9 +28,11 @@ import (
2728
"google.golang.org/protobuf/encoding/prototext"
2829

2930
"vitess.io/vitess/go/flagutil"
31+
"vitess.io/vitess/go/mysql"
3032
"vitess.io/vitess/go/streamlog"
3133
"vitess.io/vitess/go/vt/dbconfigs"
3234
"vitess.io/vitess/go/vt/log"
35+
"vitess.io/vitess/go/vt/mysqlctl"
3336
"vitess.io/vitess/go/vt/servenv"
3437
"vitess.io/vitess/go/vt/sqlparser"
3538
"vitess.io/vitess/go/vt/throttler"
@@ -213,6 +216,8 @@ func registerTabletEnvFlags(fs *pflag.FlagSet) {
213216
fs.BoolVar(&currentConfig.EnableViews, "queryserver-enable-views", false, "Enable views support in vttablet.")
214217

215218
fs.BoolVar(&currentConfig.EnablePerWorkloadTableMetrics, "enable-per-workload-table-metrics", defaultConfig.EnablePerWorkloadTableMetrics, "If true, query counts and query error metrics include a label that identifies the workload")
219+
220+
fs.BoolVar(&currentConfig.Unmanaged, "unmanaged", false, "Indicates an unmanaged tablet, i.e. using an external mysql-compatible database")
216221
}
217222

218223
var (
@@ -298,6 +303,8 @@ func Init() {
298303
type TabletConfig struct {
299304
DB *dbconfigs.DBConfigs `json:"db,omitempty"`
300305

306+
Unmanaged bool `json:"unmanaged,omitempty"`
307+
301308
OltpReadPool ConnPoolConfig `json:"oltpReadPool,omitempty"`
302309
OlapReadPool ConnPoolConfig `json:"olapReadPool,omitempty"`
303310
TxPool ConnPoolConfig `json:"txPool,omitempty"`
@@ -861,6 +868,9 @@ func (c *TabletConfig) TxTimeoutForWorkload(workload querypb.ExecuteOptions_Work
861868

862869
// Verify checks for contradicting flags.
863870
func (c *TabletConfig) Verify() error {
871+
if err := c.verifyUnmanagedTabletConfig(); err != nil {
872+
return err
873+
}
864874
if err := c.verifyTransactionLimitConfig(); err != nil {
865875
return err
866876
}
@@ -882,6 +892,50 @@ func (c *TabletConfig) Verify() error {
882892
return nil
883893
}
884894

895+
// verifyUnmanagedTabletConfig checks unmanaged tablet related config for sanity
896+
func (c *TabletConfig) verifyUnmanagedTabletConfig() error {
897+
// Skip checks if tablet is not unmanaged
898+
if !c.Unmanaged {
899+
return nil
900+
}
901+
902+
// Throw error if both host and socket are null
903+
if !c.DB.HasGlobalSettings() {
904+
return errors.New("no connection parameters specified but unmanaged mode specified")
905+
}
906+
if c.DB.App.User == "" {
907+
return errors.New("database app user not specified")
908+
}
909+
if c.DB.App.Password == "" {
910+
return errors.New("database app user password not specified")
911+
}
912+
// Replication fixes should be disabled for Unmanaged tablets.
913+
mysqlctl.DisableActiveReparents = true
914+
915+
return c.checkConnectionForExternalMysql()
916+
}
917+
918+
// Test connectivity of external mysql
919+
func (c *TabletConfig) checkConnectionForExternalMysql() error {
920+
params := mysql.ConnParams{
921+
Host: c.DB.Host,
922+
Port: c.DB.Port,
923+
DbName: c.DB.DBName,
924+
Uname: c.DB.App.User,
925+
Pass: c.DB.App.Password,
926+
UnixSocket: c.DB.Socket,
927+
}
928+
929+
conn, err := mysql.Connect(context.Background(), &params)
930+
if err != nil {
931+
return err
932+
}
933+
934+
defer conn.Close()
935+
936+
return conn.Ping()
937+
}
938+
885939
// verifyTransactionLimitConfig checks TransactionLimitConfig for sanity
886940
func (c *TabletConfig) verifyTransactionLimitConfig() error {
887941
actual, dryRun := c.EnableTransactionLimit, c.EnableTransactionLimitDryRun

go/vt/vttablet/tabletserver/tabletenv/config_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
"github.com/stretchr/testify/assert"
2525
"github.com/stretchr/testify/require"
2626

27+
"vitess.io/vitess/go/mysql/fakesqldb"
2728
"vitess.io/vitess/go/test/utils"
2829
"vitess.io/vitess/go/vt/dbconfigs"
30+
"vitess.io/vitess/go/vt/mysqlctl"
2931
"vitess.io/vitess/go/vt/throttler"
3032
"vitess.io/vitess/go/vt/topo/topoproto"
3133
"vitess.io/vitess/go/vt/vterrors"
@@ -444,3 +446,38 @@ func TestVerifyTxThrottlerConfig(t *testing.T) {
444446
})
445447
}
446448
}
449+
450+
func TestVerifyUnmanagedTabletConfig(t *testing.T) {
451+
oldDisableActiveReparents := mysqlctl.DisableActiveReparents
452+
defer func() {
453+
mysqlctl.DisableActiveReparents = oldDisableActiveReparents
454+
}()
455+
456+
config := defaultConfig
457+
458+
db := fakesqldb.New(t)
459+
defer db.Close()
460+
461+
params := db.ConnParams()
462+
config.DB = dbconfigs.NewTestDBConfigs(*params, *params, "")
463+
464+
// By default, unmanaged mode should be false
465+
err := config.verifyUnmanagedTabletConfig()
466+
assert.Nil(t, err)
467+
468+
config.Unmanaged = true
469+
err = config.verifyUnmanagedTabletConfig()
470+
assert.EqualError(t, err, "no connection parameters specified but unmanaged mode specified")
471+
472+
config.DB.Socket = db.ConnParams().UnixSocket
473+
err = config.verifyUnmanagedTabletConfig()
474+
assert.EqualError(t, err, "database app user not specified")
475+
476+
config.DB.App.User = "testUser"
477+
err = config.verifyUnmanagedTabletConfig()
478+
assert.EqualError(t, err, "database app user password not specified")
479+
480+
config.DB.App.Password = "testPassword"
481+
err = config.verifyUnmanagedTabletConfig()
482+
assert.Nil(t, err)
483+
}

0 commit comments

Comments
 (0)