cayleygraph/cayley · error

cannot get %s: %v

Error message

cannot get %s: %v

What it means

incMetaInt reads the current counter value via getMetaIntTx and wraps any non-ErrNotFound read failure as "cannot get %s: %v" where %s is the meta key (e.g. horizon or size counters). Callers incSize and genIDs use it to advance counters within a write transaction.

Source

Thrown at graph/kv/indexing.go:251

}

func (qs *QuadStore) getMetaIntTx(ctx context.Context, tx kv.Tx, key string) (int64, error) {
	val, err := tx.Get(ctx, metaBucket.AppendBytes([]byte(key)))
	if err == kv.ErrNotFound {
		return 0, err
	} else if err != nil {
		return 0, fmt.Errorf("cannot get horizon value: %v", err)
	}
	return int64(binary.LittleEndian.Uint64(val)), nil
}

func (qs *QuadStore) incMetaInt(ctx context.Context, tx kv.Tx, key string, n int64) (int64, error) {
	if n == 0 {
		return 0, nil
	}
	v, err := qs.getMetaIntTx(ctx, tx, key)
	if err != nil && err != kv.ErrNotFound {
		return 0, fmt.Errorf("cannot get %s: %v", key, err)
	}
	start := v
	v += n

	buf := make([]byte, 8) // bolt needs all slices available on Commit
	binary.LittleEndian.PutUint64(buf, uint64(v))

	err = tx.Put(ctx, metaBucket.AppendBytes([]byte(key)), buf)
	if err != nil {
		return 0, fmt.Errorf("cannot inc %s: %v", key, err)
	}
	return start, nil
}

func (qs *QuadStore) genIDs(ctx context.Context, tx kv.Tx, n int) (uint64, error) {
	if n == 0 {
		return 0, nil
	}

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Read the wrapped key and inner error to identify which counter read failed and why; fix the backend issue.
  2. Ensure the store is open and the transaction is used before commit/close.
  3. Serialize write access or use the backend's recommended concurrency settings if lock contention is the cause.
  4. Check disk space/health; restore from backup and reindex if the meta bucket is corrupted.

Example fix

// before
err = qs.incSize(ctx, 1) // fails: db closed
qs.Close()
// after
// close only after all writes complete
qs.incSize(ctx, 1)
qs.Close()
Defensive patterns

Strategy: retry

Validate before calling

if err := qs.checkOpen(); err != nil {
    return err // store must be open and writable before incrementing counters
}

Try / catch

_, err := qs.incSize(ctx, delta)
if err != nil && strings.Contains(err.Error(), "cannot get ") {
    log.Printf("meta read failed: %v", err)
    return err // surface backend error; do not blind-retry on closed/corrupt store
}

Prevention

When it happens

Trigger: incSize or genIDs invoked while the underlying kv Get of a meta key fails with a backend error other than ErrNotFound (I/O error, closed store, lock contention).

Common situations: Concurrent writers hitting backend locking limits; database closed or reopening mid-write; disk failure or corrupted meta bucket while updating size/horizon counters.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/a26548df669bd63a. Report an issue: GitHub.