Skip to content

Commit

Permalink
Promptly terminate AdaptiveDirectoryCacheMaintainer (#9062)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed Jul 11, 2024
1 parent a264ce0 commit e19a176
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
6 changes: 5 additions & 1 deletion Orleans.sln
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DistributedTests", "DistributedTests", "{FFEC9FEE-FEDF-4510-B7D2-0B0B3374ED2F}"
ProjectSection(SolutionItems) = preProject
test\DistributedTests\README.md = test\DistributedTests\README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DistributedTests.Common", "test\DistributedTests\DistributedTests.Common\DistributedTests.Common.csproj", "{E8FFBF2E-80FE-4D80-B79A-2097180D203A}"
EndProject
Expand Down Expand Up @@ -222,6 +225,7 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Orleans.Clustering.Cassandra", "src\Cassandra\Orleans.Clustering.Cassandra\Orleans.Clustering.Cassandra.csproj", "{7A1A2ECE-DC4B-4DE7-AEF7-855C50895171}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tester.Cassandra", "test\Extensions\Tester.Cassandra\Tester.Cassandra.csproj", "{15A1777E-D1B6-4DC8-81D4-998A4CBA63FE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Orleans.Streaming.AdoNet", "src\AdoNet\Orleans.Streaming.AdoNet\Orleans.Streaming.AdoNet.csproj", "{2B994F33-16CF-4679-936A-5AEABC529D2C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks.AdoNet", "test\Benchmarks.AdoNet\Benchmarks.AdoNet.csproj", "{B8F43537-2D2E-42A0-BE67-5E07E4313AEA}"
Expand All @@ -234,7 +238,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DashboardToy.Frontend", "pl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DashboardToy.AppHost", "playground\DashboardToy\DashboardToy.AppHost\DashboardToy.AppHost.csproj", "{84B44F1D-B7FE-40E3-82F0-730A55AC8613}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Orleans.Serialization.FSharp.Tests", "test\Orleans.Serialization.FSharp.Tests\Orleans.Serialization.FSharp.Tests.fsproj", "{B2D53D3C-E44A-4C9B-AAEE-28FB8C1BDF62}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Orleans.Serialization.FSharp.Tests", "test\Orleans.Serialization.FSharp.Tests\Orleans.Serialization.FSharp.Tests.fsproj", "{B2D53D3C-E44A-4C9B-AAEE-28FB8C1BDF62}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Orleans.Serialization.MessagePack", "src\Orleans.Serialization.MessagePack\Orleans.Serialization.MessagePack.csproj", "{F50F81B6-E9B5-4143-B66B-A1AD913F6E9C}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ private async Task Run()
// Immediately yield back to the caller
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding | ConfigureAwaitOptions.ContinueOnCapturedContext);

while (!_shutdownCts.IsCancellationRequested)
var cancellationToken = _shutdownCts.Token;
while (!cancellationToken.IsCancellationRequested)
{
try
{
// recheck every X seconds (Consider making it a configurable parameter)
await Task.Delay(SLEEP_TIME_BETWEEN_REFRESHES);
await Task.Delay(SLEEP_TIME_BETWEEN_REFRESHES, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing | ConfigureAwaitOptions.ContinueOnCapturedContext);
if (cancellationToken.IsCancellationRequested)
{
break;
}

// Run through all cache entries and do the following:
// 1. If the entry is not expired, skip it
Expand Down Expand Up @@ -101,19 +106,19 @@ private async Task Run()
if (entry == null)
{
// 0. If the entry was deleted in parallel, presumably due to cleanup after silo death
cache.Remove(grain); // for debug
removedCount++;
cache.Remove(grain);
removedCount++; // for debug
}
else if (!entry.IsExpired())
{
// 1. If the entry is not expired, skip it
keptCount++; // for debug
keptCount++; // for debug
}
else if (entry.NumAccesses == 0)
{
// 2. If the entry is expired and was not accessed in the last time interval -- throw it away
cache.Remove(grain); // for debug
removedCount++;
cache.Remove(grain);
removedCount++; // for debug
}
else
{
Expand All @@ -122,10 +127,11 @@ private async Task Run()
{
fetchInBatchList[owner] = list = new List<GrainId>();
}

list.Add(grain);
// And reset the entry's access count for next time
entry.NumAccesses = 0;
refreshedCount++; // for debug
refreshedCount++; // for debug
}
}

Expand All @@ -138,12 +144,12 @@ private async Task Run()
removedCount,
refreshedCount);

// send batch requests
// Send batch requests
SendBatchCacheRefreshRequests(fetchInBatchList);

ProduceStats();
}
catch (Exception ex) when (!_shutdownCts.IsCancellationRequested)
catch (Exception ex) when (!cancellationToken.IsCancellationRequested)
{
Log.LogError(ex, $"Error in {nameof(AdaptiveDirectoryCacheMaintainer)}.");
}
Expand Down

0 comments on commit e19a176

Please sign in to comment.