vitessio/vitess · error

failed to marshal pk fields and value into query result: %s

Error message

failed to marshal pk fields and value into query result: %s

What it means

At the end of copying a table, vcopier logs the last copied primary key by marshalling the PK fields and last row into a prototext QueryResult. If prototext.Marshal fails (unexpected), copyTable returns this wrapping error instead of losing the progress log.

Source

Thrown at go/vt/vttablet/tabletmanager/vreplication/vcopier.go:666

					terrs = append(terrs, result.err)
				}
			}
		default:
			empty = true
		}
	}
	if terr := formatTaskError(terrs); terr != nil {
		log.Warn(fmt.Sprintf("task error in workflow %s: %v", vc.vr.WorkflowName, terr))
		return terr
	}

	// Get the last committed pk into a loggable form.
	lastpkbuf, merr := prototext.Marshal(&querypb.QueryResult{
		Fields: pkfields,
		Rows:   []*querypb.Row{lastpk},
	})
	if merr != nil {
		return fmt.Errorf("failed to marshal pk fields and value into query result: %s", merr.Error())
	}
	lastpkbv := map[string]*querypb.BindVariable{
		"lastpk": {
			Type:  sqltypes.VarBinary,
			Value: lastpkbuf,
		},
	}

	// A context expiration was probably caused by a PlannedReparentShard or an
	// elapsed copy phase duration. Those are normal, non-error interruptions
	// of a copy phase.
	select {
	case <-ctx.Done():
		log.Info(fmt.Sprintf("Copy of %v stopped at lastpk: %v", tableName, lastpkbv))
		return nil
	default:
	}
	if serr != nil {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Collect vttablet logs and report — this indicates an internal inconsistency in the copy plan's pkfields
  2. Restart the workflow copy phase to rebuild the plan from current schema
  3. Ensure all Vitess components run the same version to avoid protobuf mismatches
Defensive patterns

Strategy: try-catch

Try / catch

if err := copyTable(ctx, ...); err != nil {
  if strings.Contains(err.Error(), "failed to marshal pk fields") {
    // log and report: internal protobuf inconsistency; restart copy phase
  }
  return err
}

Prevention

When it happens

Trigger: prototext.Marshal of &querypb.QueryResult{Fields: pkfields, Rows: []*querypb.Row{lastpk}} returns an error in copyTable; this is nearly always caused by malformed protobuf state (e.g. nil/invalid field descriptors) rather than user input.

Common situations: Very rare; indicates an internal bug, corrupted plan metadata (bad pkfields), or a binary/protobuf version mismatch between components.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/6d5d811b0d7ee499. Report an issue: GitHub.