{"record":{"id":"ea805d14748f2817","repo":"dgraph-io/dgraph","slug":"while-parsing-kv-v-got-error-v","errorCode":null,"errorMessage":"while parsing KV: %+v, got error: %v","messagePattern":"while parsing KV: %\\+v, got error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/predicate_move.go","lineNumber":55,"sourceCode":"\temptyPayload      = api.Payload{}\n)\n\n// size of kvs won't be too big, we would take care before proposing.\nfunc populateKeyValues(ctx context.Context, kvs []*bpb.KV) error {\n\tglog.Infof(\"Writing %d keys\\n\", len(kvs))\n\tif len(kvs) == 0 {\n\t\treturn nil\n\t}\n\twriter := posting.NewTxnWriter(pstore)\n\tif err := writer.Write(&bpb.KVList{Kv: kvs}); err != nil {\n\t\treturn err\n\t}\n\tif err := writer.Flush(); err != nil {\n\t\treturn err\n\t}\n\tpk, err := x.Parse(kvs[0].Key)\n\tif err != nil {\n\t\treturn errors.Errorf(\"while parsing KV: %+v, got error: %v\", kvs[0], err)\n\t}\n\treturn schema.Load(pk.Attr)\n}\n\nfunc batchAndProposeKeyValues(ctx context.Context, kvs chan *pb.KVS) error {\n\tglog.Infoln(\"Receiving predicate. Batching and proposing key values\")\n\tn := groups().Node\n\tproposal := &pb.Proposal{}\n\tsize := 0\n\tvar pk x.ParsedKey\n\n\tfor kvPayload := range kvs {\n\t\tbuf := z.NewBufferSlice(kvPayload.GetData())\n\t\terr := buf.SliceIterate(func(s []byte) error {\n\t\t\tkv := &bpb.KV{}\n\t\t\tx.Check(proto.Unmarshal(s, kv))\n\t\t\tif len(pk.Attr) == 0 {\n\t\t\t\t// This only happens once.","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/predicate_move.go#L37-L73","documentation":"populateKeyValues is invoked by applyCommitted when a moved predicate's KVs are applied on the destination group. After writing the batch, it parses the first KV's key with x.Parse to load the predicate's schema. If that key cannot be parsed as a valid Dgraph key, this error is returned, indicating corrupt or out-of-protocol data in the moved KV stream.","triggerScenarios":"applyCommitted -> populateKeyValues receives a KV list whose first key fails x.Parse: key format is invalid (wrong byte prefix/length), data written by an incompatible Dgraph version, or corrupted bytes in the posting store during a predicate move.","commonSituations":"Rolling upgrades where source and destination Alphas run incompatible versions during a tablet move; bit-rot or manual tampering with the postings directory; custom tooling injecting malformed KVs into pstore.","solutions":["Retry the predicate move after verifying all Alphas run the same Dgraph version.","Inspect the failing KV printed in the error to identify the malformed key prefix.","If corruption is suspected, run `dgraph debug` on the source posting directory and restore the affected predicate from backup.","Re-move the tablet from a healthy source replica (another group member with correct data)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := x.Parse(kvs[0].Key); err != nil {\n\treturn errors.Errorf(\"refusing to apply corrupt KV: %v\", err)\n}","typeGuard":"func validDgraphKey(key []byte) bool {\n\t_, err := x.Parse(key)\n\treturn err == nil\n}","tryCatchPattern":"if err := applyCommitted(...); err != nil && strings.Contains(err.Error(), \"while parsing KV\") {\n\t// abort move, verify Alpha versions, restore predicate from backup\n}","preventionTips":["Keep all Alphas on the same Dgraph version during moves","Run `dgraph debug` on postings before moving a suspect predicate","Protect postings dirs from out-of-band writes","Restore corrupt predicates from backups before moving them"],"tags":["dgraph","predicate-move","key-parsing","data-corruption"],"backgroundTag":"invalid-key-format","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}