dgraph-io/dgraph · error
while parsing KV: %+v, got error: %v
Error message
while parsing KV: %+v, got error: %v
What it means
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.
Source
Thrown at worker/predicate_move.go:55
emptyPayload = api.Payload{}
)
// size of kvs won't be too big, we would take care before proposing.
func populateKeyValues(ctx context.Context, kvs []*bpb.KV) error {
glog.Infof("Writing %d keys\n", len(kvs))
if len(kvs) == 0 {
return nil
}
writer := posting.NewTxnWriter(pstore)
if err := writer.Write(&bpb.KVList{Kv: kvs}); err != nil {
return err
}
if err := writer.Flush(); err != nil {
return err
}
pk, err := x.Parse(kvs[0].Key)
if err != nil {
return errors.Errorf("while parsing KV: %+v, got error: %v", kvs[0], err)
}
return schema.Load(pk.Attr)
}
func batchAndProposeKeyValues(ctx context.Context, kvs chan *pb.KVS) error {
glog.Infoln("Receiving predicate. Batching and proposing key values")
n := groups().Node
proposal := &pb.Proposal{}
size := 0
var pk x.ParsedKey
for kvPayload := range kvs {
buf := z.NewBufferSlice(kvPayload.GetData())
err := buf.SliceIterate(func(s []byte) error {
kv := &bpb.KV{}
x.Check(proto.Unmarshal(s, kv))
if len(pk.Attr) == 0 {
// This only happens once.View on GitHub (pinned to 759e242be6)
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).
Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := x.Parse(kvs[0].Key); err != nil {
return errors.Errorf("refusing to apply corrupt KV: %v", err)
} Type guard
func validDgraphKey(key []byte) bool {
_, err := x.Parse(key)
return err == nil
} Try / catch
if err := applyCommitted(...); err != nil && strings.Contains(err.Error(), "while parsing KV") {
// abort move, verify Alpha versions, restore predicate from backup
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- while parsing kv: %+v, got error: %v
- Predicate not specified
- Server is not leader of this group
- Expecting first key to be schema key: %+v
- ReceivePredicate failed: Not the leader of group
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/ea805d14748f2817.
Report an issue: GitHub.