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

[release-19.0] VReplication Atomic Copy Workflows: fix bugs around concurrent inserts (#17772) #17791

Merged
merged 3 commits into from
Feb 17, 2025
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
5 changes: 4 additions & 1 deletion go/test/endtoend/vreplication/fk_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ func TestFKExt(t *testing.T) {
setSidecarDBName("_vt")

// Ensure that there are multiple copy phase cycles per table.
extraVTTabletArgs = append(extraVTTabletArgs, "--vstream_packet_size=256", "--queryserver-config-schema-change-signal")
extraVTTabletArgs = append(extraVTTabletArgs,
"--vstream_packet_size=256",
"--queryserver-config-schema-change-signal",
parallelInsertWorkers)
extraVTGateArgs = append(extraVTGateArgs, "--schema_change_signal=true", "--planner-version", "Gen4")
defer func() { extraVTTabletArgs = nil }()
initFKExtConfig(t)
Expand Down
1 change: 1 addition & 0 deletions go/test/endtoend/vreplication/fk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const testWorkflowFlavor = workflowFlavorRandom
// 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.
func TestFKWorkflow(t *testing.T) {
setSidecarDBName("_vt")
extraVTTabletArgs = []string{
// Ensure that there are multiple copy phase cycles per table.
"--vstream_packet_size=256",
Expand Down
17 changes: 8 additions & 9 deletions go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@
defer rowsCopiedTicker.Stop()

parallelism := getInsertParallelism()
// For now do not support concurrent inserts for atomic copies.
if parallelism > 1 {
parallelism = 1
log.Infof("Disabling concurrent inserts for atomic copies")
}

Check warning on line 89 in go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go#L89

Added line #L89 was not covered by tests
copyWorkerFactory := vc.newCopyWorkerFactory(parallelism)
var copyWorkQueue *vcopierCopyWorkQueue

Expand All @@ -114,7 +110,6 @@
resp.TableName, len(resp.Fields), len(resp.Rows), resp.Gtid, resp.Lastpk)
tableName := resp.TableName
gtid = resp.Gtid

updateRowsCopied := func() error {
updateRowsQuery := binlogplayer.GenerateUpdateRowsCopied(vc.vr.id, vc.vr.stats.CopyRowCount.Get())
_, err := vc.vr.dbClient.Execute(updateRowsQuery)
Expand Down Expand Up @@ -204,6 +199,10 @@
log.Infof("copying table %s with lastpk %v", tableName, lastpkbv)
// Prepare a vcopierCopyTask for the current batch of work.
currCh := make(chan *vcopierCopyTaskResult, 1)

if parallelism > 1 {
resp = resp.CloneVT()
}

Check warning on line 205 in go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go#L202-L205

Added lines #L202 - L205 were not covered by tests
currT := newVCopierCopyTask(newVCopierCopyTaskArgs(resp.Rows, resp.Lastpk))

// Send result to the global resultCh and currCh. resultCh is used by
Expand Down Expand Up @@ -291,12 +290,12 @@
log.Infof("Copy of %v stopped", state.currentTableName)
return fmt.Errorf("CopyAll was interrupted due to context expiration")
default:
if err := vc.deleteCopyState(state.currentTableName); err != nil {
return err
}
if copyWorkQueue != nil {
copyWorkQueue.close()
}
if err := vc.deleteCopyState(state.currentTableName); err != nil {
return err
}

Check warning on line 298 in go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go#L296-L298

Added lines #L296 - L298 were not covered by tests
if err := vc.updatePos(ctx, gtid); err != nil {
return err
}
Expand Down
Loading