test: validate grpc data connections with local docker and opcua cli
This commit is contained in:
@@ -53,7 +53,7 @@ public static class DataConnectionRegistration
|
||||
return new LocalCatalogCoordinator(sp.GetRequiredService<CatalogActivation>(), sp.GetRequiredService<DataPlaneAuthorityState>(),
|
||||
() =>
|
||||
{
|
||||
var state = CaptureRole(role, warm);
|
||||
var state = CaptureReadRole(role, warm);
|
||||
var servingRole = settings.IsWarm && state.WarmRole != WarmRole.Active ? "Standby" : state.Role;
|
||||
return new(identity.NodeId, identity.Incarnation, servingRole, 0, 0, state.Generation);
|
||||
});
|
||||
@@ -108,12 +108,12 @@ public static class DataConnectionRegistration
|
||||
localWriteRole: () =>
|
||||
{
|
||||
var role = sp.GetRequiredService<RedundancyRoleView>();
|
||||
var state = CaptureRole(role, sp.GetRequiredService<DataConnectionWarmRoleView>());
|
||||
var state = CaptureWriteRole(role, sp.GetRequiredService<DataConnectionWarmRoleView>());
|
||||
var settings = sp.GetService<WarmRedundancySettings>() ?? WarmRedundancySettings.Unset;
|
||||
var active = sp.GetRequiredService<LocalCatalogCoordinator>().Current is { IsActive: true };
|
||||
return (active && role.ShouldActAsPrimary && state.Role == "Primary" &&
|
||||
(!settings.IsWarm || state.WarmRole == WarmRole.Active), state.Generation);
|
||||
}));
|
||||
}, renewalSink: sp.GetRequiredService<IProjectedNamespacePageSink>()));
|
||||
services.AddSingleton<IProjectedDataAccess>(sp => sp.GetRequiredService<ProjectedDataAccess>());
|
||||
services.AddSingleton<IConfiguredProjectionDiscovery>(sp => new ConfiguredProjectionDiscovery(
|
||||
sp.GetRequiredService<ProjectedMappingDeploymentRuntime>(), sp.GetRequiredService<IFederatedProjectionCatalog>(),
|
||||
@@ -171,6 +171,7 @@ public static class DataConnectionRegistration
|
||||
sp.GetRequiredService<DataConnectionSecretChangeHandler>(), id.ClusterId, id.NodeId);
|
||||
});
|
||||
services.AddSingleton<IDataConnectionSecurityProvider, DataConnectionSecurityProvider>();
|
||||
services.AddSingleton<IDataConnectionBundleCommitObserver, DataConnectionBundleCommitObserver>();
|
||||
services.AddSingleton<IDataConnectionScopeActivator, DataConnectionScopeActivator>();
|
||||
services.AddSingleton(sp =>
|
||||
{
|
||||
@@ -183,7 +184,7 @@ public static class DataConnectionRegistration
|
||||
sp.GetRequiredService<IDataConnectionScopeActivator>(), 256, sp.GetRequiredService<TimeProvider>(),
|
||||
() =>
|
||||
{
|
||||
var state = CaptureRole(role, warm);
|
||||
var state = CaptureReadRole(role, warm);
|
||||
var mode = settings.Mode switch
|
||||
{
|
||||
OpcUaRedundancyMode.Warm => RedundancyMode.Warm,
|
||||
@@ -192,6 +193,25 @@ public static class DataConnectionRegistration
|
||||
};
|
||||
return state.Generation > 0 && Enum.TryParse<RedundancyRole>(state.Role, out var actual)
|
||||
&& DataConnectionRoleAdapter.MayAcquire(mode, state.WarmRole, actual);
|
||||
}, useCompactBatches: options.UseCompactBatches, consumerRoleSnapshot: artifactMode =>
|
||||
{
|
||||
var mode = settings.Mode switch
|
||||
{
|
||||
OpcUaRedundancyMode.Warm => RedundancyMode.Warm,
|
||||
OpcUaRedundancyMode.None => RedundancyMode.None,
|
||||
_ => artifactMode
|
||||
};
|
||||
if (mode == RedundancyMode.Hot)
|
||||
{
|
||||
var hot = role.CaptureDataServingRole();
|
||||
var hotEligible = hot.Generation > 0 && Enum.TryParse<RedundancyRole>(hot.Role, out var hotRole)
|
||||
&& DataConnectionRoleAdapter.MayAcquire(mode, null, hotRole);
|
||||
return new DataConnectionConsumerRoleSnapshot(mode, hotEligible, hot.ReadEligibilityEpoch);
|
||||
}
|
||||
var state = CaptureReadRole(role, warm);
|
||||
var eligible = state.Generation > 0 && Enum.TryParse<RedundancyRole>(state.Role, out var actual)
|
||||
&& DataConnectionRoleAdapter.MayAcquire(mode, state.WarmRole, actual);
|
||||
return new DataConnectionConsumerRoleSnapshot(mode, eligible, state.Generation);
|
||||
});
|
||||
return runtime;
|
||||
});
|
||||
@@ -213,19 +233,37 @@ public static class DataConnectionRegistration
|
||||
return options;
|
||||
}
|
||||
|
||||
private static (string Role, long Generation, WarmRole? WarmRole) CaptureRole(RedundancyRoleView role, DataConnectionWarmRoleView warm)
|
||||
private static (string Role, long Generation, WarmRole? WarmRole, long ReadEpoch) CaptureReadRole(
|
||||
RedundancyRoleView role, DataConnectionWarmRoleView warm)
|
||||
{
|
||||
if (!ReferenceEquals(role.DispatchFence, warm.DispatchFence)) return ("Unknown", 0, null, 0);
|
||||
|
||||
// Both verdicts are immutable. The monotone primary generation brackets
|
||||
// the Warm read, so a stable generation gives a pair that coexisted.
|
||||
// A competing read or dispatch does not withdraw an unchanged role.
|
||||
var primary = role.CaptureDataServingRole();
|
||||
var warmVerdict = warm.Snapshot;
|
||||
return primary.Generation == role.PrimaryGeneration
|
||||
? CombineRole(primary, warmVerdict)
|
||||
: ("Unknown", 0, null, 0);
|
||||
}
|
||||
|
||||
private static (string Role, long Generation, WarmRole? WarmRole, long ReadEpoch) CaptureWriteRole(
|
||||
RedundancyRoleView role, DataConnectionWarmRoleView warm)
|
||||
{
|
||||
if (!ReferenceEquals(role.DispatchFence, warm.DispatchFence) || !role.DispatchFence.TryEnter(out var lease))
|
||||
return ("Unknown", 0, null);
|
||||
return ("Unknown", 0, null, 0);
|
||||
using (lease)
|
||||
{
|
||||
var observed = role.DataServingRole;
|
||||
var primaryGeneration = role.PrimaryGeneration;
|
||||
var verdict = warm.Snapshot;
|
||||
if (primaryGeneration == long.MaxValue || verdict.Generation == long.MaxValue
|
||||
|| primaryGeneration > long.MaxValue - verdict.Generation) return ("Unknown", long.MaxValue, null);
|
||||
return (observed, primaryGeneration + verdict.Generation, verdict.Role);
|
||||
}
|
||||
return CombineRole(role.CaptureDataServingRole(), warm.Snapshot);
|
||||
}
|
||||
|
||||
private static (string Role, long Generation, WarmRole? WarmRole, long ReadEpoch) CombineRole(
|
||||
DataServingRoleSnapshot primary, DataConnectionWarmRoleSnapshot warm)
|
||||
{
|
||||
if (primary.Generation == long.MaxValue || warm.Generation == long.MaxValue
|
||||
|| primary.Generation > long.MaxValue - warm.Generation)
|
||||
return ("Unknown", long.MaxValue, null, long.MaxValue);
|
||||
return (primary.Role, primary.Generation + warm.Generation, warm.Role, primary.ReadEligibilityEpoch);
|
||||
}
|
||||
|
||||
private sealed class DeferredFactory(Func<IDataConnectionFactory> resolve) : IDataConnectionFactory
|
||||
|
||||
Reference in New Issue
Block a user