From 1b86928162e348b5a38d053b3ccad40238623d0e Mon Sep 17 00:00:00 2001 From: deepthi Date: Mon, 6 Jul 2020 17:23:15 -0700 Subject: [PATCH 1/2] linter fixes, remove staticcheck hook because golangci-lint includes it Signed-off-by: deepthi --- go/cmd/automation_client/automation_client.go | 4 +- go/mysql/replication_constants.go | 2 +- .../backup/vtctlbackup/backup_utils.go | 1 + go/vt/grpcclient/client.go | 2 +- go/vt/vttablet/faketmclient/fake_client.go | 18 ++--- go/vt/vttablet/grpctmclient/client.go | 18 ++--- .../vttablet/tabletmanager/rpc_replication.go | 18 ++--- misc/git/hooks/staticcheck | 70 ------------------- 8 files changed, 32 insertions(+), 101 deletions(-) delete mode 100755 misc/git/hooks/staticcheck diff --git a/go/cmd/automation_client/automation_client.go b/go/cmd/automation_client/automation_client.go index 94553f1318d..61bb65b47a6 100644 --- a/go/cmd/automation_client/automation_client.go +++ b/go/cmd/automation_client/automation_client.go @@ -92,7 +92,7 @@ func main() { Parameters: params.parameters, } fmt.Printf("Sending request:\n%v", proto.MarshalTextString(enqueueRequest)) - enqueueResponse, err := client.EnqueueClusterOperation(context.Background(), enqueueRequest, grpc.FailFast(false)) //nolint + enqueueResponse, err := client.EnqueueClusterOperation(context.Background(), enqueueRequest, grpc.WaitForReady(true)) if err != nil { fmt.Println("Failed to enqueue ClusterOperation. Error:", err) os.Exit(4) @@ -113,7 +113,7 @@ func waitForClusterOp(client automationservicepb.AutomationClient, id string) (* Id: id, } - resp, err := client.GetClusterOperationDetails(context.Background(), req, grpc.FailFast(false)) //nolint + resp, err := client.GetClusterOperationDetails(context.Background(), req, grpc.WaitForReady(true)) if err != nil { return nil, fmt.Errorf("failed to get ClusterOperation Details. Request: %v Error: %v", req, err) } diff --git a/go/mysql/replication_constants.go b/go/mysql/replication_constants.go index 53937a01ac4..53d51c944eb 100644 --- a/go/mysql/replication_constants.go +++ b/go/mysql/replication_constants.go @@ -13,7 +13,7 @@ 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. */ -//nolint:unparam + package mysql // This file contains the constant definitions for this package. diff --git a/go/test/endtoend/backup/vtctlbackup/backup_utils.go b/go/test/endtoend/backup/vtctlbackup/backup_utils.go index 2754baf6e76..0d0acceafda 100644 --- a/go/test/endtoend/backup/vtctlbackup/backup_utils.go +++ b/go/test/endtoend/backup/vtctlbackup/backup_utils.go @@ -38,6 +38,7 @@ import ( "vitess.io/vitess/go/test/endtoend/cluster" ) +// constants for test variants const ( XtraBackup = iota Backup diff --git a/go/vt/grpcclient/client.go b/go/vt/grpcclient/client.go index 2c317d3d30f..d229c32b1af 100644 --- a/go/vt/grpcclient/client.go +++ b/go/vt/grpcclient/client.go @@ -62,7 +62,7 @@ func Dial(target string, failFast FailFast, opts ...grpc.DialOption) (*grpc.Clie grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(*grpccommon.MaxMessageSize), grpc.MaxCallSendMsgSize(*grpccommon.MaxMessageSize), - grpc.FailFast(bool(failFast)), //nolint + grpc.WaitForReady(bool(!failFast)), ), } diff --git a/go/vt/vttablet/faketmclient/fake_client.go b/go/vt/vttablet/faketmclient/fake_client.go index 5a63cbf23a2..2fcb728c744 100644 --- a/go/vt/vttablet/faketmclient/fake_client.go +++ b/go/vt/vttablet/faketmclient/fake_client.go @@ -285,47 +285,47 @@ func (client *FakeTabletManagerClient) PromoteReplica(ctx context.Context, table return "", nil } -//Deprecated +// StopSlave is deprecated func (client *FakeTabletManagerClient) StopSlave(ctx context.Context, tablet *topodatapb.Tablet) error { return nil } -//Deprecated +// StopSlaveMinimum is deprecated func (client *FakeTabletManagerClient) StopSlaveMinimum(ctx context.Context, tablet *topodatapb.Tablet, minPos string, waitTime time.Duration) (string, error) { return "", nil } -//Deprecated +// StartSlave is deprecated func (client *FakeTabletManagerClient) StartSlave(ctx context.Context, tablet *topodatapb.Tablet) error { return nil } -//Deprecated +// StartSlaveUntilAfter is deprecated func (client *FakeTabletManagerClient) StartSlaveUntilAfter(ctx context.Context, tablet *topodatapb.Tablet, position string, duration time.Duration) error { return nil } -//Deprecated +// GetSlaves is deprecated func (client *FakeTabletManagerClient) GetSlaves(ctx context.Context, tablet *topodatapb.Tablet) ([]string, error) { return nil, nil } -//Deprecated +// SlaveStatus is deprecated func (client *FakeTabletManagerClient) SlaveStatus(ctx context.Context, tablet *topodatapb.Tablet) (*replicationdatapb.Status, error) { return &replicationdatapb.Status{}, nil } -//Deprecated +// InitSlave is deprecated func (client *FakeTabletManagerClient) InitSlave(ctx context.Context, tablet *topodatapb.Tablet, parent *topodatapb.TabletAlias, position string, timeCreatedNS int64) error { return nil } -//Deprecated +// SlaveWasPromoted is deprecated func (client *FakeTabletManagerClient) SlaveWasPromoted(ctx context.Context, tablet *topodatapb.Tablet) error { return nil } -//Deprecated +// SlaveWasRestarted is deprecated func (client *FakeTabletManagerClient) SlaveWasRestarted(ctx context.Context, tablet *topodatapb.Tablet, parent *topodatapb.TabletAlias) error { return nil } diff --git a/go/vt/vttablet/grpctmclient/client.go b/go/vt/vttablet/grpctmclient/client.go index 3fc55a4eacf..911506b9482 100644 --- a/go/vt/vttablet/grpctmclient/client.go +++ b/go/vt/vttablet/grpctmclient/client.go @@ -823,7 +823,7 @@ func (client *Client) Close() { client.rpcClientMap = nil } -// Deprecated +// SlaveStatus is deprecated func (client *Client) SlaveStatus(ctx context.Context, tablet *topodatapb.Tablet) (*replicationdatapb.Status, error) { cc, c, err := client.dial(tablet) if err != nil { @@ -837,7 +837,7 @@ func (client *Client) SlaveStatus(ctx context.Context, tablet *topodatapb.Tablet return response.Status, nil } -// Deprecated +// StopSlave is deprecated func (client *Client) StopSlave(ctx context.Context, tablet *topodatapb.Tablet) error { cc, c, err := client.dial(tablet) if err != nil { @@ -848,7 +848,7 @@ func (client *Client) StopSlave(ctx context.Context, tablet *topodatapb.Tablet) return err } -// Deprecated +// StopSlaveMinimum is deprecated func (client *Client) StopSlaveMinimum(ctx context.Context, tablet *topodatapb.Tablet, minPos string, waitTime time.Duration) (string, error) { cc, c, err := client.dial(tablet) if err != nil { @@ -865,7 +865,7 @@ func (client *Client) StopSlaveMinimum(ctx context.Context, tablet *topodatapb.T return response.Position, nil } -// Deprecated +// StartSlave is deprecated func (client *Client) StartSlave(ctx context.Context, tablet *topodatapb.Tablet) error { cc, c, err := client.dial(tablet) if err != nil { @@ -876,7 +876,7 @@ func (client *Client) StartSlave(ctx context.Context, tablet *topodatapb.Tablet) return err } -// Deprecated +// StartSlaveUntilAfter is deprecated func (client *Client) StartSlaveUntilAfter(ctx context.Context, tablet *topodatapb.Tablet, position string, waitTime time.Duration) error { cc, c, err := client.dial(tablet) if err != nil { @@ -890,7 +890,7 @@ func (client *Client) StartSlaveUntilAfter(ctx context.Context, tablet *topodata return err } -// Deprecated +// GetSlaves is deprecated func (client *Client) GetSlaves(ctx context.Context, tablet *topodatapb.Tablet) ([]string, error) { cc, c, err := client.dial(tablet) if err != nil { @@ -904,7 +904,7 @@ func (client *Client) GetSlaves(ctx context.Context, tablet *topodatapb.Tablet) return response.Addrs, nil } -// Deprecated +// InitSlave is deprecated func (client *Client) InitSlave(ctx context.Context, tablet *topodatapb.Tablet, parent *topodatapb.TabletAlias, replicationPosition string, timeCreatedNS int64) error { cc, c, err := client.dial(tablet) if err != nil { @@ -919,7 +919,7 @@ func (client *Client) InitSlave(ctx context.Context, tablet *topodatapb.Tablet, return err } -// Deprecated +// SlaveWasPromoted is deprecated func (client *Client) SlaveWasPromoted(ctx context.Context, tablet *topodatapb.Tablet) error { cc, c, err := client.dial(tablet) if err != nil { @@ -930,7 +930,7 @@ func (client *Client) SlaveWasPromoted(ctx context.Context, tablet *topodatapb.T return err } -// Deprecated +// SlaveWasRestarted is deprecated func (client *Client) SlaveWasRestarted(ctx context.Context, tablet *topodatapb.Tablet, parent *topodatapb.TabletAlias) error { cc, c, err := client.dial(tablet) if err != nil { diff --git a/go/vt/vttablet/tabletmanager/rpc_replication.go b/go/vt/vttablet/tabletmanager/rpc_replication.go index 4454e794bbe..2200cf3aad2 100644 --- a/go/vt/vttablet/tabletmanager/rpc_replication.go +++ b/go/vt/vttablet/tabletmanager/rpc_replication.go @@ -748,47 +748,47 @@ func (tm *TabletManager) handleRelayLogError(err error) error { return err } -// Deprecated delete after 7.0 +// SlaveStatus is deprecated func (tm *TabletManager) SlaveStatus(ctx context.Context) (*replicationdatapb.Status, error) { return tm.ReplicationStatus(ctx) } -// Deprecated delete after 7.0 +// StopSlave is deprecated func (tm *TabletManager) StopSlave(ctx context.Context) error { return tm.StopReplication(ctx) } -// Deprecated delete after 7.0 +// StopSlaveMinimum is deprecated func (tm *TabletManager) StopSlaveMinimum(ctx context.Context, position string, waitTime time.Duration) (string, error) { return tm.StopReplicationMinimum(ctx, position, waitTime) } -// Deprecated delete after 7.0 +// StartSlave is deprecated func (tm *TabletManager) StartSlave(ctx context.Context) error { return tm.StartReplication(ctx) } -// Deprecated delete after 7.0 +// StartSlaveUntilAfter is deprecated func (tm *TabletManager) StartSlaveUntilAfter(ctx context.Context, position string, waitTime time.Duration) error { return tm.StartReplicationUntilAfter(ctx, position, waitTime) } -// Deprecated delete after 7.0 +// GetSlaves is deprecated func (tm *TabletManager) GetSlaves(ctx context.Context) ([]string, error) { return tm.GetReplicas(ctx) } -// Deprecated delete after 7.0 +// InitSlave is deprecated func (tm *TabletManager) InitSlave(ctx context.Context, parent *topodatapb.TabletAlias, position string, timeCreatedNS int64) error { return tm.InitReplica(ctx, parent, position, timeCreatedNS) } -// Deprecated delete after 7.0 +// SlaveWasPromoted is deprecated func (tm *TabletManager) SlaveWasPromoted(ctx context.Context) error { return tm.ReplicaWasPromoted(ctx) } -// Deprecated delete after 7.0 +// SlaveWasRestarted is deprecated func (tm *TabletManager) SlaveWasRestarted(ctx context.Context, parent *topodatapb.TabletAlias) error { return tm.ReplicaWasRestarted(ctx, parent) } diff --git a/misc/git/hooks/staticcheck b/misc/git/hooks/staticcheck deleted file mode 100755 index f0ea8d5d543..00000000000 --- a/misc/git/hooks/staticcheck +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash - -# git staticcheck pre-commit hook - -if [ -z "$GOPATH" ]; then - echo "ERROR: pre-commit hook for staticcheck: \$GOPATH is empty. Please run 'source dev.env' to set the correct \$GOPATH." - exit 1 -fi - -# This script does not handle file names that contain spaces. -# Exclude auto-generated files (from proto or yacc compile). -gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '^go/.*\.go$' | grep -v '^go/vt/proto/' | grep -v 'go/vt/sqlparser/sql.go') -if [ "$gofiles" = "" ]; then - exit 0 -fi - -# xargs -n1 because dirname on MacOS does not support multiple arguments. -gopackages=$(echo $gofiles | xargs -n1 dirname | sort -u) - -warnings= - -# Run on one package at a time -gopackages_with_warnings=() -for gopackage in $gopackages -do - warningcount="$(go run honnef.co/go/tools/cmd/staticcheck "vitess.io/vitess/$gopackage" | wc -l)" - if [ "$warningcount" -gt "0" ]; then - warnings=YES - echo "$warningcount reports for:" - echo "go run honnef.co/go/tools/cmd/staticcheck vitess.io/vitess/$gopackage" - gopackages_with_warnings+=($gopackage) - fi -done - -[ -z "$warnings" ] && exit 0 - -# git doesn't give us access to user input, so let's steal it. -exec < /dev/tty -if [[ $? -eq 0 ]]; then - # interactive shell. Prompt the user. - echo - echo "Suggestions from the go 'staticcheck' program were found." - echo "They're not enforced, but we're pausing to let you know" - echo "before they get clobbered in the scrollback buffer." - echo - read -r -p 'Press enter to cancel, "s" to step through the warnings or type "ack" to continue: ' - if [ "$REPLY" = "ack" ]; then - exit 0 - fi - if [ "$REPLY" = "s" ]; then - first_file="true" - for gopackage in "${gopackages_with_warnings[@]}" - do - echo - if [ "$first_file" != "true" ]; then - echo "Press enter to show the warnings for the next file." - read - fi - go run honnef.co/go/tools/cmd/staticcheck "vitess.io/vitess/$gopackage" - first_file="false" - done - fi -else - # non-interactive shell (e.g. called from Eclipse). Just display the warnings. - for gopackage in "${gopackages_with_warnings[@]}" - do - go run honnef.co/go/tools/cmd/staticcheck "vitess.io/vitess/$gopackage" - done -fi -exit 1 From 842b0ccdf82f3e80d14b9667c97b685e18e1813e Mon Sep 17 00:00:00 2001 From: deepthi Date: Mon, 6 Jul 2020 17:31:19 -0700 Subject: [PATCH 2/2] fix lint error Signed-off-by: deepthi --- go/vt/worker/diff_utils.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/go/vt/worker/diff_utils.go b/go/vt/worker/diff_utils.go index 685b470afa7..f4d17579878 100644 --- a/go/vt/worker/diff_utils.go +++ b/go/vt/worker/diff_utils.go @@ -559,22 +559,22 @@ func (rd *RowDiffer) Go(log logutil.Logger) (dr DiffReport, err error) { // drain right, update count log.Errorf("Draining extra row(s) found on the right starting with: %v", right) - if count, err := rd.right.Drain(); err != nil { + var count int + if count, err = rd.right.Drain(); err != nil { return dr, err - } else { - dr.extraRowsRight += 1 + count } + dr.extraRowsRight += 1 + count return } if right == nil { // no more rows from the right // we know we have rows from left, drain, update count log.Errorf("Draining extra row(s) found on the left starting with: %v", left) - if count, err := rd.left.Drain(); err != nil { + var count int + if count, err = rd.left.Drain(); err != nil { return dr, err - } else { - dr.extraRowsLeft += 1 + count } + dr.extraRowsLeft += 1 + count return }