{"record":{"id":"e9b1f8972511d930","repo":"vitessio/vitess","slug":"copyschemashard-failed-because-schemas-could-not-b","errorCode":null,"errorMessage":"CopySchemaShard failed because schemas could not be compared initially: %v","messagePattern":"CopySchemaShard failed because schemas could not be compared initially: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/schema.go","lineNumber":215,"sourceCode":"}\n\n// CopySchemaShard copies the schema from a source tablet to the\n// specified shard.  The schema is applied directly on the primary of\n// the destination shard, and is propagated to the replicas through\n// binlogs.\nfunc (wr *Wrangler) CopySchemaShard(ctx context.Context, sourceTabletAlias *topodatapb.TabletAlias, tables, excludeTables []string, includeViews bool, destKeyspace, destShard string, waitReplicasTimeout time.Duration, skipVerify bool) error {\n\tdestShardInfo, err := wr.ts.GetShard(ctx, destKeyspace, destShard)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"GetShard(%v, %v) failed: %v\", destKeyspace, destShard, err)\n\t}\n\n\tif destShardInfo.PrimaryAlias == nil {\n\t\treturn fmt.Errorf(\"no primary in shard record %v/%v. Consider running 'vtctl InitShardPrimary' in case of a new shard or reparenting the shard to fix the topology data\", destKeyspace, destShard)\n\t}\n\n\tdiffs, err := schematools.CompareSchemas(ctx, wr.ts, wr.tmc, sourceTabletAlias, destShardInfo.PrimaryAlias, tables, excludeTables, includeViews)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"CopySchemaShard failed because schemas could not be compared initially: %v\", err)\n\t}\n\tif diffs == nil {\n\t\t// Return early because dest has already the same schema as source.\n\t\treturn nil\n\t}\n\n\treq := &tabletmanagerdatapb.GetSchemaRequest{Tables: tables, ExcludeTables: excludeTables, IncludeViews: includeViews}\n\tsourceSd, err := schematools.GetSchema(ctx, wr.ts, wr.tmc, sourceTabletAlias, req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"GetSchema(%v, %v, %v, %v) failed: %v\", sourceTabletAlias, tables, excludeTables, includeViews, err)\n\t}\n\n\tcreateSQLstmts := tmutils.SchemaDefinitionToSQLStrings(sourceSd)\n\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}","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/schema.go#L197-L233","documentation":"CopySchemaShard starts by comparing the source tablet's schema with the destination primary's schema via schematools.CompareSchemas. This error is returned when that initial comparison fails — either side's GetSchema RPC failed, a tablet was unreachable, or the comparison itself errored. It deliberately aborts before attempting any copy, so no schema changes have been applied when this is raised.","triggerScenarios":"Calling CopySchemaShard where the source tablet or destination primary is down/not serving, the tabletmanager GetSchema RPC fails or times out on either side, or CompareSchemas hits an internal error.","commonSituations":"Source tablet decommissioned between alias resolution and comparison; destination primary restarting; network partition between vtctld and either tablet; version mismatch causing schema parse failures.","solutions":["Check both tablets' health (vtctl GetTablet on source alias and dest primary) and ensure vttablet is serving.","Re-run CopySchemaShard after restoring connectivity — the failure is before any mutation, so it is safe to retry.","Inspect the wrapped inner error to determine which side (source vs dest) failed and why.","If timeouts are the cause, increase the context deadline or check for network latency between vtctld and tablets."],"exampleFix":"// before (dest primary unreachable)\nwr.CopySchemaShard(ctx, srcAlias, nil, nil, true, \"ks\", \"0\", timeout, false)\n// after: verify tablets then retry\nti, _ := wr.ts.GetTablet(ctx, destPrimaryAlias) // ensure reachable\nwr.CopySchemaShard(ctx, srcAlias, nil, nil, true, \"ks\", \"0\", timeout, false)","handlingStrategy":"retry","validationCode":"for _, alias := range []*topodatapb.TabletAlias{srcAlias, dstPrimaryAlias} {\n\tti, err := ts.GetTablet(ctx, alias)\n\tif err != nil { return err }\n\tif ti.State != topodatapb.TabletState_SERVING { return fmt.Errorf(\"tablet %v not serving\", alias) }\n}","typeGuard":null,"tryCatchPattern":"err := wr.CopySchemaShard(...)\nif err != nil && strings.Contains(err.Error(), \"could not be compared initially\") {\n\t// safe to retry: nothing was applied; fix tablet health then retry with backoff\n\ttime.Sleep(backoff)\n\treturn wr.CopySchemaShard(...)\n}","preventionTips":["Ensure both source and destination tablets are serving before copying","Retry safely — failure occurs before any schema mutation","Watch for tablet restarts and network issues between vtctld and tablets"],"tags":["schema-compare","tablet","rpc","copy-schema"],"backgroundTag":"tablet-rpc-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}