Path: redb-tsak/src/redb.Tsak.Core/Services/NamedRedbStartFailures.cs
Snapshot: redb-tsak, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-tsak
Page: https://redbase.app/src/dev-2026-12-06/redb-tsak/src/redb.Tsak.Core/Services/NamedRedbStartFailures.cs
----
using System.Collections.Concurrent;
namespace redb.Tsak.Core.Services;
///
/// What went wrong with the named redb instances of the contexts at their start, kept for the health check: an instance
/// whose schema bootstrap failed (it is registered and may work once the database answers), and an instance that was
/// not registered because its database refused the start. A line of the log at start is easy to miss; this stays until
/// the context is removed or built again.
///
internal sealed class NamedRedbStartFailures
{
/// False when the instance was not registered at all.
///
/// The type of the failure. Its message stays in the log: a health answer may be read without authorization (the
/// readiness probe), and a message of a driver names the database host.
///
internal sealed record Failure(string ContextName, string InstanceName, bool Registered, string Kind);
private readonly ConcurrentDictionary<(string Context, string Instance), Failure> _failures = new();
internal void Report(string contextName, string instanceName, bool registered, Exception failure) =>
_failures[(contextName.ToLowerInvariant(), instanceName.ToLowerInvariant())] =
new Failure(contextName, instanceName, registered, failure.GetType().Name);
/// Forgets a context: it was removed, or is about to be built again.
internal void Clear(string contextName)
{
var key = contextName.ToLowerInvariant();
foreach (var entry in _failures.Keys.Where(k => k.Context == key))
_failures.TryRemove(entry, out _);
}
internal IReadOnlyList Current =>
_failures.Values
.OrderBy(f => f.ContextName, StringComparer.OrdinalIgnoreCase)
.ThenBy(f => f.InstanceName, StringComparer.OrdinalIgnoreCase)
.ToArray();
}