17 KiB
Changelog
Unreleased
Changed
- Breaking:
define_document_typewrites and reads MessagePack payloads by default (cultlib-gaps:ruling:py-msgpack-default); it wrote JSON until 0.3. A definition'spayload_codec(PayloadCodec, withMESSAGEPACK_PAYLOAD_CODECandJSON_PAYLOAD_CODECexported) owns its payload format, replacing thepayload_encoderandpayload_decoderparameters and fields, so no definition carries a second author of the format. A store written by 0.3 or earlier holds JSON: define its types withpayload_codec=JSON_PAYLOAD_CODECto read them, or write a new MessagePack store withconvert(source, destination, definitions), which never writes its source. The MessagePack codec takes the keys, integers, timestamps and nesting the C# reference's object reader takes and refuses the rest on read and on write (CultCachePayloadFormatError,PayloadCodecFault; see the README, Payload format); the single-file store's reader takes the same map keys. A 0.3 JSON payload that is an object or list is refused by count as a payload with bytes after its first MessagePack value, aValueError.define_database_entry_typeinherits the checked codec too: main wrote{b'k': 1}in an untyped slot, which is now refused on write, and a bin map key in an entry payload is refused on read where main read it, so a main-era store with a bin-keyed entry fails to load. The checked codec walks each tree twice (the depth walk, then the carried-value check), which roughly doubles entry and document codec cost; the double walk is left in place. The JSON codec'sdepth_faults=(RecursionError,)gives a JSON payload nested past the interpreter's stack the typedCultCachePayloadDepthError, which resolves the deferredcut-union-bounds-py.s2.depth-typed-refusal-lostfor the JSON codec only. This is the same minor bump as the rest of this section: 0.4.0 is not yet tagged. parse_stored_at(was_parse_stored_at) is public: cultmesh-py judges a peer'sstoredAtby it. A peer'sdocument_put_rawwhosestoredAtis missing, empty or not a stamp is refusedmessage_invalid(fielddocument) and nothing is minted or stored (variants:ruling:raw-put-without-stamp-refused). A subscribed server's stampless put now raisesValueErrorfromCultMeshClient.read_next_changeinstead of being stored under a minted stamp.
Added
CultCache.updateandupdate_globalreturnUpdateResult(outcome, document);UpdateOutcomeisUPDATED,DECLINEDorLOST_RACE. The single-file store gainsread(key)(the record and its content version, the SHA-256 C# computes) andcommit_if(envelope, expected), the version is the SHA-256 of the record re-encoded as[key, schemaId, storedAt, payload]with minimal MessagePack encodings, which is the SHA-256 of the record's stored bytes exactly when the writer encoded it minimally (every writer in this library does; a record another writer encoded with a wider-than-needed length or integer has the version of its minimal form, not of its bytes). Both looked up by the cache and notBackingStoreprotocol members (variants:cut_spec:cut-update-with-retry-py).read_payload_tree(type_name, payload, decoder=None, depth_faults=(msgpack.exceptions.StackError,)): the exported owner of the one-value, depth-first payload read thatdecode_payloaduses, for payloads read outside a definition (cultnet-py's witness bundle decode needs it, socultnet-pynow requirescultcache-py>=0.4.0). The manifest version is 0.4.0, the minor these Unreleased breaking changes imply, set in this change so the workspace install resolves the new bound; the## Unreleasedheading becomes## [0.4.0]when it is tagged.
Changed
- A write that replaces a record is stored at a later
stored_atthan the record it replaces, in the single-file store, the JSONL store and a store-less cache, with no exception for identical content (variants:ruling:py-rs-update-follow-csharp-restamp); the cache holds the stamp the store wrote. A stored_at is read only in the shape the runtimes write (an RFC 3339 date-time with T, a fraction of 1 to 9 digits, Z or a numeric offset), the same on every Python; any other text, or an instant outsidedatetime's range, is not a stamp and a write over it is stamped at now. A write over a record stamped at the last instantdatetimecan hold (9999-12-31T23:59:59.999999Z) is refused withValueErrorand writes nothing. store_write_locklooks for a link at the store path again once the lock is held, so a link put at the path while a writer waited on the lock is refused withStoreLinkedErrorand the lock released, instead of being replaced.JsonLinesBackingStoretakes no cross-process lock (only its thread lock, under which it already refuses a link), so it has no lock wait to re-check across. Pinned by a test that puts the link while a foreign process holds the lock.CultCache.is_writabledoes not look at store paths: a link at a store path is not predicted, and the write refuses it withStoreLinkedError. Pinned by a test through a cache attached to a linked store.JsonLinesBackingStorewrites LF line endings on Windows. It wrote CRLF there, throughwrite_textnewline translation, before the commit_store_file change (#154,adbbb780).msgpackis a hard dependency, aspyproject.tomldeclared it. The optional-import fallbacks and thecultcache-py[msgpack]extra they named (which never existed) are gone: a missing msgpack is anImportErrorat import.JsonLinesBackingStorewrites through the samecommit_store_fileas the single-file store: a unique staged file, fsynced before the replace and removed when the replace fails, so a refused replace no longer leaves<path>.tmpbehind. It staged a fixed<path>.tmpwithout an fsync.- The single-file store's
push,push_allanddeletetake the cross-process lock on<path>.lock(flock; LockFileEx over the whole file on Windows) across the read and the replace, waiting up tolock_timeoutseconds (30 by default,TimeoutErrorafter), and exclude the C#, Rust and TypeScript runtimes' writers. The staged file is<path>.tmp-<pid>-<uuid>, fsynced before the replace, with a directory fsync after it off Windows. A fixed<path>.tmpis no longer used.
Breaking
-
update(document, key, apply, *, max_attempts=5)andupdate_global(document, apply, *, max_attempts=5)replace the blind pair. Each attempt reads the record from the home store, runsapplyon a copy (None when absent) outside every lock, and commits only if the record is unchanged, runningapplyagain on a lost race; it returnsUpdateResult, not the value.applyreturning None writes nothing; a lost race that outlastsmax_attemptsreturnsLOST_RACE; a store withoutreadandcommit_if(JSON lines among them) refuses beforeapply.putis the blind write. -
pushreturns thestored_atit wrote andpush_alla dict of them by key ({}when a soft push skipped); a store returning None keeps the cache's own stamp. -
push_all(envelopes, soft=False)on the single-file and JSONL stores and on theBackingStoreprotocol takes the soft flag, as TypeScript, Rust and C# do: a soft push writes only where nothing is at the path; over a store the reader reads, empty included, it returns without writing, and over a file the reader cannot read it refuses (StoreUnreadableErrorfor the single-file store). TheBackingStoreprotocol haspull_or_absent(): the envelopes the reader reads,Nonewhen nothing is at the path, a raise when the path cannot be read; its default ispull_all(), which cannot say absent, so a store that inherits it is always read. The defaultpush_alldecides soft by it (writes where it says absent, skips over a store it read, refuses where it raises), and the single-file and JSONL stores expose their pull through it; an inheriting store that can tell nothing-at-the-path overridespull_or_absent, notpush_all. Before, a soft push through the default always skipped. A store kind that overridespush_all(envelopes)without the keyword fails when a caller passessoft. -
A write at a store path that is a link, live or dangling, is refused with the new
StoreLinkedError(anOSError, exported fromcultcache_py;.pathnames the path) before the lock and the replace, for the single-file store and forJsonLinesBackingStore(push,push_all,delete), and nothing is written. Before, a write at a live link replaced the link with a regular file, and at a dangling link both stores raisedFileNotFoundError. A caller catchingFileNotFoundErrorthere now catchesStoreLinkedError(OSError); configure the link's target as the store path. On Windows a junction or any reparse point counts as a link. Reads through a live link work. -
A record whose payload carries a slot past its reader's declared slots, at any depth (the document, a nested record, a list element, a union arm, a unit arm), is read, held read-only, and every write or removal of its key (
put,put_global,update,put_envelope,put_envelopes,delete,delete_global) is refused withSchemaConflictErrorbefore any store is touched (cultlib-gaps:ruling:extra-trailing-slots). Reading dropped those slots silently and the next write shed them.SchemaConflictError.unread_slotsis anUnreadSlots(type_name, slot_count, declared_count, occurrences, depth0_only)and the message names the type and both counts, never a slot value. A depth-0 mark is consented, and the record writable, only when the record is stored under an id the document lists incompatible_schema_idsand that id's catalog entry has slots past the document's, covering the mark's slot count (cultlib-gaps:ruling:slot-mark-consent); a nested mark, or a mark under the document's own id, keeps the record read-only whatever is declared. Missing trailing slots keep their declared defaults. An untouched marked record keeps its stored bytes through every other write. AddedCultCache.is_writable(document, key)(advisory; the write still decides: it also answers False for a foreign-carried key, for a key held as a type the document does not own, and for a global document at a non-global key;deleteasks the same judges, so removing a key held as another type is refused withSchemaConflictErrorunless the document owns that record's schema id (its own or one it lists compatible), in which case the removal removes that record, its file row and its lookups, as a write of the key would replace it; it returned silently and removed nothing),DocumentDefinition.decode_payload_marked, andUnreadSlots. A document with a customdecode(no slot codec) never marks. A store holding a variant record is still unreadable here. Implies a minor bump while the version is 0.x (0.3.0 to 0.4.0): code that wrote back a record from a newer writer now getsSchemaConflictError. -
A payload is one MessagePack value:
DocumentDefinition.decode_payloadrefuses bytes after it, by count, withValueError<type> payload has N bytes after its first MessagePack value (refused on read).(never the bytes, never the depth refusal; a payload that ends early stays the decoder's), as the C# reference does (tests/vectors/union-parity/bytes-after-outcomes.msgpack). It raisedmsgpack.ExtraData(aValueError, so only a caller namingmsgpack.ExtraDatais affected); this is a minor-version bump while pre-1.0. The refused set is unchanged. Cache loads,getand every definition built on a codec go through it; a codec whosedecoderaisesExtraDatais refused the same way. Depth is judged first, so a value nested past 256 with a tail is the depth refusal, as in C#. -
A cache holds one record per key whatever its type (
variants:ruling:cache-refuses-retype). Aput,put_envelope,put_envelopesorput_globalof a second type under a key the cache holds, or under a key a store carries foreign, is refused withSchemaConflictErrornaming the key, even with no store, and changes nothing; retype a key by deleting it, then putting the new type. A write may replace another registered type's record only when the written type owns its schema id (declares it or lists it compatible) and both types share one home store. A load that reads one key from two stores, whatever the types, is refused withCultCacheErrornaming the key and both types, and admits nothing. A store that holds a record no registered type claims now loads and is carried: the cache does not serve it, the store keeps its bytes through every write,deleteorputat its key is refused withSchemaConflictError, and registering a type that declares its schema id claims it at the next load. It raisedCultCacheError"Unknown persisted document type". Two global types share the key__global__, so a second global type in one cache is now refused, and a store that already holds two global types at__global__(a JSONL store written by caches that never pulled could produce one) no longer loads: the pull raisesCultCacheErrorand admits nothing. C# refuses a second persisted global on pull the same way (cultcache-store-composition.md, "Globals never invented"); repair such a file by deleting one of the two records with the runtime that wrote it. -
Added
foreign_records()and the frozenForeignRecord(key, schema_id, schema_name, stored_at), sorted by key in UTF-16 code-unit order.stores.retypedandstores.written_ownslose their underscore: the cache judge and the single-file store's commit guard ask one predicate. -
A single-file store holding two records under one key is unreadable: the v1 reader and the legacy envelope-array reader refuse it with
StoreUnreadableError(a key is compared by its exact code points, no case folding or normalisation). A catalog slot whose canonical schema is not a string is refused the same way. A store that loaded before can now be refused: repair it with the runtime that wrote the duplicate. -
A
putorpush_allthat would land a second type under a key the store holds is refused withSchemaConflictError, and the file is left as it was. Retype a key by deleting it, then putting the new type. A write replaces the record at a key only when the written type owns it: its catalog entry declares the stored schema id (its own, or one it lists compatible), so a renamed type that lists the old id compatible may replace the record, or it has the stored record's schema name. This runtime does not compare shapes, so a same-name type is never refused for dropping persisted slots as C# refuses it. -
Writes of the same type replace by key: the last record wins, in a batch as in the file.
-
indexesare unique, as C#[CultIndex]: a write, load orregister_indexthat leaves two records of a type holding one non-blank value under one alias is refused (CultCacheError) naming both keys and the alias, and writes nothing. Index text is the C# canonical text (True/False, integers as digits, floats as the exact expansion, blank values never indexed), so an empty or whitespace string is no longer a value. A newrolesmap names the many-row selection aliases (never indexed for lookup, same catalogindex_alias). Classify everyindexeskey per the README before updating. The verdict is the contract, the text is informational. -
A single-file store written as
cultcache.store.v3is read and written: a store the C# runtime marked v3 (it holds a record with an element id: an owned list element with a[CultElementId]member) keeps its header here, and is carried through every rewrite with its ids; this runtime never drops the mark. A runtime from before this change refuses a v3 store by name. Rolling back to an older release after a store has been written as v3 is one-way: there is no carry-back, so restore from a copy taken before upgrading. -
A write over a file the reader refuses (
StoreUnreadableError, frompush,push_allanddelete) refuses and leaves the file as it is. A flush used to replace such a file. A write set cannot merge with a disk it cannot read, so the file is repaired or removed by its owner before the store writes again. -
Added
StoreUnreadableError(aValueError) for a store file this runtime cannot read, andSchemaConflictError(aValueError) for a write the catalog cannot describe. A store is exactly three slots; a schema is never recovered from a record's payload. -
The single-file writer derives the catalog from the records it writes: one entry per carried schema id, the registered entry over an arrived one, written as chosen and never merged. A cache stamps a record with its registered schema's id.
-
Every registration refusal is now a
SchemaConflictError, aValueError, where it was aCultCacheError, aRuntimeError: registering a document type or a schema name twice no longer raises whatexcept CultCacheErrororexcept RuntimeErrorcatches. -
Two documents that own one schema id are refused at registration (
SchemaConflictError). 2.0.1 accepted them. A document may still list another's id as compatible. -
A loaded record resolves by its schema id first: the document that owns the id, else the one document that lists it as compatible; several listers and no owner refuse the record with
SchemaConflictError. The record's type name resolves it only when its schema id names no registered document. 2.0.1 resolved by the record's type name alone.