Retype in one batch or staged apart, and a store-less cache refuses it too
A removal followed by an add at the same key is a retype (variants:ruling:cache-refuses-retype): the batch's staged add records that it replaces, the key is judged as the removal it names, and the record lands. The store carries the same fact for removals the cache staged apart (Remove then UpsertAsync), so the flush no longer reads the add as an upsert over the record it removed and discards it. A cache with no backing store judges the upsert against the record it holds. The variant plan's rebase-type check is deleted: write ownership refuses that retype first. The StoredPublishedBy staleness guard is deleted (a loaded record is never relabelled in place). Protected RefuseUndeclaredOnDisk doc states the per-key rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cf9f8dc0e1
commit
e163e6b006
4 changed files with 91 additions and 46 deletions
|
|
@ -189,7 +189,8 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
|
|||
manifest,
|
||||
request.Upserts.Concat(request.Deletes).Select(entry => entry.Key.Value).Concat(request.Checks).Concat(StagedKeys),
|
||||
request.Upserts,
|
||||
request.Deletes);
|
||||
request.Deletes,
|
||||
request.Checks);
|
||||
if (request.Upserts.Count == 0 && request.Deletes.Count == 0 && !IsDirty)
|
||||
{
|
||||
// Nothing to write: the batch only judged keys it does not hold.
|
||||
|
|
@ -247,7 +248,7 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
|
|||
Directory.CreateDirectory(_manifestFile.DirectoryName!);
|
||||
using var commitLease = AcquireCommitLease(wait: true, create: true);
|
||||
var (manifest, catalogBytes) = ReadManifest();
|
||||
RefuseUndeclaredOnDisk(manifest, StagedKeys, Array.Empty<CultStoredDocument>(), Array.Empty<CultStoredDocument>());
|
||||
RefuseUndeclaredOnDisk(manifest, StagedKeys, Array.Empty<CultStoredDocument>(), Array.Empty<CultStoredDocument>(), Array.Empty<string>());
|
||||
if (IsDirty)
|
||||
WriteGeneration(manifest, catalogBytes);
|
||||
else
|
||||
|
|
@ -279,7 +280,7 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
|
|||
using var commitLease = AcquireCommitLease(wait, create: true);
|
||||
if (commitLease == null)
|
||||
return CultCommitOutcome.Contended;
|
||||
RefuseUndeclaredOnDisk(ReadManifest().Snapshot, keys, Array.Empty<CultStoredDocument>(), Array.Empty<CultStoredDocument>());
|
||||
RefuseUndeclaredOnDisk(ReadManifest().Snapshot, keys, Array.Empty<CultStoredDocument>(), Array.Empty<CultStoredDocument>(), Array.Empty<string>());
|
||||
return CultCommitOutcome.Committed;
|
||||
});
|
||||
}
|
||||
|
|
@ -293,15 +294,16 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
|
|||
// store shares (CacheBackingStore.UndeclaredAt, CacheBackingStore.RefuseUndeclaredOnDisk). The refused records reload as a
|
||||
// pull loads them. A key is owned by the entry the write puts there: the batch's upsert, or the staged document. A key it
|
||||
// removes (the batch's deletes, the staged deletes) or only checks goes to the registry's removal rule.
|
||||
private void RefuseUndeclaredOnDisk(CultPersistedStoreSnapshot currentManifest, IEnumerable<string> written, IReadOnlyList<CultStoredDocument> upserts, IReadOnlyList<CultStoredDocument> deletes)
|
||||
private void RefuseUndeclaredOnDisk(CultPersistedStoreSnapshot currentManifest, IEnumerable<string> written, IReadOnlyList<CultStoredDocument> upserts, IReadOnlyList<CultStoredDocument> deletes, IEnumerable<string> checks)
|
||||
{
|
||||
CultPersistedRecord? HeldAt(string key) =>
|
||||
currentManifest.Records.FirstOrDefault(record => string.Equals(record.Key, key, StringComparison.Ordinal));
|
||||
var batch = upserts.ToDictionary(entry => entry.Key.Value, entry => entry.Descriptor, StringComparer.Ordinal);
|
||||
var removed = deletes.Select(entry => entry.Key.Value).ToHashSet(StringComparer.Ordinal);
|
||||
var removed = deletes.Select(entry => entry.Key.Value).Concat(checks).Concat(StagedRemovals).ToHashSet(StringComparer.Ordinal);
|
||||
CultSchemaCatalogEntry? WrittenAt(string key) =>
|
||||
batch.TryGetValue(key, out var descriptor) ? descriptor.ToCatalogEntry()
|
||||
: !removed.Contains(key) && _dirtyKeys.ContainsKey(key) && Entries.TryGetValue(key, out var staged) ? staged.Descriptor.ToCatalogEntry()
|
||||
removed.Contains(key) ? null
|
||||
: batch.TryGetValue(key, out var descriptor) ? descriptor.ToCatalogEntry()
|
||||
: _dirtyKeys.ContainsKey(key) && Entries.TryGetValue(key, out var staged) ? staged.Descriptor.ToCatalogEntry()
|
||||
: null;
|
||||
RefuseUndeclaredOnDisk(
|
||||
written,
|
||||
|
|
|
|||
Loading…
Reference in a new issue