pykinos-penelope
Copyright(c) Nadia Yvette Chambers 2026
LicenseEUPL-1.2
MaintainerNadia Chambers <nadia.yvette.chambers@ik.me>
Stabilityexperimental
Portabilitynon-portable (GHC extensions, row types)
Safe HaskellNone
LanguageGHC2024

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

  1. **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 minted EpochId. Nodes created within the same epoch can be reused without defensive cloning.
  2. **Lockless MVCC Snapshots (MVCCSnapshot):** Captures an \(O(1)\) reference to the root BPlusMap at a given EpochId, optionally pre-materializing a contiguous FASTMap read-accelerator (msFastAcc) for branch-minimized query routing.
  3. **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 unified MVCCSnapshot. * If concurrent writes to the same key diverge, commitEpochPushout isolates the cellular sheaf \(H^1\) obstruction as a list of PushoutConflict records.
Synopsis

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 EpochId, avoiding wide-node write amplification before freezing on region exit.

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 

Fields

  • msEpoch :: !EpochId

    Epoch watermark associated with this snapshot.

  • msTree :: !(BPlusMap k v)

    Root persistent B+ tree node hierarchy.

  • msFastAcc :: !(Maybe (FASTMap k v))

    Optional cache-line blocked Eytzinger read accelerator.

Instances

Instances details
(Eq k, Eq v) => Eq (MVCCSnapshot k v) Source # 
Instance details

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 # 
Instance details

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

  • pcKey :: !k

    Key where concurrent conflicting writes occurred.

  • pcBaseVal :: !(Maybe v)

    Original value in common ancestor snapshot \(V_0\) (if present).

  • pcLeftVal :: !v

    Mutated value in worker branch \(V_1\).

  • pcRightVal :: !v

    Divergent mutated value in worker branch \(V_2\).

Instances

Instances details
(Eq k, Eq v) => Eq (PushoutConflict k v) Source # 
Instance details

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 # 
Instance details

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

withTransientEpoch Source #

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 and insertion closure.

-> (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.

commitEpochPushout Source #

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 Right with the merged snapshot.
  • If overlapping keys diverge, returns Left containing the list of PushoutConflict records.

Running time: \(O(|\Delta_1| \log n + |\Delta_2| \log n)\).