{"record":{"id":"5f754c7b639a9104","repo":"dgraph-io/dgraph","slug":"while-copying-value","errorCode":null,"errorMessage":"while copying value","messagePattern":"while copying value","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/backup.go","lineNumber":666,"sourceCode":"\t\t\tif item.IsDeletedOrExpired() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tparsedKey, err := x.Parse(item.Key())\n\t\t\tif err != nil {\n\t\t\t\tglog.Errorf(\"error %v while parsing key %v during backup. Skipping...\",\n\t\t\t\t\terr, hex.EncodeToString(item.Key()))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// This check makes sense only for the schema keys. The types are not stored in it.\n\t\t\tif _, ok := predMap[parsedKey.Attr]; !parsedKey.IsType() && !ok {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tkv := y.NewKV(tl.alloc)\n\t\t\tif err := item.Value(func(val []byte) error {\n\t\t\t\tkv.Value = append(kv.Value, val...)\n\t\t\t\treturn nil\n\t\t\t}); err != nil {\n\t\t\t\treturn errors.Wrapf(err, \"while copying value\")\n\t\t\t}\n\n\t\t\tbackupKey, err := tl.toBackupKey(item.Key())\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tkv.Key = backupKey\n\t\t\tkv.UserMeta = tl.alloc.Copy([]byte{item.UserMeta()})\n\t\t\tkv.Version = item.Version()\n\t\t\tkv.ExpiresAt = item.ExpiresAt()\n\t\t\tlist.Kv = append(list.Kv, kv)\n\t\t}\n\t\treturn writeKVList(list, cWriter)\n\t}\n\n\tfor _, prefix := range []byte{x.ByteSchema, x.ByteType} {\n\t\tif err := writePrefix(prefix); err != nil {\n\t\t\tglog.Errorf(\"While writing prefix %d to backup: %v\", prefix, err)","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/backup.go#L648-L684","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the wrapped inner error to identify the failing badger item/key","Run badger value-log recovery or restore from a known-good backup","Check disk health and free space on the pstore mount","If corruption is limited, drop-and-replay affected tablets, then re-run the backup"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before backup, check pstore disk health and free space\nif free, err := diskFree(pstoreDir); err != nil || free < minRequiredBytes {\n    return errors.New(\"insufficient disk space or unreadable pstore; aborting backup\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := BackupGroup(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"while copying value\") {\n    glog.Errorf(\"badger value read failed during backup: %v\", errors.Cause(err))\n    // run badger recovery / restore from good backup before retrying\n}","preventionTips":["Monitor pstore disk health (SMART) and free space","Run badger integrity checks after unclean shutdowns","Avoid deleting/truncating DB files while a backup runs","Keep regular verified backups so corruption can be recovered from"],"tags":["badger","backup","corruption","io"],"backgroundTag":"badger-value-read-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}