| Copyright | (c) Nadia Yvette Chambers 2026 |
|---|---|
| License | EUPL-1.2 |
| Maintainer | Nadia Chambers <nadia.yvette.chambers@ik.me> |
| Stability | experimental |
| Portability | non-portable (GHC extensions, row types) |
| Safe Haskell | None |
| Language | GHC2024 |
Pykinos.Effect.Penelope
Description
Provides Penelope effect algebra integration for transient-epoch batching, lockless Multi-Version Concurrency Control (MVCC) snapshots, and categorical pushout merges.
Architectural Mechanics
- **Transient Epoch Scoping (
withTransientEpoch):** In transactional workloads, serial copy-on-write allocations per individual write generate excessive garbage and node copies. A transient epoch amortizes allocation by tagging all node insertions during an active batch with a freshly mintedEpochId. Nodes created within the same epoch can be reused without defensive cloning. - **Lockless MVCC Snapshots (
MVCCSnapshot):** Captures an \(O(1)\) reference to the rootBPlusMapat a givenEpochId, optionally pre-materializing a contiguousFASTMapread-accelerator (msFastAcc) for branch-minimized query routing. - **Categorical Pushout Commutation (
commitEpochPushout):** When two concurrent tasks fork from a common base snapshot \(V_0\) into divergent branches \(V_1\) and \(V_2\), their concurrent modifications form a categorical pushout span: \[ \begin{array}{ccc} V_0 & \longrightarrow & V_1 \\ \downarrow & & \downarrow \\ V_2 & \longrightarrow & V_1 \amalg_{V_0} V_2 \end{array} \] * If the disjoint deltas commute or represent idempotent updates to identical values, the pushout merges cleanly into a unifiedMVCCSnapshot. * If concurrent writes to the same key diverge,commitEpochPushoutisolates the cellular sheaf \(H^1\) obstruction as a list ofPushoutConflictrecords.
Synopsis
- data PykinosBatchH k v (regions :: [([Type], [Type])]) (ins :: [Type]) (outs :: [Type]) where
- RunPykinosBatch :: forall k v (ins :: [Type]) (outs :: [Type]). !(BPlusMap k v) -> (EpochId -> BPlusMap k v -> BPlusMap k v) -> PykinosBatchH k v '['(ins, outs)] ins outs
- type PukinosBatchH = PykinosBatchH
- pattern RunPukinosBatch :: BPlusMap k v -> (EpochId -> BPlusMap k v -> BPlusMap k v) -> PykinosBatchH k v '['(ins, outs)] ins outs
- data MVCCSnapshot k v = MVCCSnapshot {}
- data PushoutConflict k v = PushoutConflict {
- pcKey :: !k
- pcBaseVal :: !(Maybe v)
- pcLeftVal :: !v
- pcRightVal :: !v
- withTransientEpoch :: Ord k => EpochId -> BPlusMap k v -> (EpochId -> (k -> v -> BPlusMap k v -> BPlusMap k v) -> BPlusMap k v -> BPlusMap k v) -> (EpochId, BPlusMap k v)
- mvccSnapshot :: EpochId -> Bool -> BPlusMap k v -> MVCCSnapshot k v
- commitEpochPushout :: (Ord k, Eq v) => MVCCSnapshot k v -> BPlusMap k v -> BPlusMap k v -> Either [PushoutConflict k v] (MVCCSnapshot k v)
Higher-Order Penelope Effect
data PykinosBatchH k v (regions :: [([Type], [Type])]) (ins :: [Type]) (outs :: [Type]) where Source #
Higher-Order Scoped Penelope Effect for transient epoch-stamped mutations over a BPlusMap.
Regions track input and output effect rows during scoped batch mutation.
Constructors
| RunPykinosBatch :: forall k v (ins :: [Type]) (outs :: [Type]). !(BPlusMap k v) -> (EpochId -> BPlusMap k v -> BPlusMap k v) -> PykinosBatchH k v '['(ins, outs)] ins outs | Opens a transient mutation scope with a freshly minted |
type PukinosBatchH = PykinosBatchH Source #
Backward-compatible type alias for legacy PukinosBatchH.
pattern RunPukinosBatch :: BPlusMap k v -> (EpochId -> BPlusMap k v -> BPlusMap k v) -> PykinosBatchH k v '['(ins, outs)] ins outs Source #
Backward-compatible pattern synonym for RunPykinosBatch.
MVCC Snapshots & Obstructions
data MVCCSnapshot k v Source #
Lockless \(O(1)\) Multi-Version Concurrency Control (MVCC) snapshot handle.
Pairs an immutable EpochId watermark with the root BPlusMap and an optional
pre-materialized FASTMap read accelerator.
Constructors
| MVCCSnapshot | |
Instances
| (Eq k, Eq v) => Eq (MVCCSnapshot k v) Source # | |
Defined in Pykinos.Effect.Penelope Methods (==) :: MVCCSnapshot k v -> MVCCSnapshot k v -> Bool (/=) :: MVCCSnapshot k v -> MVCCSnapshot k v -> Bool | |
| (Show k, Show v) => Show (MVCCSnapshot k v) Source # | |
Defined in Pykinos.Effect.Penelope Methods showsPrec :: Int -> MVCCSnapshot k v -> ShowS show :: MVCCSnapshot k v -> String showList :: [MVCCSnapshot k v] -> ShowS | |
data PushoutConflict k v Source #
Cohomological \(H^1\) merge obstruction on key k.
Materialized when two concurrent branches modify the same key to conflicting, non-equal values relative to base snapshot \(V_0\).
Constructors
| PushoutConflict | |
Fields
| |
Instances
| (Eq k, Eq v) => Eq (PushoutConflict k v) Source # | |
Defined in Pykinos.Effect.Penelope Methods (==) :: PushoutConflict k v -> PushoutConflict k v -> Bool (/=) :: PushoutConflict k v -> PushoutConflict k v -> Bool | |
| (Show k, Show v) => Show (PushoutConflict k v) Source # | |
Defined in Pykinos.Effect.Penelope Methods showsPrec :: Int -> PushoutConflict k v -> ShowS show :: PushoutConflict k v -> String showList :: [PushoutConflict k v] -> ShowS | |
Epoch Execution & Merging
Arguments
| :: Ord k | |
| => EpochId | Previous epoch watermark. |
| -> BPlusMap k v | Base B+ tree before batch modification. |
| -> (EpochId -> (k -> v -> BPlusMap k v -> BPlusMap k v) -> BPlusMap k v -> BPlusMap k v) | Scoped mutation lambda receiving new |
| -> (EpochId, BPlusMap k v) |
Execute a batch of modifications under a freshly incremented transient EpochId.
Running time: \(O(k \log_M n)\) for \(k\) inserted entries.
mvccSnapshot :: EpochId -> Bool -> BPlusMap k v -> MVCCSnapshot k v Source #
Capture an \(O(1)\) lockless MVCC snapshot of a BPlusMap (optionally freezing a FASTMap).
Running time: \(O(1)\) when buildFast = False; \(O(n)\) when building FAST accelerator.
Arguments
| :: (Ord k, Eq v) | |
| => MVCCSnapshot k v | Base snapshot \(V_0\) |
| -> BPlusMap k v | Worker 1 branch \(V_1\) |
| -> BPlusMap k v | Worker 2 branch \(V_2\) |
| -> Either [PushoutConflict k v] (MVCCSnapshot k v) |
Compute the Categorical Pushout (\(V_1 \amalg_{V_0} V_2\)) of two concurrent BPlusMap
branches forked from a common ancestor snapshot \(V_0\).
- If all modifications commute or resolve idempotently, returns
Rightwith the merged snapshot. - If overlapping keys diverge, returns
Leftcontaining the list ofPushoutConflictrecords.
Running time: \(O(|\Delta_1| \log n + |\Delta_2| \log n)\).