fix(localdb): telemetry review fixes — meter naming, snapshot status, session-count Connected
Claude-Session: https://claude.ai/code/session_01BL2Vu1ESDQ9SCN4gVKkdts
This commit is contained in:
@@ -16,8 +16,8 @@ public interface ISyncStatus
|
||||
/// <summary>When the last inbound batch was applied / acked, else null if no sync has occurred.</summary>
|
||||
DateTimeOffset? LastSyncUtc { get; }
|
||||
|
||||
/// <summary>The current unacked oplog backlog (entries above the peer's last-acked watermark).</summary>
|
||||
long OplogBacklog { get; }
|
||||
/// <summary>The current unacked oplog backlog (entries above the peer's last-acked watermark), or null when unknown (no provider wired / the poll failed) — so a DB failure never masquerades as "0 backlog".</summary>
|
||||
long? OplogBacklog { get; }
|
||||
|
||||
/// <summary>Number of connection attempts the initiator has made this lifetime.</summary>
|
||||
long ConnectionAttempts { get; }
|
||||
@@ -30,15 +30,17 @@ public interface ISyncStatus
|
||||
/// </summary>
|
||||
internal sealed class SyncStatus : ISyncStatus
|
||||
{
|
||||
private volatile int _connected;
|
||||
// A node can run BOTH roles at once (initiator + passive server), so Connected tracks a count
|
||||
// of active sessions rather than a boolean — one session ending must not clobber the other.
|
||||
private int _activeSessions;
|
||||
private string? _peerNodeId;
|
||||
private long _lastSyncUtcTicks = -1;
|
||||
private long _connectionAttempts;
|
||||
|
||||
/// <summary>Supplies the live unacked backlog for <see cref="OplogBacklog"/>; null yields 0.</summary>
|
||||
/// <summary>Supplies the live unacked backlog for <see cref="OplogBacklog"/>; null / a throwing poll yields a null (unknown) backlog.</summary>
|
||||
public Func<long>? OplogBacklogProvider { get; set; }
|
||||
|
||||
public bool Connected => _connected != 0;
|
||||
public bool Connected => Volatile.Read(ref _activeSessions) > 0;
|
||||
|
||||
public string? PeerNodeId => Volatile.Read(ref _peerNodeId);
|
||||
|
||||
@@ -51,27 +53,29 @@ internal sealed class SyncStatus : ISyncStatus
|
||||
}
|
||||
}
|
||||
|
||||
public long OplogBacklog
|
||||
public long? OplogBacklog
|
||||
{
|
||||
get
|
||||
{
|
||||
var provider = OplogBacklogProvider;
|
||||
if (provider is null)
|
||||
return 0;
|
||||
return null;
|
||||
try
|
||||
{
|
||||
return provider();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long ConnectionAttempts => Interlocked.Read(ref _connectionAttempts);
|
||||
|
||||
public void SetConnected(bool value) => _connected = value ? 1 : 0;
|
||||
public void SessionStarted() => Interlocked.Increment(ref _activeSessions);
|
||||
|
||||
public void SessionEnded() => Interlocked.Decrement(ref _activeSessions);
|
||||
|
||||
public void SetPeerNodeId(string peerNodeId) => Volatile.Write(ref _peerNodeId, peerNodeId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user