{"record":{"id":"385e7f08cc152cec","repo":"vitessio/vitess","slug":"copyschemashard-can-t-get-replication-position-af","errorCode":null,"errorMessage":"CopySchemaShard: can't get replication position after schema applied: %v","messagePattern":"CopySchemaShard: can't get replication position after schema applied: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/schema.go","lineNumber":247,"sourceCode":"\n\tdestTabletInfo, err := wr.ts.GetTablet(ctx, destShardInfo.PrimaryAlias)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"GetTablet(%v) failed: %v\", destShardInfo.PrimaryAlias, err)\n\t}\n\tfor _, createSQL := range createSQLstmts {\n\t\terr = wr.applySQLShard(ctx, destTabletInfo, createSQL)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"creating a table failed.\"+\n\t\t\t\t\" Most likely some tables already exist on the destination and differ from the source.\"+\n\t\t\t\t\" Please remove all to be copied tables from the destination manually and run this command again.\"+\n\t\t\t\t\" Full error: %v\", err)\n\t\t}\n\t}\n\n\t// Remember the replication position after all the above were applied.\n\tdestPrimaryPos, err := wr.tmc.PrimaryPosition(ctx, destTabletInfo.Tablet)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"CopySchemaShard: can't get replication position after schema applied: %v\", err)\n\t}\n\n\t// Although the copy was successful, we have to verify it to catch the case\n\t// where the database already existed on the destination, but with different\n\t// options e.g. a different character set.\n\t// In that case, MySQL would have skipped our CREATE DATABASE IF NOT EXISTS\n\t// statement.\n\tif !skipVerify {\n\t\tdiffs, err = schematools.CompareSchemas(ctx, wr.ts, wr.tmc, sourceTabletAlias, destShardInfo.PrimaryAlias, tables, excludeTables, includeViews)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"CopySchemaShard failed because schemas could not be compared finally: %v\", err)\n\t\t}\n\t\tif diffs != nil {\n\t\t\treturn fmt.Errorf(\"CopySchemaShard was not successful because the schemas between the two tablets %v and %v differ: %v\", sourceTabletAlias, destShardInfo.PrimaryAlias, diffs)\n\t\t}\n\t}\n\n\t// Notify Replicas to reload schema. This is best-effort.","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/schema.go#L229-L265","documentation":"After applying the schema on the destination primary, CopySchemaShard reads the destination primary's replication position via wr.tmc.PrimaryPosition to record where the schema change landed. If that tabletmanager RPC fails, the copy itself may have succeeded but the operation aborts because it cannot capture the post-apply position needed for verification.","triggerScenarios":"The destination primary becomes unreachable or its tabletmanager fails between the ApplySchema calls and the PrimaryPosition call - the primary crashes, is reparented mid-copy, or a state change occurs after the 30s applySQLShard timeout window.","commonSituations":"Destination primary failover occurred mid-copy; tablet restarted; vtctld-to-tablet RPC timeouts under heavy load.","solutions":["Verify the destination primary is alive and still primary (vtctldclient GetTablet <alias>), then retry CopySchemaShard.","If a reparent happened, complete it, then rerun the copy against the current primary.","Check tablet logs around the failure time for tabletmanager errors."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if _, err := wr.ts.GetTablet(ctx, destPrimaryAlias); err != nil {\n    return fmt.Errorf(\"destination primary unreachable before schema copy: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"err := wr.CopySchemaShard(ctx, src, dst, tables, excl, false)\nif err != nil && strings.Contains(err.Error(), \"replication position\") {\n    // wait for tablet/failover to settle, then retry\n}","preventionTips":["Don't run schema copies during failovers.","Ensure tabletmanager RPC timeouts are generous.","Monitor destination primary stability during the copy."],"tags":["go","replication","tabletmanager","race"],"backgroundTag":"tablet-rpc-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}