{"record":{"id":"51e8092840c07ea7","repo":"vitessio/vitess","slug":"createtablet-v-w","errorCode":null,"errorMessage":"CreateTablet(%v): %w","messagePattern":"CreateTablet\\((.+?)\\): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/topo/helpers/copy.go","lineNumber":146,"sourceCode":"\t\t\tfor _, tabletAlias := range tabletAliases {\n\t\t\t\t// read the source tablet\n\t\t\t\tti, err := fromTS.GetTablet(ctx, tabletAlias)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"GetTablet(%v): %w\", tabletAlias, err)\n\t\t\t\t}\n\n\t\t\t\t// try to create the destination\n\t\t\t\terr = toTS.CreateTablet(ctx, ti.Tablet)\n\t\t\t\tif topo.IsErrType(err, topo.NodeExists) {\n\t\t\t\t\t// update the destination tablet\n\t\t\t\t\tlog.Warn(fmt.Sprintf(\"tablet %v already exists, updating it\", tabletAlias))\n\t\t\t\t\t_, err = toTS.UpdateTabletFields(ctx, tabletAlias, func(t *topodatapb.Tablet) error {\n\t\t\t\t\t\tproto.Merge(t, ti.Tablet)\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"CreateTablet(%v): %w\", tabletAlias, err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// CopyShardReplications will create the ShardReplication objects in\n// the destination topo.\nfunc CopyShardReplications(ctx context.Context, fromTS, toTS *topo.Server) error {\n\tkeyspaces, err := fromTS.GetKeyspaces(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"fromTS.GetKeyspaces: %w\", err)\n\t}\n\n\tcells, err := fromTS.GetCellInfoNames(ctx)\n\tif err != nil {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/topo/helpers/copy.go#L128-L164","documentation":"CopyTablets copies tablet objects from a source topo server to a destination topo server. This error wraps any failure encountered when creating a tablet in the destination topo, either via toTS.CreateTablet or via toTS.UpdateTabletFields, and prefixes it with the tablet alias so the failing tablet is identifiable.","triggerScenarios":"Calling topo/helpers.CopyTablets when the destination topo rejects a tablet insert/update: node already exists, destination cell not present in destination topo, or an underlying connection error from toTS.UpdateTabletFields.","commonSituations":"Copying a topology into a partially-initialized destination topo during vtctld copy operations or tests (copyTopos); destination already contains the tablet from a previous copy; network outage between the destination topo server and its backend.","solutions":["Check the wrapped inner error to find the actual cause (e.g. node already exists in destination topo)","Ensure destination topo cells are initialized (CreateCellInfo) before CopyTablets","Clean or diff destination tablets that already exist before re-running the copy","Verify destination topo server connectivity and credentials"],"exampleFix":"// before\n_, err = toTS.CreateTablet(ctx, ti.Tablet)\n// after\nerr := toTS.CreateTablet(ctx, ti.Tablet)\nif topo.IsErrType(err, topo.NodeExists) {\n    _, err = toTS.UpdateTabletFields(ctx, tabletAlias, func(t *topodatapb.Tablet) error {\n        proto.Merge(t, ti.Tablet)\n        return nil\n    })\n}","handlingStrategy":"try-catch","validationCode":"cells, err := toTS.GetCellInfoNames(ctx)\nif err != nil || len(cells) == 0 {\n    return fmt.Errorf(\"destination topo cells not ready: %w\", err)\n}","typeGuard":"func isNodeExists(err error) bool { return topo.IsErrType(err, topo.NodeExists) }","tryCatchPattern":"err := helpers.CopyTablets(ctx, fromTS, toTS)\nif err != nil {\n    var tabletErr error\n    if errors.Unwrap(err) != nil { tabletErr = errors.Unwrap(err) }\n    log.Errorf(\"copy failed: %v (cause: %v)\", err, tabletErr)\n}","preventionTips":["Initialize destination topo cells before copying tablets","Make the copy idempotent: handle topo.NodeExists via UpdateTabletFields","Check destination topo connectivity before starting bulk copies"],"tags":["topo","tablet-copy","error-wrapping"],"backgroundTag":"topo-tablet-create-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}