On this page

Connect storage through your callables๏ƒ

Prerequisite: persistence. Melder calls your storage functions; the example uses an in-memory dictionary so the complete integration can run without a database service or credentials.

Handler

Arguments

Responsibility

Store

kind, profile name, unit ID, payload

Store a plain record

Fetch

kind, unit ID

Return the stored payload or a known absence

List

kind, profile name

Enumerate unit IDs for the requested partition

Delete

kind, unit ID

Remove the explicitly identified stored unit

Configure the needed handlers on ExternalPersistenceManagerConfiguration, then attach it through Crystallizer. Inspect describe_external_persistence_manager() for the installed wiring and failure counts; describe_external_interface() describes the integration contract.

Verify the remote leg separately๏ƒ

A successful local flush does not establish remote delivery under the default lenient write policy. The failure lesson deliberately raises in a store handler, checks the local cache, and checks the increased failure count. Missing read lanes refuse rather than report an empty remote record.

The JSON lesson also shows the serialized payload crossing a callable boundary. For record round trips, use strict JSON serialization so unsupported values fail instead of being silently converted into lossy strings.

The workflow in code๏ƒ

These are the core steps from the saved example. Use its complete linked script for all class definitions and setup.

 1def main() -> None:
 2    crystallizer = md.Crystallizer()
 3    crystallizer.activate(
 4        md.CrystallizerConfigurationBuilder().with_defaults().activate(),
 5    )
 6
 7    # THE HANDLERS GO IN THEIR OWN OBJECT, never into the record.
 8    mesh = md.ExternalPersistenceManagerConfiguration()
 9    mesh.with_store_handler(store)
10    mesh.with_fetch_handler(fetch)
11    mesh.with_list_units_handler(list_units)
12    crystallizer.configure_external_persistence_manager(mesh)
13    print("mesh attached - melder now has four callables and no idea what")
14    print("is behind them")
15
16    # WHAT IS WIRED vs WHAT THE CONTRACT IS. Two questions, two doors,
17    # neither one a network call.
18    wiring = crystallizer.describe_external_persistence_manager()
19    contract = crystallizer.describe_external_interface()
20    assert isinstance(wiring, dict) and isinstance(contract, dict)
21    assert wiring.get("attached") is True, wiring
22    print()
23    print("describe_external_persistence_manager ->", len(wiring),
24          "keys (what is WIRED)")
25    print("describe_external_interface           ->", len(contract),
26          "keys (what the CONTRACT is)")
27
28    # PRESENCE FLAGS, NEVER CALLABLES. Search the whole record payload for
29    # anything callable - a recorded world has to stay code-free.
30    leaked = [key for key, value in wiring.items() if callable(value)]
31    assert not leaked, "the record leaked a callable: %s" % leaked
32    print("  the wiring record holds no callable objects - only presence")
33    print("  flags, because executable code cannot be serialized into a")
34    print("  world record and a record that embedded yours would only")
35    print("  restore where that code already ran")
36
37    # A WORLD WORTH SEALING.
38    spellbook_configuration = (
39        md.SpellbookConfiguration(FRAME).with_defaults().finalize()
40    )
41    book = md.Spellbook(aetheric_frame=FRAME,
42                        configuration=spellbook_configuration)
43    book.configure_aether_frame(
44        system_state="dynamic",
45        disposal=None,
46        disposal_method_names=None,
47        rift_enabled=True,
48        ai_native=True,
49    )
50    book.bind(spell=Ledger, existence="unique", permissions="create",
51              binding_name="mesh-ledger")
52    book.conjure(name="mesh-root")
53
54    # SEAL, THEN SHIP - one verb, two guarantees, one of them yours.
55    checkpoint_id = crystallizer.create_checkpoint()
56    assert checkpoint_id in crystallizer.list_checkpoint_ids()
57    flushed = crystallizer.flush_checkpoint(checkpoint_id)
58
59    # THE LOCAL SEAL IS THE PART THE RETURN VALUE COVERS. Assert it.
60    assert checkpoint_id in flushed, flushed
61    assert checkpoint_id in crystallizer.list_cached_checkpoint_ids()
62    print()
63    print("flush_checkpoint ->", checkpoint_id[:14], "...")
64    print("  LOCAL SEAL asserted: it is in the cache, on this machine")
65
66    # THE REMOTE LEG IS LENIENT, so this is REPORTED and not asserted.
67    # Teaching you to assert it would be teaching you to trust the half
68    # the return value does not cover.
69    print("  your database received", len(WRITES), "unit(s):")
70    for kind, profile_name, unit_id in WRITES[:4]:
71        print("     kind=%-11s profile=%-10s unit=%s"
72              % (kind, profile_name, unit_id[:14]))
73    print("  reported, NOT asserted - the remote leg is lenient by")
74    print("  default, so a clean return proves the local seal and nothing")
75    print("  about your storage. Local custody is never hostage to a")
76    print("  network you do not own. If you need remote confirmation, the")
77    print("  return value of flush is not it - strict uploads are")
78
79    # AND THE ABSENCE THAT MATTERS. No sync(), no mirror_all().
80    for absent in ("sync", "mirror", "mirror_all", "sync_external",
81                   "push_everything"):
82        assert not hasattr(crystallizer, absent), (
83            "%s appeared - an opaque sync verb would make the mesh "
84            "impossible to reason about when it disagrees with itself"
85            % absent
86        )
87    print()
88    print("there is NO sync() - every verb names a KIND and a DIRECTION,")
89    print("so when the two sides disagree you can say which way the last")
90    print("byte was travelling. `sync` cannot answer that question.")
91
92    print()
93    print("four callables, one kind column, zero database imports")

Runnable examples๏ƒ

All expert examples ยท Level contents ยท Full contents

Canonical page source