{"record":{"id":"2569f6dd8feea437","repo":"cayleygraph/cayley","slug":"couldn-t-write-version-v","errorCode":null,"errorMessage":"couldn't write version: %v","messagePattern":"couldn't write version: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"graph/kv/quadstore.go","lineNumber":197,"sourceCode":"\t\treturn nil, err\n\t}\n\tif !qs.exists.disabled {\n\t\tif sz, err := qs.getSize(); err != nil {\n\t\t\treturn nil, err\n\t\t} else if sz == 0 {\n\t\t\tqs.mapBloom = make(map[string]*boom.BloomFilter)\n\t\t\tqs.mapNodes = boom.NewBloomFilter(100*1000*1000, 0.05)\n\t\t}\n\t}\n\treturn qs, nil\n}\n\nfunc setVersion(ctx context.Context, db kv.KV, version int64) error {\n\treturn kv.Update(ctx, db, func(tx kv.Tx) error {\n\t\tvar buf [8]byte\n\t\tbinary.LittleEndian.PutUint64(buf[:], uint64(version))\n\t\tif err := tx.Put(ctx, metaBucket.AppendBytes([]byte(\"version\")), buf[:]); err != nil {\n\t\t\treturn fmt.Errorf(\"couldn't write version: %v\", err)\n\t\t}\n\t\treturn nil\n\t})\n}\n\nfunc (qs *QuadStore) getMetaInt(ctx context.Context, key string) (int64, error) {\n\tvar v int64\n\terr := kv.View(ctx, qs.db, func(tx kv.Tx) error {\n\t\tval, err := tx.Get(ctx, metaBucket.AppendBytes([]byte(key)))\n\t\tif err == kv.ErrNotFound {\n\t\t\treturn ErrNoBucket\n\t\t} else if err != nil {\n\t\t\treturn err\n\t\t}\n\t\tv, err = asInt64(val, 0)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/kv/quadstore.go#L179-L215","documentation":"setVersion failed to persist the schema/format version into the meta bucket because the underlying transaction Put returned an error. The version record is required for the KV store to open correctly, so this aborts store initialization.","triggerScenarios":"Opening/initializing a KV database (e.g. leveldb/bolt path) where tx.Put on the meta bucket fails — unwritable database path, corrupt or locked DB file, disk full, or the underlying KV refusing the write.","commonSituations":"Database directory with wrong permissions or read-only filesystem, another process holding a lock on the DB, full disk, or corrupted DB files after a crash.","solutions":["Check the DB path permissions and that the filesystem is writable, then retry opening the store.","Close any other process holding the DB open/locked (or delete a stale lock file if safe).","Inspect the wrapped error (%v) for the root cause; if the DB is corrupt, back it up and re-initialize a fresh store.","Free disk space if the disk is full."],"exampleFix":"// before\ncayley init --db_path /mnt/ro/data/db\n// after\ncayley init --db_path /var/lib/cayley/db  # writable path\n","handlingStrategy":"try-catch","validationCode":"if st, err := os.Stat(dbPath); err != nil || !isDirWritable(dbPath) { fail fast with a clear message }","typeGuard":null,"tryCatchPattern":"if err := setVersion(ctx, db, version); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) { /* check permissions/disk */ }\n    return fmt.Errorf(\"store init failed: %w\", err)\n}","preventionTips":["Verify the DB directory is writable and the disk has free space before opening the store.","Ensure no other process holds a lock on the database file.","Wrap store-open errors with context so the wrapped root cause is preserved.","Back up the DB directory before re-initializing after corruption."],"tags":["kv-store","initialization","persistence"],"backgroundTag":"database-write-failed","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}