Skip to content

Commit

Permalink
Merge main into movetables-complete
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
  • Loading branch information
beingnoble03 committed Oct 10, 2024
2 parents 888268b + d75272c commit ddc5e74
Show file tree
Hide file tree
Showing 59 changed files with 12,189 additions and 7,162 deletions.
7 changes: 6 additions & 1 deletion changelog/21.0/21.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
- **[Errant GTID Detection on VTTablets](#errant-gtid-vttablet)**
- **[Automatically Replace MySQL auto_increment Clauses with Vitess Sequences](#auto-replace-mysql-autoinc-with-seq)**
- **[Experimental MySQL 8.4 support](#experimental-mysql-84)**
- **[Curreny Errant GTIDs Count Metric](#errant-gtid-metric)**
- **[Current Errant GTIDs Count Metric](#errant-gtid-metric)**
- **[vtctldclient ChangeTabletTags](#vtctldclient-changetablettags)**


## <a id="major-changes"/>Major Changes</a>
Expand Down Expand Up @@ -229,3 +230,7 @@ We have added experimental support for MySQL 8.4. It passes the Vitess test suit
### <a id="errant-gtid-metric"/>Current Errant GTIDs Count Metric
A new metric called `CurrentErrantGTIDCount` has been added to the `VTOrc` component.
This metric shows the current count of the errant GTIDs in the tablets.

### <a id="vtctldclient-changetablettags"/>`vtctldclient ChangeTabletTags` command

The `vtctldclient` command `ChangeTabletTags` was added to allow the tags of a tablet to be changed dynamically.
23 changes: 22 additions & 1 deletion go/cmd/vtctldclient/cli/tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ limitations under the License.
package cli

import (
"vitess.io/vitess/go/vt/topo/topoproto"
"fmt"
"strings"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
"vitess.io/vitess/go/vt/topo/topoproto"
)

// TabletAliasesFromPosArgs takes a list of positional (non-flag) arguments and
Expand All @@ -38,3 +40,22 @@ func TabletAliasesFromPosArgs(args []string) ([]*topodatapb.TabletAlias, error)

return aliases, nil
}

// TabletTagsFromPosArgs takes a list of positional (non-flag) arguements and
// converts them to a map of tablet tags.
func TabletTagsFromPosArgs(args []string) (map[string]string, error) {
if len(args) == 0 {
return nil, fmt.Errorf("no tablet tags specified")
}

tags := make(map[string]string, len(args))
for _, kvPair := range args {
if !strings.Contains(kvPair, "=") {
return nil, fmt.Errorf("invalid tablet tag %q specified. tablet tags must be specified in key=value format", kvPair)
}
fields := strings.SplitN(kvPair, "=", 2)
tags[fields[0]] = fields[1]
}

return tags, nil
}
48 changes: 48 additions & 0 deletions go/cmd/vtctldclient/cli/tablets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cli

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestTabletTagsFromPosArgs(t *testing.T) {
t.Parallel()

{
tags, err := TabletTagsFromPosArgs([]string{"fail"})
assert.Error(t, err)
assert.Nil(t, tags)
}
{
tags, err := TabletTagsFromPosArgs([]string{"hello=world"})
assert.NoError(t, err)
assert.Equal(t, map[string]string{
"hello": "world",
}, tags)
}
{
tags, err := TabletTagsFromPosArgs([]string{"hello=world", "test=123"})
assert.NoError(t, err)
assert.Equal(t, map[string]string{
"hello": "world",
"test": "123",
}, tags)
}
}
4 changes: 2 additions & 2 deletions go/cmd/vtctldclient/command/reparents.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func commandTabletExternallyReparented(cmd *cobra.Command, args []string) error
func init() {
EmergencyReparentShard.Flags().DurationVar(&emergencyReparentShardOptions.WaitReplicasTimeout, "wait-replicas-timeout", topo.RemoteOperationTimeout, "Time to wait for replicas to catch up in reparenting.")
EmergencyReparentShard.Flags().StringVar(&emergencyReparentShardOptions.NewPrimaryAliasStr, "new-primary", "", "Alias of a tablet that should be the new primary. If not specified, the vtctld will select the best candidate to promote.")
EmergencyReparentShard.Flags().StringVar(&emergencyReparentShardOptions.NewPrimaryAliasStr, "expected-primary", "", "Alias of a tablet that must be the current primary in order for the reparent to be processed.")
EmergencyReparentShard.Flags().StringVar(&emergencyReparentShardOptions.ExpectedPrimaryAliasStr, "expected-primary", "", "Alias of a tablet that must be the current primary in order for the reparent to be processed.")
EmergencyReparentShard.Flags().BoolVar(&emergencyReparentShardOptions.PreventCrossCellPromotion, "prevent-cross-cell-promotion", false, "Only promotes a new primary from the same cell as the previous primary.")
EmergencyReparentShard.Flags().BoolVar(&emergencyReparentShardOptions.WaitForAllTablets, "wait-for-all-tablets", false, "Should ERS wait for all the tablets to respond. Useful when all the tablets are reachable.")
EmergencyReparentShard.Flags().StringSliceVarP(&emergencyReparentShardOptions.IgnoreReplicaAliasStrList, "ignore-replicas", "i", nil, "Comma-separated, repeated list of replica tablet aliases to ignore during the emergency reparent.")
Expand All @@ -320,7 +320,7 @@ func init() {
PlannedReparentShard.Flags().DurationVar(&plannedReparentShardOptions.TolerableReplicationLag, "tolerable-replication-lag", 0, "Amount of replication lag that is considered acceptable for a tablet to be eligible for promotion when Vitess makes the choice of a new primary.")
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.NewPrimaryAliasStr, "new-primary", "", "Alias of a tablet that should be the new primary.")
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.AvoidPrimaryAliasStr, "avoid-primary", "", "Alias of a tablet that should not be the primary; i.e. \"reparent to any other tablet if this one is the primary\".")
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.NewPrimaryAliasStr, "expected-primary", "", "Alias of a tablet that must be the current primary in order for the reparent to be processed.")
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.ExpectedPrimaryAliasStr, "expected-primary", "", "Alias of a tablet that must be the current primary in order for the reparent to be processed.")
PlannedReparentShard.Flags().BoolVar(&plannedReparentShardOptions.AllowCrossCellPromotion, "allow-cross-cell-promotion", false, "Allow cross cell promotion")
Root.AddCommand(PlannedReparentShard)

Expand Down
48 changes: 48 additions & 0 deletions go/cmd/vtctldclient/command/tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ import (
)

var (
// ChangeTabletTags makes a ChangeTabletTags gRPC call to a vtctld.
ChangeTabletTags = &cobra.Command{
Use: "ChangeTabletTags <alias> <tablet-tag> [ <tablet-tag> ... ]",
Short: "Changes the tablet tags for the specified tablet, if possible.",
Long: `Changes the tablet tags for the specified tablet, if possible.
Tags must be specified as key=value pairs.`,
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(2),
RunE: commandChangeTabletTags,
}
// ChangeTabletType makes a ChangeTabletType gRPC call to a vtctld.
ChangeTabletType = &cobra.Command{
Use: "ChangeTabletType [--dry-run] <alias> <tablet-type>",
Expand Down Expand Up @@ -212,6 +223,40 @@ Note that, in the SleepTablet implementation, the value should be positively-sig
}
)

var changeTabletTagsOptions = struct {
Replace bool
}{}

func commandChangeTabletTags(cmd *cobra.Command, args []string) error {
allArgs := cmd.Flags().Args()

alias, err := topoproto.ParseTabletAlias(allArgs[0])
if err != nil {
return err
}

tags, err := cli.TabletTagsFromPosArgs(allArgs[1:])
if err != nil {
return err
}

cli.FinishedParsing(cmd)

resp, err := client.ChangeTabletTags(commandCtx, &vtctldatapb.ChangeTabletTagsRequest{
TabletAlias: alias,
Tags: tags,
Replace: changeTabletTagsOptions.Replace,
})
if err != nil {
return err
}

fmt.Printf("- %v\n", cli.MarshalMapAWK(resp.BeforeTags))
fmt.Printf("+ %v\n", cli.MarshalMapAWK(resp.AfterTags))

return nil
}

var changeTabletTypeOptions = struct {
DryRun bool
}{}
Expand Down Expand Up @@ -629,6 +674,9 @@ func commandStopReplication(cmd *cobra.Command, args []string) error {
}

func init() {
ChangeTabletTags.Flags().BoolVarP(&changeTabletTagsOptions.Replace, "replace", "r", false, "Replace all tablet tags with the tags provided. By default tags are merged/updated.")
Root.AddCommand(ChangeTabletTags)

ChangeTabletType.Flags().BoolVarP(&changeTabletTypeOptions.DryRun, "dry-run", "d", false, "Shows the proposed change without actually executing it.")
Root.AddCommand(ChangeTabletType)

Expand Down
1 change: 1 addition & 0 deletions go/flags/endtoend/vtctldclient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Available Commands:
ApplyVSchema Applies the VTGate routing schema to the provided keyspace. Shows the result after application.
Backup Uses the BackupStorage service on the given tablet to create and store a new backup.
BackupShard Finds the most up-to-date REPLICA, RDONLY, or SPARE tablet in the given shard and uses the BackupStorage service on that tablet to create and store a new backup.
ChangeTabletTags Changes the tablet tags for the specified tablet, if possible.
ChangeTabletType Changes the db type for the specified tablet, if possible.
CheckThrottler Issue a throttler check on the given tablet.
CreateKeyspace Creates the specified keyspace in the topology.
Expand Down
Loading

0 comments on commit ddc5e74

Please sign in to comment.