Skip to content

Commit

Permalink
VDiff: Make max diff duration upgrade/downgrade safe (#14995)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord authored Jan 19, 2024
1 parent 9af8692 commit 9099eb8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
15 changes: 15 additions & 0 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,21 @@ func (s *Server) VDiffCreate(ctx context.Context, req *vtctldatapb.VDiffCreateRe
tabletTypesStr = discovery.InOrderHint + tabletTypesStr
}

// This is a pointer so there's no ZeroValue in the message
// and an older v18 client will not provide it.
if req.MaxDiffDuration == nil {
req.MaxDiffDuration = &vttimepb.Duration{}
}
// The other vttime.Duration vars should not be nil as the
// client should always provide them, but we check anyway to
// be safe.
if req.FilteredReplicationWaitTime == nil {
req.FilteredReplicationWaitTime = &vttimepb.Duration{}
}
if req.WaitUpdateInterval == nil {
req.WaitUpdateInterval = &vttimepb.Duration{}
}

options := &tabletmanagerdatapb.VDiffOptions{
PickerOptions: &tabletmanagerdatapb.VDiffPickerOptions{
TabletTypes: tabletTypesStr,
Expand Down
38 changes: 36 additions & 2 deletions go/vt/vtctl/workflow/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ import (

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/config"
"vitess.io/vitess/go/vt/sqlparser"

"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/topo/memorytopo"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vttablet/tmclient"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

type fakeTMC struct {
Expand Down Expand Up @@ -167,3 +168,36 @@ func TestCheckReshardingJournalExistsOnTablet(t *testing.T) {
})
}
}

// TestVDiffCreate performs some basic tests of the VDiffCreate function
// to ensure that it behaves as expected given a specific request.
func TestVDiffCreate(t *testing.T) {
ctx := context.Background()
ts := memorytopo.NewServer(ctx, "cell")
tmc := &fakeTMC{}
s := NewServer(ts, tmc, collations.MySQL8(), sqlparser.NewTestParser(), config.DefaultMySQLVersion)

tests := []struct {
name string
req *vtctldatapb.VDiffCreateRequest
wantErr string
}{
{
name: "no values",
req: &vtctldatapb.VDiffCreateRequest{},
wantErr: "node doesn't exist: keyspaces/shards", // We did not provide any keyspace or shard
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := s.VDiffCreate(ctx, tt.req)
if tt.wantErr != "" {
require.EqualError(t, err, tt.wantErr)
return
}
require.NoError(t, err)
require.NotNil(t, got)
require.NotEmpty(t, got.UUID)
})
}
}

0 comments on commit 9099eb8

Please sign in to comment.