Skip to content

Memory and concurrency model

This page explains entry metadata, shard-level concurrency, object-level synchronization, and transaction locking.

Each key maps to an Entry containing:

  • strongly typed Value;
  • creation and update timestamps;
  • optional expiry timestamp;
  • monotonically increasing version;
  • atomic access counter.

Amaquet currently creates 256 shards. The shard is selected with FNV-1a over the complete key. Independent shards can be accessed concurrently.

A new key starts at version 1. Replacing a key, changing TTL, removing TTL, scalar mutation, or successful in-place type mutation advances its version. CompareAndSet can replace a value only if the observed version still matches.

Engine.Transaction computes the distinct shards for all involved keys, sorts shard indexes, locks them in stable order, builds a view of non-expired entries, and runs the callback while those shard locks remain held. Stable lock ordering prevents lock-order inversion between transactions.

Many data types have their own sync.RWMutex or synchronization primitive. Their operation executes without a shard lock. After success, the engine takes the short shard lock needed to update the entry version and update timestamp.

Blocking queues, barriers, and semaphores must not hold keyspace shard locks while waiting. The dispatcher retrieves the object, performs the wait on the object itself, then updates key metadata after the operation completes.

A key’s logical DataType and its physical storage encoding are separate. Large eligible values can be represented by a compressed payload while the entry retains the same public type ID. Reads materialize the native value only for the operation. See Adaptive in-memory compression.