Preserve dirty CultCache state during pulls

This commit is contained in:
Meta Vens 2026-07-18 23:19:45 +01:00
commit 49c43baa4c
15 changed files with 117 additions and 5 deletions

View file

@ -75,6 +75,9 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
foreach (var pair in loaded)
{
if (_dirtyKeys.ContainsKey(pair.Key) || _deletedKeys.ContainsKey(pair.Key))
continue;
if (Entries.TryGetValue(pair.Key, out var existing) &&
string.Equals(existing.StoredAt, pair.Value.StoredAt, StringComparison.Ordinal) &&
string.Equals(existing.Descriptor.SchemaId, pair.Value.Descriptor.SchemaId, StringComparison.Ordinal))
@ -91,14 +94,15 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
foreach (var removedKey in Entries.Keys.Where(key => !loaded.ContainsKey(key)).ToArray())
{
if (_dirtyKeys.ContainsKey(removedKey) || _deletedKeys.ContainsKey(removedKey))
continue;
if (Entries.TryRemove(removedKey, out var removed))
EntryDeleted.OnNext(removed);
}
SetLastSchemaMigrationReports(reports);
_dirtyKeys.Clear();
_deletedKeys.Clear();
IsDirty = false;
IsDirty = !_dirtyKeys.IsEmpty || !_deletedKeys.IsEmpty;
}
/// <inheritdoc />

View file

@ -2092,6 +2092,13 @@ namespace GameCult.Caching
return;
}
// A single-file snapshot cannot distinguish local dirty keys from clean keys.
// Pulling while local mutations are staged would let an older disk snapshot
// erase those mutations before the next flush. Flush first; clean readers can
// still poll external snapshots incrementally.
if (IsDirty)
return;
CultPersistedStoreSnapshot snapshot;
try
{