Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cachesize test #172

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public CacheDebugger(TestHooks testHooks)

public bool EnableSizeChecking { get; set; } = true;

internal IEnumerable<TrackedObjectKey> Keys => this.Objects.Keys;

public enum CacheEvent
{
// reads and RMWs on the main session
Expand Down Expand Up @@ -299,6 +301,12 @@ internal bool CheckSize(TrackedObjectKey key, List<(long delta, long address, st
{
info.CacheEvents.Enqueue(new Entry { CacheEvent = CacheEvent.SizeCheckFail, Delta = actual, Address = reference });

if (entries.Count == 0)
{
// for now, we just tolerate this since we cannot rely on evictions to reach us in time
return false;
}

// adjust the actual
var firstActual = entries.FirstOrDefault().address;
var firstReference = entries.FirstOrDefault().address;
Expand Down
17 changes: 17 additions & 0 deletions src/DurableTask.Netherite/StorageProviders/Faster/FasterKV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ public void ValidateMemoryTracker()

var inMemoryIterator = this.fht.Log.Scan(this.fht.Log.HeadAddress, this.fht.Log.TailAddress);

// we now scan the in-memory part of the log and compute the total size, and store, for each key, the list of records found

long totalSize = 0;
Dictionary<TrackedObjectKey, List<(long delta, long address, string desc)>> perKey = new Dictionary<TrackedObjectKey, List<(long delta, long address, string desc)>>();
void Add(TrackedObjectKey key, long delta, long address, string desc)
Expand All @@ -1013,21 +1015,36 @@ void Add(TrackedObjectKey key, long delta, long address, string desc)
}
Add(key, delta, inMemoryIterator.CurrentAddress, $"{(recordInfo.Invalid ? "I" : "")}{(recordInfo.Tombstone ? "T" : "")}{delta}@{inMemoryIterator.CurrentAddress.ToString("x")}");
}

foreach (var k in this.cacheDebugger.Keys)
{
if (!perKey.ContainsKey(k))
{
perKey.Add(k, emptyList); // for keys that were not found in memory, the list of records is empty
}
}

long trackedSizeAfter = this.cacheTracker.TrackedObjectSize;

bool sizeMatches = true;

// now we compare, for each key, the list of entries found in memory with what the cache debugger is tracking

foreach (var kvp in perKey)
{
sizeMatches = sizeMatches && this.cacheDebugger.CheckSize(kvp.Key, kvp.Value, this.Log.HeadAddress);
}

// if the records matched for each key, then the total size should also match

if (sizeMatches && trackedSizeBefore == trackedSizeAfter && trackedSizeBefore != totalSize)
{
this.cacheDebugger.Fail("total size of tracked objects does not match");
}
}

readonly static List<(long delta, long address, string desc)> emptyList = new List<(long delta, long address, string desc)>();

internal (int numPages, long size) ComputeMemorySize(bool resetCacheDebugger)
{
var cacheDebugger = resetCacheDebugger ? this.cacheDebugger : null;
Expand Down