namespace SQLInsight.Core.Data;
///
/// Deadlocks captured by the system_health Extended Events session since the previous collection.
///
public sealed record DeadlockSnapshot
{
public required DateTimeOffset CapturedAt { get; init; }
/// Deadlocks newer than the previous collection.
public required IReadOnlyList NewDeadlocks { get; init; }
/// Newest event time seen so far; the next collection starts after it.
public DateTimeOffset? LastEventTime { get; init; }
/// Where reading stopped in the event file, so the next read does not rescan all files.
public string? LastFileName { get; init; }
public long? LastFileOffset { get; init; }
}
public sealed record DeadlockEvent
{
public required DateTimeOffset Time { get; init; }
public required IReadOnlyList Processes { get; init; }
/// The raw deadlock graph (XDL), for download and viewing in SSMS.
public required string GraphXml { get; init; }
///
/// Every participant is SQLInsight Pro itself (monitoring or its own repository), e.g. when the repository lives on
/// a monitored instance. Not the customer's problem, so not reported. A deadlock with any other session is kept.
///
public bool IsOwn => Processes.Count > 0
&& Processes.All(p => p.ClientApp?.StartsWith(OwnApplicationName, StringComparison.Ordinal) == true);
/// Application Name prefix on all of SQLInsight Pro's connections ("SQLInsight Pro", "SQLInsight Pro (repository)").
public const string OwnApplicationName = "SQLInsight Pro";
}
public sealed record DeadlockProcess
{
public required string Id { get; init; }
public bool IsVictim { get; init; }
public int? SessionId { get; init; }
public string? DatabaseName { get; init; }
public string? LoginName { get; init; }
public string? HostName { get; init; }
public string? ClientApp { get; init; }
public string? IsolationLevel { get; init; }
public string? WaitResource { get; init; }
public string? LockMode { get; init; }
public string? InputBuffer { get; init; }
}