Add LMDB oplog migration path with dual-write cutover support
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m16s
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m16s
Introduce LMDB oplog store, migration flags, telemetry/backfill tooling, and parity tests to enable staged Surreal-to-LMDB rollout with rollback coverage.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using ZB.MOM.WW.CBDDC.Core.Storage;
|
||||
using ZB.MOM.WW.CBDDC.Persistence.Surreal;
|
||||
|
||||
namespace ZB.MOM.WW.CBDDC.Persistence.Lmdb;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for adding the LMDB oplog provider and migration feature flags.
|
||||
/// </summary>
|
||||
public static class CBDDCLmdbOplogExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers LMDB oplog services and replaces <see cref="IOplogStore" /> with a feature-flag migration router.
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection.</param>
|
||||
/// <param name="optionsFactory">Factory creating LMDB environment options.</param>
|
||||
/// <param name="configureFlags">Optional migration feature-flag configuration.</param>
|
||||
/// <returns>The service collection.</returns>
|
||||
public static IServiceCollection AddCBDDCLmdbOplog(
|
||||
this IServiceCollection services,
|
||||
Func<IServiceProvider, LmdbOplogOptions> optionsFactory,
|
||||
Action<LmdbOplogFeatureFlags>? configureFlags = null)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
if (optionsFactory == null) throw new ArgumentNullException(nameof(optionsFactory));
|
||||
|
||||
services.TryAddSingleton(optionsFactory);
|
||||
|
||||
var flags = new LmdbOplogFeatureFlags
|
||||
{
|
||||
UseLmdbOplog = true,
|
||||
DualWriteOplog = true,
|
||||
PreferLmdbReads = false,
|
||||
EnableReadShadowValidation = false
|
||||
};
|
||||
configureFlags?.Invoke(flags);
|
||||
services.TryAddSingleton(flags);
|
||||
|
||||
services.TryAddSingleton<OplogMigrationTelemetry>();
|
||||
services.TryAddSingleton<LmdbOplogStore>();
|
||||
|
||||
bool surrealRegistered = services.Any(descriptor => descriptor.ServiceType == typeof(SurrealOplogStore));
|
||||
if (surrealRegistered)
|
||||
{
|
||||
services.TryAddSingleton<LmdbOplogBackfillTool>();
|
||||
services.Replace(ServiceDescriptor.Singleton<IOplogStore, FeatureFlagOplogStore>());
|
||||
}
|
||||
else
|
||||
services.Replace(ServiceDescriptor.Singleton<IOplogStore>(sp => sp.GetRequiredService<LmdbOplogStore>()));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user