Use Stopwatch for INFO uptime and master_sync_last_io_seconds_ago#1771
Merged
kevin-montrose merged 1 commit intoMay 8, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR replaces wall-clock-based elapsed-time calculations in Garnet's INFO output with Stopwatch-based monotonic timing so uptime and replica sync age are not distorted by system clock adjustments. It affects both the standalone server metrics path and the cluster replication metrics path, with a new INFO test intended to cover the uptime behavior.
Changes:
- Replaced server startup elapsed-time math with a monotonic
startupTimestampanchor inStoreWrapperandGarnetInfoMetrics. - Replaced replica sync age tracking with monotonic timestamps in
ReplicationManagerformaster_sync_last_io_seconds_ago. - Added a new INFO test that checks
uptime_in_secondsincreases across two calls.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
test/Garnet.test/RespInfoTests.cs |
Adds a new INFO uptime test. |
libs/server/StoreWrapper.cs |
Renames/stores startup anchor as a stopwatch timestamp. |
libs/server/Metrics/Info/GarnetInfoMetrics.cs |
Computes server uptime from monotonic elapsed time. |
libs/cluster/Server/Replication/ReplicationManager.cs |
Computes replica sync age from monotonic elapsed time. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kevin-montrose
approved these changes
May 8, 2026
badrishc
added a commit
that referenced
this pull request
May 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
uptime_in_seconds,uptime_in_days, andmaster_sync_last_io_seconds_agoinINFOare computed fromDateTime.UtcNow.Ticksdeltas. A wall-clock adjustment (NTP step, manual time change) shifts the reported duration — backward steps make the values overshoot, forward steps make them go small or negative. Sentinel and similar tooling readmaster_sync_last_io_seconds_agoto decide failover candidacy.These fields are defined by Redis as durations ("seconds since X"), not timestamps, so monotonic time is what the spec actually means. Switch to
Stopwatch.GetTimestamp()/Stopwatch.GetElapsedTimefor the elapsed-time math.INFO serverandINFO replicationcontinue to expose the same field names and semantics, just sourced from a monotonic clock.Same NTP-resilience reasoning was applied recently in dotnet/runtime#127303 for
EventCounter's polling timer.Changes
StoreWrapper.startupTime→startupTimestamp(Stopwatch tick anchor).GarnetInfoMetrics.PopulateServerInforeads uptime viaStopwatch.GetElapsedTime(startupTimestamp).ReplicationManager.primary_sync_last_time→primary_sync_last_timestamp;LastPrimarySyncSecondsandUpdateLastPrimarySyncTimeuseStopwatch.RespInfoTests.UptimeIncreasesAcrossInfoCallsasserts uptime monotonically increases between twoINFOcalls.Test plan
net8.0andnet10.0.Garnet.serverandGarnet.clusterbuild clean.