cayleygraph/cayley · error

cannot inc %s: %v

Error message

cannot inc %s: %v

What it means

After computing the new counter value, incMetaInt writes the 8-byte encoding back to the meta bucket. If tx.Put fails, the write error is wrapped as "cannot inc %s: %v" with the key name. This means the counter increment could not be persisted.

Source

Thrown at graph/kv/indexing.go:261

}

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
	}
	start, err := qs.incMetaInt(ctx, tx, "horizon", int64(n))
	if err != nil {
		return 0, err
	}
	return uint64(start + 1), nil
}

type nodeUpdate struct {
	Ind int
	ID  uint64

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Examine the wrapped inner error for the concrete backend cause (disk full, read-only, tx misuse).
  2. Free disk space if writes are failing due to storage limits.
  3. Ensure the store and transaction are opened read-write and the tx is not reused after Commit.
  4. Retry the operation; if the meta bucket is corrupted, restore from backup and reindex.

Example fix

// before: bulk load with full disk
cayley load --files data.nq // cannot inc horizon: no space left on device
// after
df -h # free space first
cayley load --files data.nq
Defensive patterns

Strategy: retry

Validate before calling

// preflight before bulk loads
if free, err := diskFree(dbPath); err == nil && free < minBytes {
    return fmt.Errorf("insufficient disk space for kv writes")
}

Try / catch

_, err := qs.incSize(ctx, 1)
if err != nil && strings.Contains(err.Error(), "cannot inc ") {
    if isDiskFull(err) {
        return errAfterFreeingSpace()
    }
    return fmt.Errorf("meta write failed, aborting tx: %w", err)
}

Prevention

When it happens

Trigger: tx.Put on a meta key failing during incSize or genIDs — backend write error such as a read-only database, full disk, bolt write failure, or transaction already errored/committed.

Common situations: Disk full while appending node IDs during bulk load; opening a bolt file in read-only mode; using a transaction after Commit; backend-specific write failures on the meta bucket.

Related errors


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