Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous code modifications based on observations made while doing a code walkthrough #12873

Merged
merged 6 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/mysql/mysql56_gtid_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestParseMysql56GTIDSetInvalid(t *testing.T) {

for _, input := range table {
_, err := ParseMysql56GTIDSet(input)
assert.Error(t, err, "parseMysql56GTIDSet(%#v) expected error, got none", err)
assert.Error(t, err, "ParseMysql56GTIDSet(%#v) expected error, got none", err)
deepthi marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
34 changes: 20 additions & 14 deletions go/test/endtoend/cluster/vttablet_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
"vitess.io/vitess/go/vt/sqlparser"
)

const vttabletStateTimeout = 30 * time.Second

// VttabletProcess is a generic handle for a running vttablet .
// It can be spawned manually
type VttabletProcess struct {
Expand Down Expand Up @@ -269,19 +271,19 @@ func (vttablet *VttabletProcess) GetTabletType() string {
return ""
}

// WaitForTabletStatus waits for 10 second till expected status is reached
// WaitForTabletStatus waits for one of the expected statuses to be reached
func (vttablet *VttabletProcess) WaitForTabletStatus(expectedStatus string) error {
return vttablet.WaitForTabletStatusesForTimeout([]string{expectedStatus}, 10*time.Second)
return vttablet.WaitForTabletStatusesForTimeout([]string{expectedStatus}, vttabletStateTimeout)
}

// WaitForTabletStatuses waits for 10 second till one of expected statuses is reached
// WaitForTabletStatuses waits for one of expected statuses is reached
func (vttablet *VttabletProcess) WaitForTabletStatuses(expectedStatuses []string) error {
return vttablet.WaitForTabletStatusesForTimeout(expectedStatuses, 10*time.Second)
return vttablet.WaitForTabletStatusesForTimeout(expectedStatuses, vttabletStateTimeout)
}

// WaitForTabletTypes waits for 10 second till one of expected statuses is reached
// WaitForTabletTypes waits for one of expected statuses is reached
func (vttablet *VttabletProcess) WaitForTabletTypes(expectedTypes []string) error {
return vttablet.WaitForTabletTypesForTimeout(expectedTypes, 10*time.Second)
return vttablet.WaitForTabletTypesForTimeout(expectedTypes, vttabletStateTimeout)
}

// WaitForTabletStatusesForTimeout waits till the tablet reaches to any of the provided statuses
Expand Down Expand Up @@ -335,7 +337,7 @@ func contains(arr []string, str string) bool {

// WaitForBinLogPlayerCount waits till binlog player count var matches
func (vttablet *VttabletProcess) WaitForBinLogPlayerCount(expectedCount int) error {
timeout := time.Now().Add(10 * time.Second)
timeout := time.Now().Add(vttabletStateTimeout)
for time.Now().Before(timeout) {
if vttablet.getVReplStreamCount() == fmt.Sprintf("%d", expectedCount) {
return nil
Expand All @@ -352,19 +354,23 @@ func (vttablet *VttabletProcess) WaitForBinLogPlayerCount(expectedCount int) err

// WaitForBinlogServerState wait for the tablet's binlog server to be in the provided state.
func (vttablet *VttabletProcess) WaitForBinlogServerState(expectedStatus string) error {
timeout := time.Now().Add(10 * time.Second)
for time.Now().Before(timeout) {
ctx, cancel := context.WithTimeout(context.Background(), vttabletStateTimeout)
defer cancel()
t := time.NewTicker(300 * time.Millisecond)
defer t.Stop()
for {
if vttablet.getVarValue("UpdateStreamState") == expectedStatus {
return nil
}
select {
case err := <-vttablet.exit:
return fmt.Errorf("process '%s' exited prematurely (err: %s)", vttablet.Name, err)
default:
time.Sleep(300 * time.Millisecond)
case <-ctx.Done():
return fmt.Errorf("vttablet %s, expected status of %s not reached before timeout of %v",
vttablet.TabletPath, expectedStatus, vttabletStateTimeout)
case <-t.C:
}
}
return fmt.Errorf("vttablet %s, expected status not reached", vttablet.TabletPath)
}

func (vttablet *VttabletProcess) getVReplStreamCount() string {
Expand All @@ -377,9 +383,9 @@ func (vttablet *VttabletProcess) getVarValue(keyname string) string {
return fmt.Sprintf("%v", object)
}

// TearDown shuts down the running vttablet service and fails after 10 seconds
// TearDown shuts down the running vttablet service and fails after a timeout
func (vttablet *VttabletProcess) TearDown() error {
return vttablet.TearDownWithTimeout(10 * time.Second)
return vttablet.TearDownWithTimeout(vttabletStateTimeout)
}

// Kill shuts down the running vttablet service immediately.
Expand Down
1 change: 1 addition & 0 deletions go/test/endtoend/vreplication/vreplication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ func TestCellAliasVreplicationWorkflow(t *testing.T) {
verifyClusterHealth(t, vc)

insertInitialData(t)

t.Run("VStreamFrom", func(t *testing.T) {
testVStreamFrom(t, keyspace, 2)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestLoadKeyspaceWithNoTablet(t *testing.T) {
Name: keyspaceName,
SchemaSQL: sqlSchema,
}
clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal"}
clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-config-schema-change-signal")
err = clusterInstance.StartUnshardedKeyspace(*keyspace, 0, false)
require.NoError(t, err)

Expand All @@ -86,7 +86,7 @@ func TestLoadKeyspaceWithNoTablet(t *testing.T) {
}

// Start vtgate with the schema_change_signal flag
clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"}
clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--schema_change_signal")
err = clusterInstance.StartVtgate()
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ func TestMain(m *testing.M) {
SchemaSQL: SchemaSQL,
VSchema: VSchema,
}
clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"}
clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal", "--queryserver-config-schema-change-signal-interval", "0.1", "--queryserver-config-strict-table-acl", "--queryserver-config-acl-exempt-acl", "userData1", "--table-acl-config", "dummy.json"}
clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--schema_change_signal")
deepthi marked this conversation as resolved.
Show resolved Hide resolved
clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs,
"--queryserver-config-schema-change-signal",
"--queryserver-config-schema-change-signal-interval", "0.1",
"--queryserver-config-strict-table-acl",
"--queryserver-config-acl-exempt-acl", "userData1",
"--table-acl-config", "dummy.json")
err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false)
if err != nil {
return 1
Expand Down
4 changes: 4 additions & 0 deletions go/vt/mysqlctl/binlogs_gtid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package mysqlctl_test is the blackbox tests for package mysqlctl.
deepthi marked this conversation as resolved.
Show resolved Hide resolved
// Tests that need to use fakemysqldaemon must be written as blackbox tests;
// since fakemysqldaemon imports mysqlctl, importing fakemysqldaemon in
// a `package mysqlctl` test would cause a circular import.
package mysqlctl

import (
Expand Down
4 changes: 2 additions & 2 deletions go/vt/mysqlctl/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ func newBuiltinDecompressor(engine string, reader io.Reader, logger logutil.Logg
return nil, err
}
decompressor = d
case "lz4":
case Lz4Compressor:
deepthi marked this conversation as resolved.
Show resolved Hide resolved
decompressor = io.NopCloser(lz4.NewReader(reader))
case "zstd":
case ZstdCompressor:
d, err := zstd.NewReader(reader)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion go/vt/schemadiff/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,6 @@ func (c *CreateTableEntity) TableDiff(other *CreateTableEntity, hints *DiffHints
}
if tableSpecHasChanged {
parentAlterTableEntityDiff = newAlterTableEntityDiff(alterTable)

}
for _, superfluousFulltextKey := range superfluousFulltextKeys {
alterTable := &sqlparser.AlterTable{
Expand Down
6 changes: 3 additions & 3 deletions go/vt/servenv/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ func TestVersionString(t *testing.T) {
buildTimePretty: "time is now",
buildGitRev: "d54b87ca0be09b678bb4490060e8f23f890ddb92",
buildGitBranch: "gitBranch",
goVersion: "1.19.3",
goVersion: "1.20.2",
goOS: "amiga",
goArch: "amd64",
version: "v1.2.3-SNAPSHOT",
}

assert.Equal(t, "Version: v1.2.3-SNAPSHOT (Git revision d54b87ca0be09b678bb4490060e8f23f890ddb92 branch 'gitBranch') built on time is now by user@host using 1.19.3 amiga/amd64", v.String())
assert.Equal(t, "Version: v1.2.3-SNAPSHOT (Git revision d54b87ca0be09b678bb4490060e8f23f890ddb92 branch 'gitBranch') built on time is now by user@host using 1.20.2 amiga/amd64", v.String())

v.jenkinsBuildNumber = 422

assert.Equal(t, "Version: v1.2.3-SNAPSHOT (Jenkins build 422) (Git revision d54b87ca0be09b678bb4490060e8f23f890ddb92 branch 'gitBranch') built on time is now by user@host using 1.19.3 amiga/amd64", v.String())
assert.Equal(t, "Version: v1.2.3-SNAPSHOT (Jenkins build 422) (Git revision d54b87ca0be09b678bb4490060e8f23f890ddb92 branch 'gitBranch') built on time is now by user@host using 1.20.2 amiga/amd64", v.String())

assert.Equal(t, "8.0.30-Vitess", v.MySQLVersion())
}
1 change: 0 additions & 1 deletion go/vt/vtexplain/vtexplain_vttablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ func (t *explainTablet) HandleQuery(c *mysql.Conn, query string, callback func(*
// return the pre-computed results for any schema introspection queries
tEnv := t.vte.getGlobalTabletEnv()
result := tEnv.getResult(query)

if result != nil {
return callback(result)
}
Expand Down
2 changes: 2 additions & 0 deletions go/vt/vttablet/tabletmanager/tm_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,10 @@ func (tm *TabletManager) initTablet(ctx context.Context) error {
// instance of a startup timeout). Upon running this code
// again, we want to fix ShardReplication.
if updateErr := topo.UpdateTabletReplicationData(ctx, tm.TopoServer, tablet); updateErr != nil {
log.Errorf("UpdateTabletReplicationData failed for tablet %v: %v", topoproto.TabletAliasString(tablet.Alias), updateErr)
return vterrors.Wrap(updateErr, "UpdateTabletReplicationData failed")
}
log.Infof("Successfully updated tablet replication data for alias: %v", topoproto.TabletAliasString(tablet.Alias))

// Then overwrite everything, ignoring version mismatch.
if err := tm.TopoServer.UpdateTablet(ctx, topo.NewTabletInfo(tablet, nil)); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/binlog/binlogplayer"
"vitess.io/vitess/go/vt/log"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
qh "vitess.io/vitess/go/vt/vttablet/tabletmanager/vreplication/queryhistory"
)
Expand Down
6 changes: 2 additions & 4 deletions go/vt/wrangler/testlib/apply_schema_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ limitations under the License.
package testlib

import (
"context"
"strings"
"testing"
"time"

"vitess.io/vitess/go/vt/discovery"

"context"

"vitess.io/vitess/go/mysql/fakesqldb"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/discovery"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl/tmutils"
"vitess.io/vitess/go/vt/topo/memorytopo"
Expand Down
5 changes: 0 additions & 5 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ func (t *Test) run(dir, dataDir string) ([]byte, error) {
testCmd = append(testCmd, "--partial-keyspace")
}
testCmd = append(testCmd, extraArgs...)
if *docker {
// Teardown is unnecessary since Docker kills everything.
// Go cluster doesn't recognize 'skip-teardown' flag so commenting it out for now.
// testCmd = append(testCmd, "--skip-teardown")
}
}

var cmd *exec.Cmd
Expand Down
2 changes: 1 addition & 1 deletion tools/rowlog/rowlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func processPositionResult(gtidset string) (string, string) {
subs := strings.Split(arr[1], "-")
id, err := strconv.Atoi(subs[0])
if err != nil {
fmt.Printf(err.Error())
fmt.Println(err.Error())
return "", ""
}
firstPos := arr[0] + ":" + strconv.Itoa(id) // subs[0]
Expand Down