pamoja.sync
Idiomatic store-and-forward facade.
The queue a node writes into while it has nowhere to send. An in-memory buffer suits a test or a process that will not outlive it; a file-backed one survives a reboot, which is what a node somewhere without reliable power actually needs.
A full store refuses the next append rather than dropping anything, so a record is never lost without the caller being told.
1"""Idiomatic store-and-forward facade. 2 3The queue a node writes into while it has nowhere to send. An in-memory buffer 4suits a test or a process that will not outlive it; a file-backed one survives a 5reboot, which is what a node somewhere without reliable power actually needs. 6 7A full store refuses the next append rather than dropping anything, so a record 8is never lost without the caller being told. 9""" 10 11from __future__ import annotations 12 13from pamoja._native import Store 14 15__all__ = ["Store"]
A store-and-forward buffer.
Handing a store to a ladder consumes it, because the ladder owns it from then on. A consumed store is emptied rather than left aliasing what now belongs to the ladder, so using one twice raises.
Creates a buffer held in memory.
A full store refuses the next append rather than dropping anything, so a record is never lost without the caller being told.
Opens a buffer backed by a directory, so it survives a restart.
A record a power cut interrupted mid-write is never seen, and one written
before the cut is found again when the directory is reopened. capacity is
the most records to hold, or 0 for no bound; a full store refuses the next
append, which keeps a long outage from filling the disk.
Drains the buffer onto a transport, publishing each record to topic,
oldest first, and returns how many went out.
Each record leaves the buffer only once the transport has taken it, so a send that fails raises the transport's error and leaves that record and every one after it buffered, in order, for the next drain. The transport is driven, not consumed.
Reads the oldest record as text without removing it, or None when empty.
Raises ValueError if the record is not UTF-8 text.