{"record":{"id":"5450517f725e03e3","repo":"hyperledger/fabric","slug":"error-writing-leveldb-key-v","errorCode":null,"errorMessage":"error writing leveldb key [%#v]","messagePattern":"error writing leveldb key \\[%#v\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/ledger/util/leveldbhelper/leveldb_helper.go","lineNumber":138,"sourceCode":"\t// Here we simulate the desired behavior that the key is in the database.\n\tif value == nil {\n\t\tvalue = []byte{}\n\t}\n\treturn value, nil\n}\n\n// Put saves the key/value\nfunc (dbInst *DB) Put(key []byte, value []byte, sync bool) error {\n\tdbInst.mutex.RLock()\n\tdefer dbInst.mutex.RUnlock()\n\two := dbInst.writeOptsNoSync\n\tif sync {\n\t\two = dbInst.writeOptsSync\n\t}\n\terr := dbInst.db.Put(key, value, wo)\n\tif err != nil {\n\t\tlogger.Errorf(\"Error writing leveldb key [%#v]\", key)\n\t\treturn errors.Wrapf(err, \"error writing leveldb key [%#v]\", key)\n\t}\n\treturn nil\n}\n\n// Delete deletes the given key\nfunc (dbInst *DB) Delete(key []byte, sync bool) error {\n\tdbInst.mutex.RLock()\n\tdefer dbInst.mutex.RUnlock()\n\two := dbInst.writeOptsNoSync\n\tif sync {\n\t\two = dbInst.writeOptsSync\n\t}\n\terr := dbInst.db.Delete(key, wo)\n\tif err != nil {\n\t\tlogger.Errorf(\"Error deleting leveldb key [%#v]\", key)\n\t\treturn errors.Wrapf(err, \"error deleting leveldb key [%#v]\", key)\n\t}\n\treturn nil","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/util/leveldbhelper/leveldb_helper.go#L120-L156","documentation":"DB.Put wraps goleveldb write failures with the key being written; the key is also logged. It means the key/value could not be persisted, whether or not the sync write option was requested. Callers include ledger ID creation and ledger status updates, so this typically breaks ledger lifecycle operations.","triggerScenarios":"Writing after DB close; leveldb manifest or log file write failure (disk full, permissions); corruption during compaction interleaving with the write.","commonSituations":"Disk full on the peer's ledger volume; DB handle shared across components where one closes it early; read-only filesystem after container restart.","solutions":["Check free disk space on the ledger data volume.","Ensure no component closes the shared DB while writers are active.","Inspect the wrapped goleveldb error for corruption and restore/re-create the DB if needed.","Retry the operation if the underlying error was transient (I/O scheduling, temporary resource limits)."],"exampleFix":"// before\nif err := db.Put(key, value, true); err != nil { return err }\n// after\nif err := db.Put(key, value, true); err != nil {\n  return fmt.Errorf(\"persisting key %#v failed, check disk space and db state: %w\", key, err)\n}","handlingStrategy":"try-catch","validationCode":"if freeSpace(dbPath) < minFreeBytes {\n  return errors.New(\"insufficient disk space for leveldb write\")\n}","typeGuard":"func isPutErr(err error) bool {\n  return err != nil && strings.Contains(err.Error(), \"error writing leveldb key\")\n}","tryCatchPattern":"if err := db.Put(key, value, true); err != nil {\n  return fmt.Errorf(\"failed persisting %#v: %w\", key, err)\n}","preventionTips":["Monitor free disk space on ledger volumes","Never close a shared DB while other writers are active","Use sync=true for data that must survive crashes","Retry transient I/O failures before failing the operation"],"tags":["leveldb","storage","golang"],"backgroundTag":"leveldb-write-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}