Skip to content

Commit

Permalink
More test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed May 10, 2024
1 parent 858c0ad commit 26adaff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
8 changes: 6 additions & 2 deletions go/test/endtoend/vreplication/resharding_workflows_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,12 @@ func testVSchemaForSequenceAfterMoveTables(t *testing.T) {
execVtgateQuery(t, vtgateConn, "product", "insert into customer2(name) values('a')")
}
waitForRowCount(t, vtgateConn, "product", "customer2", 3+num+num)
want = fmt.Sprintf("[[INT32(%d)]]", 100+num+num-1)
waitForQueryResult(t, vtgateConn, "product", "select max(cid) from customer2", want)
//want = fmt.Sprintf("[[INT32(%d)]]", 100+num+num-1)
//waitForQueryResult(t, vtgateConn, "product", "select max(cid) from customer2", want)
res := execVtgateQuery(t, vtgateConn, "product", "select max(cid) from customer2")
cid, err := res.Rows[0][0].ToInt()
require.NoError(t, err)
require.GreaterOrEqual(t, cid, 100+num+num-1)
}

// testReplicatingWithPKEnumCols ensures that we properly apply binlog events
Expand Down
26 changes: 17 additions & 9 deletions go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"vitess.io/vitess/go/constants/sidecar"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/mysql/sqlerror"
"vitess.io/vitess/go/vt/schema"
"vitess.io/vitess/go/vt/vtenv"

"vitess.io/vitess/go/acl"
Expand All @@ -43,7 +44,6 @@ import (
"vitess.io/vitess/go/vt/dbconnpool"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/mysqlctl/tmutils"
"vitess.io/vitess/go/vt/schema"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/sidecardb"
"vitess.io/vitess/go/vt/sqlparser"
Expand Down Expand Up @@ -674,14 +674,9 @@ func (se *Engine) RegisterVersionEvent() error {
// the table schema for the gtid, it returns the latest table schema available in the
// database (updating the cache entry). If the table is not found in the cache, it will
// reload the cache from the database in case the table was created after the last schema
// reload. This function makes the schema cache a read-through cache for VReplication
// purposes.
// reload or the cache has not yet been initialized. This function makes the schema
// cache a read-through cache for VReplication purposes.
func (se *Engine) GetTableForPos(ctx context.Context, tableName sqlparser.IdentifierCS, gtid string) (*binlogdatapb.MinimalTable, error) {
tableNameStr := tableName.String()
if schema.IsInternalOperationTableName(tableNameStr) { // Internal tables should be ignored by VReplication
log.Infof("internal table %v found in vttablet schema: skipping for GTID search", tableNameStr)
return nil, nil
}
mt, err := se.historian.GetTableForPos(tableName, gtid)
if err != nil {
log.Infof("GetTableForPos returned error: %s", err.Error())
Expand All @@ -693,7 +688,14 @@ func (se *Engine) GetTableForPos(ctx context.Context, tableName sqlparser.Identi
// We got nothing from the historian, which generally means that it's not enabled.
se.mu.Lock()
defer se.mu.Unlock()
if st, ok := se.tables[tableNameStr]; ok {
tableNameStr := tableName.String()
if st, ok := se.tables[tableNameStr]; ok && tableNameStr != "dual" { // No need to refresh dual
// Test Engines (NewEngineForTests()) don't have a conns pool and are not
// supposed to talk to the database, so don't update the cache entry in that
// case.
if se.conns == nil {
return newMinimalTable(st), nil
}
// We have the table in our cache. Let's be sure that our table definition is
// up-to-date for the "current" position.
conn, err := se.conns.Get(ctx, nil)
Expand All @@ -706,6 +708,12 @@ func (se *Engine) GetTableForPos(ctx context.Context, tableName sqlparser.Identi
}
return newMinimalTable(st), nil
}
// It's expected that internal tables are not found within VReplication workflows.
// No need to refresh the cache for internal tables.
if schema.IsInternalOperationTableName(tableNameStr) {
log.Infof("internal table %v found in vttablet schema: skipping for GTID search", tableNameStr)
return nil, nil
}
// We don't currently have the table in the cache. This can happen when a table
// was created after the last schema reload (which happens at least every
// --queryserver-config-schema-reload-time).
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/tabletserver/schema/historian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/collations"

"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/sqlparser"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/sqlparser"
)

func getTable(name string, fieldNames []string, fieldTypes []querypb.Type, pks []int64) *binlogdatapb.MinimalTable {
Expand Down

0 comments on commit 26adaff

Please sign in to comment.