Skip to content

[da-vinci] Invalidate stale demotions before going offline - #2973

Open
sofiaz11 wants to merge 2 commits into
linkedin:mainfrom
sofiaz11:qizhu-linkedin-fix-stale-sit-demotion
Open

[da-vinci] Invalidate stale demotions before going offline#2973
sofiaz11 wants to merge 2 commits into
linkedin:mainfrom
sofiaz11:qizhu-linkedin-fix-stale-sit-demotion

Conversation

@sofiaz11

Copy link
Copy Markdown
Contributor

Problem Statement

Asynchronous replica cleanup can advance a replica to OFFLINE while an earlier LEADER_TO_STANDBY action remains queued. If that delayed demotion runs afterward, it can modify ingestion state and restore follower heartbeat monitoring for an offline replica.

Solution

Invalidate the leader-session token when the STANDBY to OFFLINE transition begins. The existing consumer-action validation then rejects any queued stale demotion before it modifies ingestion state or heartbeat monitoring.

Code changes

  • Added new code behind a config. If so list the config names and their default values in the PR description.
  • Introduced new log lines.
    • Confirmed if logs need to be rate limited to avoid excessive logging.

No configuration or logging changes are introduced.

Concurrency-Specific Checks

Both reviewer and PR author to verify

  • Code has no race conditions or thread safety issues.
  • Proper synchronization mechanisms (e.g., synchronized, RWLock) are used where needed.
  • No blocking calls inside critical sections that could lead to deadlocks or performance degradation.
  • Verified thread-safe collections are used (e.g., ConcurrentHashMap, CopyOnWriteArrayList).
  • Validated proper exception handling in multi-threaded code to avoid silent thread termination.

The existing atomic leader-session generation provides the cross-thread validity check. This change introduces no collections, blocking calls, or exception-handling changes.

How was this PR tested?

  • New unit tests added.
  • New integration tests added.
  • Modified or extended existing tests.
  • Verified backward compatibility (if applicable).
./gradlew --no-daemon :clients:da-vinci-client:test --tests 'com.linkedin.davinci.helix.LeaderFollowerPartitionStateModelTest.testOfflineTransitionInvalidatesDelayedLeaderToStandbyAction'

The focused regression test verifies that the delayed demotion token becomes invalid and no later SET_FOLLOWER_MONITOR update occurs.

Does this PR introduce any user-facing or breaking changes?

  • No. You can skip the rest of this section.
  • Yes. Clearly explain the behavior change and its impact.

This contribution is original work and is licensed to the project under its open source license.

🤖 Generated with GitHub Copilot CLI

Copilot AI lite review requested due to automatic review settings August 13, 2026 00:14

Copilot AI 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.

Pull request overview

This PR prevents a stale queued LEADER_TO_STANDBY consumer action from applying after a replica has already begun transitioning STANDBY -> OFFLINE, by invalidating the leader-session token at the start of the OFFLINE transition so later-processed demotions are rejected by the existing session-id validation in ingestion-task consumer-action processing.

Changes:

  • Increment leaderSessionId at the beginning of onBecomeOfflineFromStandby(...) to invalidate any previously queued demotion actions.
  • Add a unit test asserting the demotion’s session checker becomes invalid once the OFFLINE transition begins.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
clients/da-vinci-client/src/main/java/com/linkedin/davinci/helix/LeaderFollowerPartitionStateModel.java Invalidates the leader-session token when starting STANDBY -> OFFLINE to reject stale queued demotions.
clients/da-vinci-client/src/test/java/com/linkedin/davinci/helix/LeaderFollowerPartitionStateModelTest.java Adds a regression test intended to cover delayed demotion invalidation during OFFLINE transition.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +161 to +184
@Test
public void testOfflineTransitionInvalidatesDelayedLeaderToStandbyAction() {
Message message = mock(Message.class);
NotificationContext context = mock(NotificationContext.class);
when(message.getResourceName()).thenReturn(resourceName);
LeaderSessionIdChecker[] demotionChecker = new LeaderSessionIdChecker[1];
doAnswer(invocation -> {
demotionChecker[0] = invocation.getArgument(2);
return null;
}).when(storeIngestionService).demoteToStandby(eq(storeAndServerConfigs), eq(partition), any());

leaderFollowerPartitionStateModel.onBecomeStandbyFromLeader(message, context);
assertNotNull(demotionChecker[0]);
assertTrue(demotionChecker[0].isSessionIdValid());

leaderFollowerPartitionStateModel.onBecomeOfflineFromStandby(message, context);

assertFalse(demotionChecker[0].isSessionIdValid());
verify(heartbeatMonitoringService, never()).updateLagMonitor(
eq(resourceName),
eq(partition),
eq(HeartbeatLagMonitorAction.SET_FOLLOWER_MONITOR),
anyString());
}
Copilot AI review requested due to automatic review settings August 13, 2026 17:35

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@sofiaz11
sofiaz11 force-pushed the qizhu-linkedin-fix-stale-sit-demotion branch from 5a9aca0 to eef7531 Compare August 13, 2026 18:10
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