C#: a flush refuses to overwrite a store file whose header it cannot read
SingleFileBackingStore.PushAll replaced the file without reading it, so a truncated store or one in a format this runtime does not read was clobbered, where Rust, TypeScript and Python refuse. PushAll now reads the header of a non-empty file under the lock before it writes; a file it cannot read throws and is left as it was. An empty file and a legacy envelope array carry no header and are still replaced. The header is read by the store's codec: SingleFileBackingStore gains a protected virtual ReadStoreHeader (default: read the whole snapshot), and the MessagePack store overrides it with CultDocumentMessagePackSerialization.ReadStoreHeader. An unconditional commit reads the file it rewrites through the same check. Doc text: last-writer-wins now says it holds only over a file the writer can read (CultCache.cs PushAll comment, cultcache-persistence-format.md "Conditional commit is the only safe multi-process write" and writer rule 4, cultcache-store-composition.md "A plain flush and an unconditional commit are last-writer-wins"). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
619e089fa6
commit
4f742d05c3
5 changed files with 69 additions and 7 deletions
|
|
@ -563,6 +563,8 @@ public class SingleFileMessagePackBackingStore : SingleFileBackingStore
|
|||
return snapshot;
|
||||
}
|
||||
|
||||
protected override string? ReadStoreHeader(byte[] data) => CultDocumentMessagePackSerialization.ReadStoreHeader(data);
|
||||
|
||||
protected override byte[] SerializePayload(object document)
|
||||
{
|
||||
return CultDocumentMessagePackSerialization.SerializeUntyped(document, document.GetType(), Registry);
|
||||
|
|
|
|||
Loading…
Reference in a new issue