Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into vtctld-conclude-tra…
Browse files Browse the repository at this point in the history
…nsactions

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Sep 16, 2024
2 parents bb38600 + fd18ae4 commit 3ed6b66
Show file tree
Hide file tree
Showing 85 changed files with 8,016 additions and 7,695 deletions.
2 changes: 1 addition & 1 deletion examples/common/scripts/vtadmin-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ vtadmin \
--alsologtostderr \
--rbac \
--rbac-config="${script_dir}/../vtadmin/rbac.yaml" \
--cluster "id=${cluster_name},name=${cluster_name},discovery=staticfile,discovery-staticfile-path=${script_dir}/../vtadmin/discovery.json,tablet-fqdn-tmpl=http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \
--cluster "id=${cluster_name},name=${cluster_name},discovery=staticfile,discovery-staticfile-path=${script_dir}/../vtadmin/discovery.json,tablet-fqdn-tmpl=http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }},schema-cache-default-expiration=1m" \
> "${log_dir}/vtadmin-api.out" 2>&1 &

vtadmin_api_pid=$!
Expand Down
2 changes: 1 addition & 1 deletion examples/operator/401_scheduled_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
jobTimeoutMinute: 5
strategies:
- name: BackupShard
keyspace: "customer"
keyspace: "commerce"
shard: "-"
images:
vtctld: vitess/lite:latest
Expand Down
10 changes: 4 additions & 6 deletions go/cmd/vtctldclient/command/vreplication/common/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import (
"sort"
"strings"

"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"

"github.com/spf13/cobra"

"vitess.io/vitess/go/cmd/vtctldclient/cli"
"vitess.io/vitess/go/textutil"
"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
Expand Down Expand Up @@ -143,9 +142,8 @@ func commandUpdateState(cmd *cobra.Command, args []string) error {
TabletRequest: &tabletmanagerdatapb.UpdateVReplicationWorkflowRequest{
Workflow: workflowUpdateOptions.Workflow,
Cells: textutil.SimulatedNullStringSlice,
TabletTypes: []topodatapb.TabletType{topodatapb.TabletType(textutil.SimulatedNullInt)},
OnDdl: binlogdatapb.OnDDLAction(textutil.SimulatedNullInt),
State: state,
TabletTypes: textutil.SimulatedNullTabletTypeSlice,
State: &state,
},
}

Expand Down
6 changes: 2 additions & 4 deletions go/cmd/vtctldclient/command/vreplication/workflow/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

Expand Down Expand Up @@ -79,9 +78,8 @@ func commandUpdateState(cmd *cobra.Command, args []string) error {
TabletRequest: &tabletmanagerdatapb.UpdateVReplicationWorkflowRequest{
Workflow: baseOptions.Workflow,
Cells: textutil.SimulatedNullStringSlice,
TabletTypes: []topodatapb.TabletType{topodatapb.TabletType(textutil.SimulatedNullInt)},
OnDdl: binlogdatapb.OnDDLAction(textutil.SimulatedNullInt),
State: state,
TabletTypes: textutil.SimulatedNullTabletTypeSlice,
State: &state,
},
}

Expand Down
25 changes: 11 additions & 14 deletions go/cmd/vtctldclient/command/vreplication/workflow/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"vitess.io/vitess/go/cmd/vtctldclient/cli"
"vitess.io/vitess/go/cmd/vtctldclient/command/vreplication/common"
"vitess.io/vitess/go/ptr"
"vitess.io/vitess/go/textutil"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
Expand Down Expand Up @@ -65,14 +66,14 @@ var (
}
changes = true
} else {
updateOptions.TabletTypes = []topodatapb.TabletType{topodatapb.TabletType(textutil.SimulatedNullInt)}
updateOptions.TabletTypes = textutil.SimulatedNullTabletTypeSlice
}
if cmd.Flags().Lookup("on-ddl").Changed { // Validate the provided value
changes = true
if _, ok := binlogdatapb.OnDDLAction_value[strings.ToUpper(updateOptions.OnDDL)]; !ok {
return fmt.Errorf("invalid on-ddl value: %s", updateOptions.OnDDL)
}
} // Simulated NULL will need to be handled in command
}
if !changes {
return fmt.Errorf("no configuration options specified to update")
}
Expand All @@ -85,15 +86,6 @@ var (
func commandUpdate(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

// We've already validated any provided value, if one WAS provided.
// Now we need to do the mapping from the string representation to
// the enum value.
onddl := int32(textutil.SimulatedNullInt) // Simulated NULL when no value provided
if val, ok := binlogdatapb.OnDDLAction_value[strings.ToUpper(updateOptions.OnDDL)]; ok {
onddl = val
}

// Simulated NULL when no value is provided.
tsp := tabletmanagerdatapb.TabletSelectionPreference_UNKNOWN
if cmd.Flags().Lookup("tablet-types-in-order").Changed {
if updateOptions.TabletTypesInPreferenceOrder {
Expand All @@ -109,12 +101,17 @@ func commandUpdate(cmd *cobra.Command, args []string) error {
Workflow: baseOptions.Workflow,
Cells: updateOptions.Cells,
TabletTypes: updateOptions.TabletTypes,
TabletSelectionPreference: tsp,
OnDdl: binlogdatapb.OnDDLAction(onddl),
State: binlogdatapb.VReplicationWorkflowState(textutil.SimulatedNullInt), // We don't allow changing this in the client command
TabletSelectionPreference: &tsp,
},
}

// We've already validated any provided value, if one WAS provided.
// Now we need to do the mapping from the string representation to
// the enum value.
if val, ok := binlogdatapb.OnDDLAction_value[strings.ToUpper(updateOptions.OnDDL)]; ok {
req.TabletRequest.OnDdl = ptr.Of(binlogdatapb.OnDDLAction(val))
}

resp, err := common.GetClient().WorkflowUpdate(common.GetCommandCtx(), req)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/auth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func newSalt() ([]byte, error) {
}

// Salt must be a legal UTF8 string.
for i := 0; i < len(salt); i++ {
for i := range len(salt) {
salt[i] &= 0x7f
if salt[i] == '\x00' || salt[i] == '$' {
salt[i]++
Expand Down
8 changes: 4 additions & 4 deletions go/mysql/binlog/binlog_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ var binaryIntSizes = map[jsonDataType]int{
func binparserInt(typ jsonDataType, data []byte, pos int) (*json.Value, error) {
var val uint64
size := binaryIntSizes[typ]
for i := 0; i < size; i++ {
for i := range size {
val = val + uint64(data[pos+i])<<(8*i)
}
var s string
Expand Down Expand Up @@ -344,7 +344,7 @@ func binparserArray(typ jsonDataType, data []byte, pos int) (node *json.Value, e
large := typ == jsonLargeArray
elementCount, pos = readInt(data, pos, large)
_, pos = readInt(data, pos, large)
for i := 0; i < elementCount; i++ {
for range elementCount {
elem, pos, err = binparserElement(data, pos, large)
if err != nil {
return nil, err
Expand All @@ -366,7 +366,7 @@ func binparserObject(typ jsonDataType, data []byte, pos int) (node *json.Value,
_, pos = readInt(data, pos, large)

keys := make([]string, elementCount) // stores all the keys in this object
for i := 0; i < elementCount; i++ {
for i := range elementCount {
var keyOffset int
var keyLength int
keyOffset, pos = readInt(data, pos, large)
Expand All @@ -384,7 +384,7 @@ func binparserObject(typ jsonDataType, data []byte, pos int) (node *json.Value,
var elem *json.Value

// get the value for each key
for i := 0; i < elementCount; i++ {
for i := range elementCount {
elem, pos, err = binparserElement(data, pos, large)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions go/mysql/binlog/rbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func CellValue(data []byte, pos int, typ byte, metadata uint16, field *querypb.F
}

// now the full digits, 32 bits each, 9 digits
for i := 0; i < intg0; i++ {
for range intg0 {
val = binary.BigEndian.Uint32(d[pos : pos+4])
fmt.Fprintf(txt, "%09d", val)
pos += 4
Expand All @@ -564,7 +564,7 @@ func CellValue(data []byte, pos int, typ byte, metadata uint16, field *querypb.F
txt.WriteByte('.')

// now the full fractional digits
for i := 0; i < frac0; i++ {
for range frac0 {
val = binary.BigEndian.Uint32(d[pos : pos+4])
fmt.Fprintf(txt, "%09d", val)
pos += 4
Expand Down Expand Up @@ -718,7 +718,7 @@ func CellValue(data []byte, pos int, typ byte, metadata uint16, field *querypb.F
// numbers.
l := int(metadata & 0xff)
var val uint64
for i := 0; i < l; i++ {
for i := range l {
val += uint64(data[pos+i]) << (uint(i) * 8)
}
return sqltypes.MakeTrusted(querypb.Type_UINT64,
Expand Down
4 changes: 3 additions & 1 deletion go/mysql/binlog_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type BinlogEvent interface {

// Timestamp returns the timestamp from the event header.
Timestamp() uint32
// ServerID returns the server ID from the event header.
ServerID() uint32

// Format returns a BinlogFormat struct based on the event data.
// This is only valid if IsFormatDescription() returns true.
Expand Down Expand Up @@ -328,7 +330,7 @@ func (b *Bitmap) Set(index int, value bool) {
// hence the non-efficient logic.
func (b *Bitmap) BitCount() int {
sum := 0
for i := 0; i < b.count; i++ {
for i := range b.count {
if b.Bit(i) {
sum++
}
Expand Down
4 changes: 4 additions & 0 deletions go/mysql/binlog_event_filepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func (ev filePosFakeEvent) Timestamp() uint32 {
return ev.timestamp
}

func (ev filePosFakeEvent) ServerID() uint32 {
return 1
}

func (ev filePosFakeEvent) Format() (BinlogFormat, error) {
return BinlogFormat{}, nil
}
Expand Down
12 changes: 7 additions & 5 deletions go/mysql/binlog_event_make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestLargeTableMapEvent(t *testing.T) {
types := make([]byte, 0, colLen)
metadata := make([]uint16, 0, colLen)

for i := 0; i < colLen; i++ {
for range colLen {
types = append(types, binlog.TypeLongLong)
metadata = append(metadata, 0)
}
Expand Down Expand Up @@ -374,6 +374,7 @@ func TestRowsEvent(t *testing.T) {
require.True(t, reflect.DeepEqual(gotRows, rows), "NewRowsEvent().Rows() got Rows:\n%v\nexpected:\n%v", gotRows, rows)

assert.NotZero(t, event.Timestamp())
assert.NotZero(t, event.ServerID())
}

func TestHeartbeatEvent(t *testing.T) {
Expand All @@ -384,6 +385,7 @@ func TestHeartbeatEvent(t *testing.T) {
require.NotNil(t, event)
assert.True(t, event.IsHeartbeat())
assert.Zero(t, event.Timestamp())
assert.NotZero(t, event.ServerID())
}

func TestRotateRotateEvent(t *testing.T) {
Expand Down Expand Up @@ -429,7 +431,7 @@ func TestLargeRowsEvent(t *testing.T) {
types := make([]byte, 0, colLen)
metadata := make([]uint16, 0, colLen)

for i := 0; i < colLen; i++ {
for range colLen {
types = append(types, binlog.TypeLong)
metadata = append(metadata, 0)
}
Expand All @@ -446,7 +448,7 @@ func TestLargeRowsEvent(t *testing.T) {

identify := make([]byte, 0, colLen*4)
data := make([]byte, 0, colLen*4)
for i := 0; i < colLen; i++ {
for range colLen {
identify = append(identify, 0x10, 0x20, 0x30, 0x40)
data = append(data, 0x10, 0x20, 0x30, 0x40)
}
Expand All @@ -467,7 +469,7 @@ func TestLargeRowsEvent(t *testing.T) {
}

// All rows are included, none are NULL.
for i := 0; i < colLen; i++ {
for i := range colLen {
rows.IdentifyColumns.Set(i, true)
rows.DataColumns.Set(i, true)
}
Expand All @@ -476,7 +478,7 @@ func TestLargeRowsEvent(t *testing.T) {
// 1076895760 is 0x40302010.
identifies, _ := rows.StringIdentifiesForTests(tm, 0)
expected := make([]string, 0, colLen)
for i := 0; i < colLen; i++ {
for range colLen {
expected = append(expected, "1076895760")
}
if !reflect.DeepEqual(identifies, expected) {
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/charset/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Slice(charset Charset, input []byte, from, to int) []byte {
}
iter := input
start := 0
for i := 0; i < to; i++ {
for i := range to {
r, size := charset.DecodeRune(iter)
if r == RuneError && size < 2 {
break
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/collations/colldata/8bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *Collation_8bit_simple_ci) Collate(left, right []byte, rightIsPrefix boo
sortOrder := c.sort
cmpLen := min(len(left), len(right))

for i := 0; i < cmpLen; i++ {
for i := range cmpLen {
sortL, sortR := sortOrder[left[i]], sortOrder[right[i]]
if sortL != sortR {
return int(sortL) - int(sortR)
Expand All @@ -174,7 +174,7 @@ func (c *Collation_8bit_simple_ci) TinyWeightString(src []byte) uint32 {
var w32 [4]byte
sortOrder := c.sort
sortLen := min(4, len(src))
for i := 0; i < sortLen; i++ {
for i := range sortLen {
w32[i] = sortOrder[src[i]]
}
return binary.BigEndian.Uint32(w32[:4])
Expand Down
6 changes: 3 additions & 3 deletions go/mysql/collations/colldata/uca_contraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func benchmarkFind(b *testing.B, input []byte, contract uca.Contractor) {
b.ReportAllocs()
b.ResetTimer()

for n := 0; n < b.N; n++ {
for range b.N {
in := input
for len(in) > 0 {
cp, width := utf8.DecodeRune(in)
Expand All @@ -144,7 +144,7 @@ func benchmarkFindJA(b *testing.B, input []byte, contract uca.Contractor) {
b.ReportAllocs()
b.ResetTimer()

for n := 0; n < b.N; n++ {
for range b.N {
prev := rune(0)
in := input
for len(in) > 0 {
Expand All @@ -166,7 +166,7 @@ func newStrgen() *strgen {
}

func (s *strgen) withASCII() *strgen {
for r := rune(0); r < utf8.RuneSelf; r++ {
for r := range rune(utf8.RuneSelf) {
s.repertoire[r] = struct{}{}
}
return s
Expand Down
6 changes: 3 additions & 3 deletions go/mysql/collations/colldata/uca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestIsPrefix(t *testing.T) {
coll := testcollation(t, collName)
input := []rune(strings.ToUpper(ExampleStringLong))

for size := 0; size < len(input); size++ {
for size := range len(input) {
left := ExampleStringLong
right := string(input[:size])

Expand Down Expand Up @@ -777,7 +777,7 @@ func BenchmarkAllUCAWeightStrings(b *testing.B) {

b.ResetTimer()

for i := 0; i < b.N; i++ {
for range b.N {
_ = collation.WeightString(buf, input, 0)
}
})
Expand Down Expand Up @@ -1058,7 +1058,7 @@ func BenchmarkUCA900Collation(b *testing.B) {
str2 := []byte(strings.ToUpper(content))
for _, collation := range Collations {
b.Run(fmt.Sprintf("%s/%d/%s", teststr.Name, length, collation.Name()), func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
_ = collation.Collate(str1, str2, false)
}
})
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/internal/uca/iter_fast_900.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (it *FastIterator900) NextWeightBlock64(dstbytes []byte) int {

// Slow path: just loop up to 8 times to fill the buffer and bail
// early if we exhaust the iterator.
for i := 0; i < 8; i++ {
for i := range 8 {
w, ok := it.Next()
if !ok {
return i * 2
Expand Down
Loading

0 comments on commit 3ed6b66

Please sign in to comment.