dgraph-io/dgraph · error

while copying value

Error message

while copying value

What it means

During backup stream iteration, each badger item's value is copied into a freshly allocated KV. If item.Value's callback fails (badger read error, corrupted value log, I/O failure reading the value), the error is wrapped with this message, aborting the backup.

Source

Thrown at worker/backup.go:666

			if item.IsDeletedOrExpired() {
				continue
			}
			parsedKey, err := x.Parse(item.Key())
			if err != nil {
				glog.Errorf("error %v while parsing key %v during backup. Skipping...",
					err, hex.EncodeToString(item.Key()))
				continue
			}
			// This check makes sense only for the schema keys. The types are not stored in it.
			if _, ok := predMap[parsedKey.Attr]; !parsedKey.IsType() && !ok {
				continue
			}
			kv := y.NewKV(tl.alloc)
			if err := item.Value(func(val []byte) error {
				kv.Value = append(kv.Value, val...)
				return nil
			}); err != nil {
				return errors.Wrapf(err, "while copying value")
			}

			backupKey, err := tl.toBackupKey(item.Key())
			if err != nil {
				return err
			}
			kv.Key = backupKey
			kv.UserMeta = tl.alloc.Copy([]byte{item.UserMeta()})
			kv.Version = item.Version()
			kv.ExpiresAt = item.ExpiresAt()
			list.Kv = append(list.Kv, kv)
		}
		return writeKVList(list, cWriter)
	}

	for _, prefix := range []byte{x.ByteSchema, x.ByteType} {
		if err := writePrefix(prefix); err != nil {
			glog.Errorf("While writing prefix %d to backup: %v", prefix, err)

View on GitHub (pinned to 759e242be6)

Solutions

  1. Inspect the wrapped inner error to identify the failing badger item/key
  2. Run badger value-log recovery or restore from a known-good backup
  3. Check disk health and free space on the pstore mount
  4. If corruption is limited, drop-and-replay affected tablets, then re-run the backup
Defensive patterns

Strategy: try-catch

Validate before calling

// before backup, check pstore disk health and free space
if free, err := diskFree(pstoreDir); err != nil || free < minRequiredBytes {
    return errors.New("insufficient disk space or unreadable pstore; aborting backup")
}

Try / catch

resp, err := BackupGroup(ctx, req)
if err != nil && strings.Contains(err.Error(), "while copying value") {
    glog.Errorf("badger value read failed during backup: %v", errors.Cause(err))
    // run badger recovery / restore from good backup before retrying
}

Prevention

When it happens

Trigger: WriteBackup iterating a badger iterator hits an item whose value cannot be read — corrupted value log file, disk read error, or item truncated/expired mid-scan on the pstore.

Common situations: Badger value log corruption after a crash; disk failure or full disk on the pstore; backing up while the DB files are being deleted/truncated; running backup on a corrupted post-restore pstore.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/5f754c7b639a9104. Report an issue: GitHub.