Skip to content

Add restart-safe backup staleness gauges - #178

Open
arkmish wants to merge 1 commit into
branch-3.6from
armishra/restart-safe-backup-staleness
Open

arkmish wants to merge 1 commit into
branch-3.6from
armishra/restart-safe-backup-staleness

Conversation

@arkmish

@arkmish arkmish commented Nov 16, 2026

Copy link
Copy Markdown

Description

MinutesSinceLastSuccessful{Snapshot,TxnLog,Timetable}Iteration start over at 0 every time the server starts, because BackupStats and TimetableBackupStats take the process start time as the last success. A backup server that keeps restarting before an iteration completes, for example one evicted while staging a large txn log backlog or one crashing on startup, never looks stale, so alerts on these gauges cannot fire.

This adds three gauges that survive restarts:

  • MinutesSinceLastSuccessfulSnapshotIterationAcrossRestarts and MinutesSinceLastSuccessfulTxnLogIterationAcrossRestarts on the Backup MBean
  • MinutesSinceLastSuccessfulTimetableIterationAcrossRestarts on the TimetableBackup MBean

Each successful iteration writes its finish time to a small file in the backup status directory (zkBackupLastSuccessful{Snapshot,TxnLog,Timetable}Iteration), and the stats seed the new gauges from those files on startup. A missing or unreadable file falls back to the process start time, as before. Writes go through a temp file and an atomic rename, and a failed write is only logged.

The existing gauges keep their behavior. Alert actions that restart the server on a stale backup rely on the reset; with a restart-safe value they would keep restarting the server until a backup succeeds.

The 3.8.x backup port (#175) will need the same change.

Tests

The following tests are written for this issue:

  • BackupStatsTest (new, uses an injected clock): the new gauges continue after a restart while the existing ones restart at 0; a failed iteration does not reset them and a successful one does; snapshot and txn log are tracked separately; a missing or corrupt file, or no status directory, falls back to process start; the timetable gauge behaves the same.
  • BackupBeanTest test2 and test3: after a restarted BackupManager, the new gauges report more than 0 minutes while the existing gauges are back at 0.

The following is the result of the "mvn test" command on the appropriate module:

  • mvn -pl zookeeper-server test -Dtest='org.apache.zookeeper.server.backup.**.*Test,BackupManagerTest' on JDK 11: 45 run, 1 failure. The failure was the existing lastTimetableIterationDuration > 0 assertion in BackupBeanTest.test3; run alone, test3 passed twice on this branch and twice on unmodified branch-3.6.
  • After a final change to PersistedTimestamp: BackupBeanTest 3/3 and BackupStatsTest 6/6 passed.
  • mvn -pl zookeeper-server -Pfull-build -DskipTests verify spotbugs:check checkstyle:check apache-rat:check: passed.
  • Not run locally: JDK 8 build and the full test suite.
  • Local code review completed

Changes that Break Backward Compatibility (Optional)

None. Existing MBean attributes are unchanged; three attributes are added, and the backup status directory gains three small files.

🤖 Generated with GitHub Copilot CLI

MinutesSinceLastSuccessful{Snapshot,TxnLog,Timetable}Iteration start over at 0 every time the
server starts, because BackupStats and TimetableBackupStats take the process start time as the last
success. A backup server that keeps restarting before an iteration completes, for example one evicted
while staging a large txn log backlog or one crashing on startup, never looks stale, so alerts on
these gauges cannot fire.

Add MinutesSinceLastSuccessful{Snapshot,TxnLog,Timetable}IterationAcrossRestarts. Each successful
iteration writes its finish time to a small file in the backup status directory, and the stats seed
the new gauges from those files on startup. A missing or unreadable file falls back to the process
start time, as before. Writes go through a temp file and an atomic rename, and a failed write is
logged without affecting the backup.

The existing gauges keep their behavior. Alert actions that restart the server on a stale backup
rely on the reset; with a restart-safe value they would keep restarting the server until a backup
succeeds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bellatrix007

Copy link
Copy Markdown

Lets wait for this PR and merge it in the latest 3.6.7 branch whenever its ready?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants