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

Wait for migrating activations to become active or terminated #8527

Merged
merged 2 commits into from
Jul 6, 2023
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
33 changes: 30 additions & 3 deletions src/Orleans.Runtime/Catalog/ActivationMigrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,43 @@ public ActivationMigrationManager(
}
}

public ValueTask AcceptMigratingGrains(List<GrainMigrationPackage> migratingGrains)
public async ValueTask AcceptMigratingGrains(List<GrainMigrationPackage> migratingGrains)
{
var activations = new List<ActivationData>();
foreach (var package in migratingGrains)
{
// If the activation does not exist, create it and provide it with the migration context while doing so.
// If the activation already exists or cannot be created, it is too late to perform migration, so ignore the request.
_catalog.GetOrCreateActivation(package.GrainId, requestContextData: null, package.MigrationContext);
var context = _catalog.GetOrCreateActivation(package.GrainId, requestContextData: null, package.MigrationContext);
if (context is ActivationData activation)
{
activations.Add(activation);
}
}

return default;
while (true)
{
var allActiveOrTerminal = true;
foreach (var activation in activations)
{
lock (activation)
{
if (activation.State is not ActivationState.Valid or ActivationState.Invalid or ActivationState.FailedToActivate)
{
allActiveOrTerminal = false;
break;
}
}
}

if (allActiveOrTerminal)
{
break;
}

// Wait a short amount of time and poll the activations again.
await Task.Delay(5);
}
}

public ValueTask MigrateAsync(SiloAddress targetSilo, GrainId grainId, MigrationContext migrationContext)
Expand Down
21 changes: 18 additions & 3 deletions test/DefaultCluster.Tests/Migration/MigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public async Task DirectedGrainMigrationTest()
RequestContext.Set(IPlacementDirector.PlacementHintKey, targetHost);
await grain.Cast<IGrainManagementExtension>().MigrateOnIdle();

var newAddress = await grain.GetGrainAddress();
GrainAddress newAddress;
do
{
newAddress = await grain.GetGrainAddress();
} while (newAddress.ActivationId == originalAddress.ActivationId);

var newHost = newAddress.SiloAddress;
Assert.Equal(targetHost, newHost);

Expand Down Expand Up @@ -91,7 +96,12 @@ public async Task DirectedGrainMigrationTest_GrainOfT()
RequestContext.Set(IPlacementDirector.PlacementHintKey, targetHost);
await grain.Cast<IGrainManagementExtension>().MigrateOnIdle();

var newAddress = await grain.GetGrainAddress();
GrainAddress newAddress;
do
{
newAddress = await grain.GetGrainAddress();
} while (newAddress.ActivationId == originalAddress.ActivationId);

var newHost = newAddress.SiloAddress;
Assert.Equal(targetHost, newHost);

Expand Down Expand Up @@ -121,7 +131,12 @@ public async Task DirectedGrainMigrationTest_IPersistentStateOfT()
RequestContext.Set(IPlacementDirector.PlacementHintKey, targetHost);
await grain.Cast<IGrainManagementExtension>().MigrateOnIdle();

var newAddress = await grain.GetGrainAddress();
GrainAddress newAddress;
do
{
newAddress = await grain.GetGrainAddress();
} while (newAddress.ActivationId == originalAddress.ActivationId);

var newHost = newAddress.SiloAddress;
Assert.Equal(targetHost, newHost);

Expand Down
Loading