C#: HoldsIds is read off the stored form each time a store writes
A record's HoldsIds was decided by its admission and trusted afterwards, so a document changed after it was committed, or loaded and changed in place, flushed under the header its admission-time content needed (Soul P7, P10). HoldsIds now has one owner, the record's stored form, read when asked: - a plain record: CultElementIds.Holds over its document, a scan that reads and refuses nothing; - a variant: the same scan over each override value, decoded with the codec the record was built with (the cache's, or the attached cache's at load); - a variant built with no codec (a store that loaded it with no cache) cannot see its values and counts as holding an id, so a store never writes an unmarked header over ids it could not see. Cut: the admission path that set HoldsIds on plain records, on variants from their resolved copies, and on flattened records; the internal setter and its backing flag; IdPlan.HeldIds and IdPlan.HoldsIds. The Mesh typed write reads Holds off the document it writes. Admission keeps its own id counting (IdPlan.Count) for IdsInMemoryOnly. Tests: an id added to a committed or loaded deck after admission marks a PushAll v3, and taking it away unmarks it; a variant read without a codec counts as holding ids while the same record read with one does not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cf16cb7c1f
commit
619e089fa6
4 changed files with 121 additions and 35 deletions
|
|
@ -731,6 +731,60 @@ namespace GameCult.Caching.Tests
|
|||
Assert.That(HeaderOf(path), Is.EqualTo("cultcache.store.v1"), "a whole-store flush decides by what the store now holds");
|
||||
}
|
||||
|
||||
// Soul's P7 and P10: a store reads the header off what it writes, when it writes it. A document changed after its admission,
|
||||
// or loaded and changed in place, is marked by what it holds at the flush, in both directions.
|
||||
[TestCase(false)]
|
||||
[TestCase(true)]
|
||||
public void AFlushIsMarkedByWhatADocumentHoldsNowNotWhatItHeldWhenAdmitted(bool loaded)
|
||||
{
|
||||
var path = PathOf(loaded ? "mutated-loaded.cc" : "mutated-admitted.cc");
|
||||
var key = new CultRecordKey("d");
|
||||
using (var seed = Open(path))
|
||||
seed.Commit(batch => batch.Upsert(typeof(IdDeck), EmptyDeck("d"), key));
|
||||
Assert.That(HeaderOf(path), Is.EqualTo("cultcache.store.v1"));
|
||||
|
||||
using var cache = Open(path);
|
||||
var deck = EmptyDeck("d");
|
||||
if (loaded)
|
||||
deck = cache.Get<IdDeck>(key)!;
|
||||
else
|
||||
cache.Commit(batch => batch.Upsert(typeof(IdDeck), deck, key));
|
||||
|
||||
deck.Reels.Add(new IdReel { Id = HexA });
|
||||
cache.BackingStores[0].PushAll();
|
||||
Assert.That(HeaderOf(path), Is.EqualTo("cultcache.store.v3"), "an id added after admission marks the flush");
|
||||
|
||||
deck.Reels.Clear();
|
||||
cache.BackingStores[0].PushAll();
|
||||
Assert.That(HeaderOf(path), Is.EqualTo("cultcache.store.v1"), "the last id taken away after admission unmarks it");
|
||||
}
|
||||
|
||||
// A store with no cache has no codec to read a variant's override values with, so it cannot see whether they hold an id: the
|
||||
// variant counts as holding one. The same record read through a cache is marked by what its values hold.
|
||||
[Test]
|
||||
public void AVariantAStoreCannotReadCountsAsHoldingIds()
|
||||
{
|
||||
var path = PathOf("detached-variant.cc");
|
||||
using (var cache = Open(path))
|
||||
{
|
||||
cache.Commit(batch =>
|
||||
{
|
||||
batch.Upsert(typeof(IdDeck), EmptyDeck("base"), new CultRecordKey("base"));
|
||||
batch.UpsertVariant(new CultRecordKey("v"), new CultRecordKey("base"), new[] { cache.Override<IdDeck>(nameof(IdDeck.Name), "v") });
|
||||
});
|
||||
}
|
||||
|
||||
using (var cache = Open(path))
|
||||
cache.BackingStores[0].PushAll();
|
||||
Assert.That(HeaderOf(path), Is.EqualTo("cultcache.store.v2"), "read with a codec, a name override holds no id");
|
||||
|
||||
var blind = new SingleFileMessagePackBackingStore(path);
|
||||
blind.AttachRegistry(Registry);
|
||||
blind.PullAll();
|
||||
blind.PushAll();
|
||||
Assert.That(HeaderOf(path), Is.EqualTo("cultcache.store.v3"), "read without one, it cannot be seen, so it is marked");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ADirectoryStoreIsMarkedByTheIdsItWritesAndAnEmptyDeckDoesNotMarkIt()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue