Skip to content

HBASE-30547 Master active time can go backwards after a failover to a master whose clock is behind - #8898

Open
SpookyJumpyBeans wants to merge 2 commits into
apache:masterfrom
SpookyJumpyBeans:HBASE-30547
Open

SpookyJumpyBeans wants to merge 2 commits into
apache:masterfrom
SpookyJumpyBeans:HBASE-30547

Conversation

@SpookyJumpyBeans

@SpookyJumpyBeans SpookyJumpyBeans commented Nov 16, 2026 •

Copy link
Copy Markdown

https://issues.apache.org/jira/browse/HBASE-30547

Since HBASE-28690 a master rejects a report whose initiating master active time is greater than its own. The active time comes from the wall clock, so after a failover to a master whose clock is behind, the new master can have a lower active time than the old one and rejects every report for a procedure the old master started. For a region open, the region server keeps retrying OPENED with the old active time and ignores the new master's re-dispatch of the same procedure, so the region stays in OPENING while the new master is active.

Changes

  • New MasterActiveTimeStore, a MasterStateStore holding the last active master's active time in the master local region.
  • HMaster.finishActiveMasterInitialization still reads the clock as before, then, right after opening the master local region, sets the active time to max(now, last stored + 1) and stores it:
masterRegion = MasterRegionFactory.create(this);
rsListStorage = new MasterRegionServerList(masterRegion, this);
// The active time is sent with remote procedures and must be greater than that of every earlier
// active master, see MasterActiveTimeStore. Opening the master local region has fenced off the
// earlier active master, and no remote procedure has been sent yet.
this.masterActiveTime = new MasterActiveTimeStore(masterRegion).advance(masterActiveTime);

Opening the master local region renames the previous master's WAL directory and recovers the lease on its WAL files, so the previous master can no longer write to it. The procedure executor is created after this point, so no remote procedure carries the earlier value, and reports are only checked once serviceStarted is set, also later. A warning is logged when the stored time is used, since it means the masters' clocks disagree.

  • If the stored active time is ahead of the new master's clock by more than hbase.master.maxclockskew (30s by default, the same limit ServerManager uses for region servers), startup fails with a ClockOutOfSyncException and nothing is stored. Below that, the stored time plus one is used and a warning is logged. The 30s default is now ServerManager.DEFAULT_MAX_CLOCK_SKEW_MS.
  • The "completed initialization" log line measures from the clock read instead of the active time, which can now be ahead of the clock.
  • masterActiveTime is now volatile, since RPC handlers read it and it is now written twice during initialization.
  • The clock read is moved into a protected getCurrentTimeForActiveTime(), so a test can simulate a master whose clock is behind.

Limits

  • If a past active master's clock was more than hbase.master.maxclockskew ahead, the time it stored stays ahead, so later masters with correct clocks fail to start until the wall clock passes it.
  • Only failovers between masters with this change are covered. The first master started on this version has no stored value and uses its clock. An older master in a rolling upgrade does not store its active time.
  • branch-2.5 has HBASE-28690 but no master state store, so a backport there would need another place for the value. branch-2.6, branch-2, branch-3 have MasterStateStore.

Other approaches I looked at: the master start code comes from the same clock; the zxid of the active master znode is monotonic but on a different scale, which would break comparisons with older masters during an upgrade; and the initiating active time is not persisted with the procedures, so it can't be recovered from the procedure store.

Tests

  • TestOpenRegionReportAfterFailoverToMasterWithClockBehind: holds the OPENED report on the active master, fails over to a master whose clock is behind (through an override of getCurrentTimeForActiveTime()), and releases the report. Without this change the new master keeps rejecting the report ("initiatingMasterAT 1794786260006 received on master with activeTime 1794786200028", thousands of times per run) and the open never finishes. With this change the open finishes on the new master.
  • TestMasterActiveTimeStore: unit tests for advance, including a malformed stored value and the max clock skew check.

I ran these on Linux (WSL) with JDK 21: the new test passed 5 of 5 runs with this change and fails without it. These also pass with it: TestMasterActiveTimeStore, TestOpenRegionProcedureHang, TestReportRegionStateTransitionRetry, TestServerRemoteProcedure, TestMasterFailover, TestMasterMetrics, TestMasterMetricsWrapper, TestMasterNoCluster, TestMasterRegionInitialize, TestSnapshotCleanupStateStore.

@JHSUYU

JHSUYU commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@Umeshkumar9414 @mnpoonia

@charlesconnell charlesconnell left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the merit of storing the active master's start time. However, if a new master starts up and detects the clock has gone backwards, I think it would be better to fail startup, rather than inventing a new startup time that has no relationship to the system clock. Clocks are not supposed to go backwards, so it would be better to expose that issue than paper over it.

@SpookyJumpyBeans

Copy link
Copy Markdown
Author

@charlesconnell, thanks for taking a look! I agree a real clock problem should be visible rather than hidden. My concern with failing startup is that this case doesn't need a clock going backwards on one host. It only needs the backup master's clock to be behind the old master's by more than the time between the two becoming active, which in a fast failover can be a few seconds. HBase already accepts that much skew between servers: ServerManager.checkClockSkew only warns above hbase.master.warningclockskew (10s) and rejects above hbase.master.maxclockskew (30s). If the backup master refused to start in that case, the cluster would be left without an active master during the failover.

How about doing both: if the stored active time is ahead of the new master's clock by more than hbase.master.maxclockskew, fail startup with an error that says the masters' clocks are out of sync, and below that use the stored time plus one and log a warning, as now. That keeps the behavior consistent with the existing region server check. If you'd rather always fail, I can change it to that instead.

@charlesconnell

Copy link
Copy Markdown
Contributor

How about doing both: if the stored active time is ahead of the new master's clock by more than hbase.master.maxclockskew, fail startup with an error that says the masters' clocks are out of sync, and below that use the stored time plus one and log a warning, as now.

That sounds great

@SpookyJumpyBeans

Copy link
Copy Markdown
Author

Thanks! Pushed it. If the stored active time is ahead of the new master's clock by more than hbase.master.maxclockskew (30s by default), startup now fails with a ClockOutOfSyncException that says the masters' clocks are out of sync, and nothing is stored. Below that it uses the stored time plus one and logs a warning, as before. I moved the 30s default into ServerManager.DEFAULT_MAX_CLOCK_SKEW_MS so both checks use the same value.

One consequence worth knowing: if a master's clock was ever far ahead, the time it stored stays ahead, so later masters with correct clocks will refuse to start until the wall clock passes it. That seems in line with exposing the problem, but let me know if you'd want a way around it.

@charlesconnell charlesconnell left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Let me know if/when you would like me to merge this.

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.

3 participants