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

[7.x] Fix exception while collecting activations when activation.KeepAliveUntil = DateTime.MaxValue (#8740) #8755

Merged
merged 1 commit into from
Dec 2, 2023
Merged
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
16 changes: 8 additions & 8 deletions src/Orleans.Runtime/Catalog/ActivationCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public int GetNumRecentlyUsed(TimeSpan recencyPeriod)
/// <param name="timeout">
/// The current idle collection time for the grain.
/// </param>
public void ScheduleCollection(ICollectibleGrainContext item, TimeSpan timeout)
public void ScheduleCollection(ICollectibleGrainContext item, TimeSpan timeout, DateTime now)
{
lock (item)
{
Expand All @@ -94,7 +94,7 @@ public void ScheduleCollection(ICollectibleGrainContext item, TimeSpan timeout)
return;
}

DateTime ticket = MakeTicketFromTimeSpan(timeout);
DateTime ticket = MakeTicketFromTimeSpan(timeout, now);

if (default != item.CollectionTicket)
{
Expand Down Expand Up @@ -154,7 +154,7 @@ private bool TryRescheduleCollection_Impl(ICollectibleGrainContext item, TimeSpa
if (IsExpired(item.CollectionTicket)) return false;

DateTime oldTicket = item.CollectionTicket;
DateTime newTicket = MakeTicketFromTimeSpan(timeout);
DateTime newTicket = MakeTicketFromTimeSpan(timeout, DateTime.UtcNow);
// if the ticket value doesn't change, then the source and destination bucket are the same and there's nothing to do.
if (newTicket.Equals(oldTicket)) return true;

Expand Down Expand Up @@ -239,11 +239,11 @@ public List<ICollectibleGrainContext> ScanStale()
{
var keepAliveDuration = activation.KeepAliveUntil - now;
var timeout = TimeSpan.FromTicks(Math.Max(keepAliveDuration.Ticks, activation.CollectionAgeLimit.Ticks));
ScheduleCollection(activation, timeout);
ScheduleCollection(activation, timeout, now);
}
else if (!activation.IsInactive || !activation.IsStale())
{
ScheduleCollection(activation, activation.CollectionAgeLimit);
ScheduleCollection(activation, activation.CollectionAgeLimit, now);
}
else
{
Expand Down Expand Up @@ -354,14 +354,14 @@ private DateTime MakeTicketFromDateTime(DateTime timestamp)
return ticket;
}

private DateTime MakeTicketFromTimeSpan(TimeSpan timeout)
private DateTime MakeTicketFromTimeSpan(TimeSpan timeout, DateTime now)
{
if (timeout < quantum)
{
throw new ArgumentException(string.Format("timeout must be at least {0}, but it is {1}", quantum, timeout), nameof(timeout));
}

return MakeTicketFromDateTime(DateTime.UtcNow + timeout);
return MakeTicketFromDateTime(now + timeout);
}

private void Add(ICollectibleGrainContext item, DateTime ticket)
Expand All @@ -379,7 +379,7 @@ void IActivationWorkingSetObserver.OnAdded(IActivationWorkingSetMember member)
{
if (activation.CollectionTicket == default)
{
ScheduleCollection(activation, activation.CollectionAgeLimit);
ScheduleCollection(activation, activation.CollectionAgeLimit, DateTime.UtcNow);
}
else
{
Expand Down
Loading