Files
CBDDC/src/ZB.MOM.WW.CBDDC.Persistence/Lmdb/CBDDCLmdbOplogExtensions.cs
Joseph Doherty cce24fa8f3
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m16s
Add LMDB oplog migration path with dual-write cutover support
Introduce LMDB oplog store, migration flags, telemetry/backfill tooling, and parity tests to enable staged Surreal-to-LMDB rollout with rollback coverage.
2026-02-22 17:44:57 -05:00

55 lines
2.2 KiB
C#

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;
}
}