Normandy.Behaviours.MemoryStore.Postgres
(normandy v2.2.0)
View Source
Durable, cluster-shared MemoryStore over Postgres. The handle is the host's Ecto
Repo module: pass {Normandy.Behaviours.MemoryStore.Postgres, MyApp.Repo}, for
example as Normandy.Tools.Memory.new/1's :store. Its tables come from
Normandy.Behaviours.MemoryStore.Postgres.Migration: call its up/0 and down/0
from a host migration.
Every write (put, delete, delete_tree, rename, delete_namespace) is one
transaction that first locks the namespace's row in normandy_memory_namespaces,
which tracks the namespace's content bytes and document count for put/6's limits.
So the writers of one namespace run one at a time, and compare-and-set, the limits
check and the counters change atomically with the document. The row goes with the
namespace's last document. rename/4 also locks the moving rows FOR UPDATE. Prefixes match with starts_with/2 (nothing to escape);
listing orders by path COLLATE "C" (byte order).
The counters are kept by these functions only: a row written to
normandy_memory_documents by other SQL is not counted, and the limits then count
wrong for its namespace.