Skip to content

Commit

Permalink
Self-review
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps committed Mar 11, 2024
1 parent 7c23bae commit ad71d89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 2 additions & 0 deletions go/test/endtoend/vreplication/fk_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

package vreplication

// The tables in the schema are selected so that we have one parent/child table with names in reverse lexical order
// (child before parent), t1,t2 are in lexical order, and t11,t12 have valid circular foreign key constraints.
var (
initialFKSchema = `
create table parent(id int, name varchar(128), primary key(id)) engine=innodb;
Expand Down
32 changes: 24 additions & 8 deletions go/test/endtoend/vreplication/fk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import (

const testWorkflowFlavor = workflowFlavorRandom

var counter int = 100

// TestFKWorkflow runs a MoveTables workflow with atomic copy for a db with foreign key constraints.
// It inserts initial data, then simulates load. We insert both child rows with foreign keys and those without,
// i.e. with foreign_key_checks=0.
Expand Down Expand Up @@ -130,6 +128,14 @@ func TestFKWorkflow(t *testing.T) {
<-ch
}
mt.Complete()
vtgateConn, closeConn := getVTGateConn()
defer closeConn()

t11Count := getRowCount(t, vtgateConn, "t11")
t12Count := getRowCount(t, vtgateConn, "t12")
require.Greater(t, t11Count, 1)
require.Greater(t, t12Count, 1)
require.Equal(t, t11Count, t12Count)
}

func insertInitialFKData(t *testing.T) {
Expand All @@ -139,12 +145,21 @@ func insertInitialFKData(t *testing.T) {
sourceKeyspace := "fksource"
shard := "0"
db := fmt.Sprintf("%s:%s", sourceKeyspace, shard)
log.Infof("Inserting initial FK data")
execMultipleQueries(t, vtgateConn, db, initialFKData)
waitForRowCount(t, vtgateConn, db, "parent", 2)
waitForRowCount(t, vtgateConn, db, "child", 3)
waitForRowCount(t, vtgateConn, db, "t1", 2)
waitForRowCount(t, vtgateConn, db, "t2", 3)
log.Infof("Done inserting initial FK data")

type tableCounts struct {
name string
count int
}
for _, table := range []tableCounts{
{"parent", 2}, {"child", 3},
{"t1", 2}, {"t2", 3},
{"t11", 1}, {"t12", 1},
} {
waitForRowCount(t, vtgateConn, db, table.name, table.count)
}
})
}

Expand All @@ -170,6 +185,7 @@ func newFKLoadSimulator(t *testing.T, ctx context.Context) *fkLoadSimulator {
}
}

var indexCounter int = 100 // used to insert into t11 and t12
func (ls *fkLoadSimulator) simulateLoad() {
t := ls.t
var err error
Expand All @@ -194,9 +210,9 @@ func (ls *fkLoadSimulator) simulateLoad() {
ls.delete()
}
for _, table := range []string{"t11", "t12"} {
query := fmt.Sprintf("insert /*+ SET_VAR(foreign_key_checks=0) */ into fksource.%s values(%d, %d)", table, counter, counter)
query := fmt.Sprintf("insert /*+ SET_VAR(foreign_key_checks=0) */ into fksource.%s values(%d, %d)", table, indexCounter, indexCounter)
ls.exec(query)
counter++
indexCounter++
}
require.NoError(t, err)
time.Sleep(10 * time.Millisecond)
Expand Down
3 changes: 2 additions & 1 deletion proto/tabletmanagerdata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ message ApplySchemaRequest {
SchemaDefinition before_schema = 4;
SchemaDefinition after_schema = 5;
string sql_mode = 6;
// BatchSize indicates how many queries to apply together
// BatchSize indicates how many queries to apply together.
int64 batch_size = 7;
// SetForeignKeyChecksOff will result in setting foreign_key_checks to off before applying the schema.
bool set_foreign_key_checks_off = 8;
}

Expand Down

0 comments on commit ad71d89

Please sign in to comment.