Skip to content

Commit d1dc662

Browse files
[Migration Engine Part 2] Add a migration checkpoint table to SQL Server and PostgreSQL (#5897)
* feat: Add Migration Checkpoints to EF Core - Introduced a new table `MigrationCheckpoints` to track migration states and progress. - Implemented `MigrationCheckpointEntity` to represent the checkpoint data structure. - Added `EFMigrationCheckpointStore` for managing checkpoint data with methods for reading and upserting checkpoints. - Created `MigrationCheckpointConfiguration` for configuring the entity in the DbContext. - Enhanced `ServiceControlDbContext` to include the new `MigrationCheckpoints` DbSet. - Updated `EfCoreExtensions` to provide an `UpsertCheckpoint` method for managing checkpoint persistence. - Added unit tests for `EFMigrationCheckpointStore` and `MigrationCheckpointTable` to ensure correct functionality. - Implemented transaction handling in `MigrationCheckpointTransactionTests` to verify checkpoint behavior during commits and rollbacks. - Updated RavenDB integration to support embedded server readiness checks. * feat: Enhance migration engine with improved error handling and configuration options * feat: Refactor migration checkpoint handling and add UpsertCheckpoint method * docs: Update migration documentation for clarity on RavenDB to SQL migration process * [Migration Engine Part 3] Implement the RavenDB to SQL migration machinery (#5911) * Update migration documentation * feat: run the required migration copy at host start Adds the RavenDB source and the EF Core target for the KnownEndpoints and EndpointSettings categories, the startup checks that refuse an unsupported or unready migration, and the stall watchdog that stops a copy committing nothing for 30 minutes. Documents the migration contracts. * test: cover the RavenDB to SQL migration end to end Adds unit tests for the startup checks, the stall watchdog and the refusals, target and reader tests for both persisters, a SQL Server collation test for the endpoint settings key, and acceptance tests for a copy that is killed, restarted and opened on. Approves the two new migration settings. * tests: ensure DB schema is setup before the host starts * refactor: update BatchSizeFor method to return Task<int> for async compatibility across migration targets * docs: update migration instructions and system design to clarify settings and behavior * Refactor migration checks and improve error handling * Refactor migration commands and error handling * PR review * Fix flakey test
1 parent 3ced8c5 commit d1dc662

149 files changed

Lines changed: 11303 additions & 595 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ the `launchSettings.json` file of each instance. When started in setup mode, the
3535

3636
## Migrating from RavenDB to SQL Server or PostgreSQL
3737

38-
See [Migrating from RavenDB to SQL Server or PostgreSQL](docs/migration/ravendb-to-sql-migration-instructions.md).
38+
- [Migrate from RavenDB to SQL Server or PostgreSQL](docs/migration/ravendb-to-sql-migration-instructions.md): what an operator can run today, and what is not built yet.
3939

4040
## Secrets
4141

-107 KB
Loading

‎docs/migration/ravendb-to-sql-migration-instructions.md‎

Lines changed: 208 additions & 26 deletions
Large diffs are not rendered by default.

‎docs/migration/ravendb-to-sql-migration-overview.md‎

Lines changed: 410 additions & 298 deletions
Large diffs are not rendered by default.

‎docs/migration/ravendb-to-sql-migration-system-design.md‎

Lines changed: 289 additions & 0 deletions
Large diffs are not rendered by default.

‎src/ServiceControl.AcceptanceTests.PostgreSql/ServiceControl.AcceptanceTests.PostgreSql.csproj‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<ItemGroup>
1313
<ProjectReference Include="..\ServiceControl.AcceptanceTesting\ServiceControl.AcceptanceTesting.csproj" />
1414
<ProjectReference Include="..\ServiceControl.Persistence.EFCore.PostgreSql\ServiceControl.Persistence.EFCore.PostgreSql.csproj" />
15+
<!-- Built so its manifest is where DevelopmentPersistenceLocations looks; not copied, or its persistence.manifest would collide with this project's own. -->
16+
<ProjectReference Include="..\ServiceControl.Persistence.RavenDB\ServiceControl.Persistence.RavenDB.csproj" ReferenceOutputAssembly="false" Private="false" />
17+
<ProjectReference Include="..\ServiceControl.RavenDB\ServiceControl.RavenDB.csproj" />
1518
<ProjectReference Include="..\ServiceControl.Transports.Learning\ServiceControl.Transports.Learning.csproj" />
1619
<ProjectReference Include="..\ServiceControl\ServiceControl.csproj" />
1720
<ProjectReference Include="..\TestHelper\TestHelper.csproj" />
@@ -20,6 +23,7 @@
2023
<ItemGroup>
2124
<PackageReference Include="GitHubActionsTestLogger" />
2225
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
26+
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
2327
<PackageReference Include="Microsoft.NET.Test.Sdk" />
2428
<PackageReference Include="NServiceBus.Heartbeat" />
2529
<PackageReference Include="NServiceBus.SagaAudit" />
@@ -31,6 +35,9 @@
3135

3236
<ItemGroup>
3337
<Compile Include="..\ServiceControl.AcceptanceTests\**\*.cs" LinkBase="Shared" />
38+
<Compile Include="..\ServiceControl.Migration.AcceptanceTests\**\*.cs" LinkBase="Migration" />
39+
<Compile Include="..\ServiceControl.Persistence.Tests\IngestedFailure.cs" />
40+
<Compile Include="..\ServiceControl.Persistence.Tests\EFCore\InMemoryBodyStoragePersistence.cs" />
3441
<Compile Include="..\ServiceControl.Persistence.Tests.PostgreSql\PostgreSqlSharedContainer.cs" />
3542
<Compile Include="..\ServiceControl.Persistence.Tests.PostgreSql\TestSchema.cs" />
3643
<Compile Include="..\ServiceControl.Persistence.Tests.PostgreSql\StopSharedPostgreSql.cs" />

‎src/ServiceControl.AcceptanceTests.SqlServer/ServiceControl.AcceptanceTests.SqlServer.csproj‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<ItemGroup>
1313
<ProjectReference Include="..\ServiceControl.AcceptanceTesting\ServiceControl.AcceptanceTesting.csproj" />
1414
<ProjectReference Include="..\ServiceControl.Persistence.EFCore.SqlServer\ServiceControl.Persistence.EFCore.SqlServer.csproj" />
15+
<!-- Built so its manifest is where DevelopmentPersistenceLocations looks; not copied, or its persistence.manifest would collide with this project's own. -->
16+
<ProjectReference Include="..\ServiceControl.Persistence.RavenDB\ServiceControl.Persistence.RavenDB.csproj" ReferenceOutputAssembly="false" Private="false" />
17+
<ProjectReference Include="..\ServiceControl.RavenDB\ServiceControl.RavenDB.csproj" />
1518
<ProjectReference Include="..\ServiceControl.Transports.Learning\ServiceControl.Transports.Learning.csproj" />
1619
<ProjectReference Include="..\ServiceControl\ServiceControl.csproj" />
1720
<ProjectReference Include="..\TestHelper\TestHelper.csproj" />
@@ -20,6 +23,7 @@
2023
<ItemGroup>
2124
<PackageReference Include="GitHubActionsTestLogger" />
2225
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
26+
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
2327
<PackageReference Include="Microsoft.NET.Test.Sdk" />
2428
<PackageReference Include="NServiceBus.Heartbeat" />
2529
<PackageReference Include="NServiceBus.SagaAudit" />
@@ -31,6 +35,9 @@
3135

3236
<ItemGroup>
3337
<Compile Include="..\ServiceControl.AcceptanceTests\**\*.cs" LinkBase="Shared" />
38+
<Compile Include="..\ServiceControl.Migration.AcceptanceTests\**\*.cs" LinkBase="Migration" />
39+
<Compile Include="..\ServiceControl.Persistence.Tests\IngestedFailure.cs" />
40+
<Compile Include="..\ServiceControl.Persistence.Tests\EFCore\InMemoryBodyStoragePersistence.cs" />
3441
<Compile Include="..\ServiceControl.Persistence.Tests.SqlServer\SqlServerSharedContainer.cs" />
3542
<Compile Include="..\ServiceControl.Persistence.Tests.SqlServer\TestSchema.cs" />
3643
<Compile Include="..\ServiceControl.Persistence.Tests.SqlServer\StopSharedSqlServer.cs" />

‎src/ServiceControl.AcceptanceTests/Recoverability/When_hosting_error_ingestion_only.cs‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ namespace ServiceControl.AcceptanceTests.Recoverability
2929
using ServiceControl.Infrastructure;
3030
using ServiceControl.MessageFailures;
3131
using ServiceControl.Operations;
32+
using ServiceControl.Persistence.DataMigration;
3233
using ServiceControl.Persistence.EFCore.DbContexts;
3334
using ServiceControl.Persistence.EFCore.Entities;
34-
using ServiceControl.Persistence.EFCore.Infrastructure;
35-
using ServiceControl.Recoverability;
3635
using ServiceControl.Transports;
3736

3837
class When_hosting_error_ingestion_only : AcceptanceTest
@@ -98,9 +97,36 @@ public async Task Should_default_the_concurrency_to_10_when_none_is_configured()
9897
"InternalCustomChecksHostedService", // reports this node's ingestion health to the database
9998
"MetricsReporterHostedService",
10099
"HealthCheckPublisherHostedService", // inert, no IHealthCheckPublisher is registered
101-
"ExternalIntegrationRequestsDataStore" // its drain is inert here, nothing calls Subscribe
100+
"ExternalIntegrationRequestsDataStore", // its drain is inert here, nothing calls Subscribe
101+
"FinishedCopyBeforeAnIngestionNodeOpens" // keeps this node out of a database a copy has not finished filling
102102
];
103103

104+
[Test]
105+
public async Task Should_refuse_to_start_while_a_copy_into_the_database_is_unfinished()
106+
{
107+
var settings = await CreateSettings();
108+
109+
await new SetupCommand().Execute(new HostArguments([]), settings);
110+
111+
var host = ErrorIngestionOnlyCommand.BuildHost(settings);
112+
113+
try
114+
{
115+
await host.Services.GetRequiredService<IMigrationCheckpointStore>().Upsert(
116+
new MigrationCheckpoint(MigrationCategoryIds.KnownEndpoints, MigrationCategoryState.Halted, null, 0, 0, null, null, null, null, null, "The source stopped responding."));
117+
118+
var exception = Assert.ThrowsAsync<Exception>(() => host.StartAsync());
119+
120+
Assert.That(exception.Message, Does.Contain("has not finished")
121+
.And.Contain(MigrationCategoryIds.KnownEndpoints)
122+
.And.Contain("--migration-abandon KnownEndpoints"));
123+
}
124+
finally
125+
{
126+
await host.DisposeAsync();
127+
}
128+
}
129+
104130
[Test]
105131
public void Should_refuse_to_start_against_unsupported_storage()
106132
{
@@ -201,6 +227,7 @@ public async Task Should_serve_health_over_https_with_the_configured_certificate
201227
await new SetupCommand().Execute(new HostArguments([]), settings);
202228

203229
host = ErrorIngestionOnlyCommand.BuildHost(settings);
230+
host.Urls.Clear();
204231
host.Urls.Add("https://127.0.0.1:0");
205232

206233
await host.StartAsync();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[*.cs]
2+
3+
# Justification: Test project
4+
dotnet_diagnostic.CA2007.severity = none
5+
dotnet_diagnostic.PS0013.severity = none
6+
dotnet_diagnostic.PS0018.severity = none

0 commit comments

Comments
 (0)