Skip to content

Gate leader task assignment behind a dynamic ZooKeeper flag - #1044

Merged
manishGoyalCode merged 3 commits into
linkedin:masterfrom
manishGoyalCode:manish/zk-flag-gated-assignment
Jul 15, 2026
Merged

Gate leader task assignment behind a dynamic ZooKeeper flag#1044
manishGoyalCode merged 3 commits into
linkedin:masterfrom
manishGoyalCode:manish/zk-flag-gated-assignment

Conversation

@manishGoyalCode

@manishGoyalCode manishGoyalCode commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Gate leader task assignment behind a dynamic ZooKeeper flag

Summary

Adds a dynamic ZooKeeper-backed kill-switch for datastream task assignment. The leader Coordinator now consults a /{cluster}/assignmentEnabled znode before performing assignment, allowing operators to pause/resume assignment at runtime without a redeploy or restart.

Motivation

During incidents or maintenance, we sometimes need to temporarily stop the leader from (re)assigning datastream tasks. Previously this required code/config changes and a restart. This change introduces a runtime toggle controlled purely via ZooKeeper.

Behavior

The flag at /{cluster}/assignmentEnabled is interpreted as:

Znode state Assignment
Absent (default) Enabled
Value "false" (case-insensitive) Disabled
Empty / null value Enabled
Any other value (e.g. "true", "yes") Enabled

When assignment is disabled, the leader does not block the Coordinator event thread. Instead, handleLeaderDoAssignment skips the current cycle and reschedules a LEADER_DO_ASSIGNMENT event after the configured check period (default 5s). This keeps the Coordinator event loop responsive (heartbeats, partition operations, the leader's own assignment changes, and graceful shutdown) while assignment is paused. Assignment resumes automatically once the flag is re-enabled or the znode is deleted; the rescheduled event is a no-op if the instance is no longer the leader, so leadership loss and shutdown naturally stop the re-check loop.

Changes

Production code

  • KeyBuilder.java — New assignmentEnabled(String cluster) helper returning the /{cluster}/assignmentEnabled znode path, with Javadoc describing the flag semantics.
  • ZkAdapter.java — New isAssignmentEnabled() method that reads the flag from ZooKeeper. Defaults to enabled; treats only a case-insensitive "false" as disabled. Safely handles the znode being deleted between the exists() check and read (returnNullIfPathNotExists=true).
  • Coordinator.javahandleLeaderDoAssignment checks isAssignmentEnabled() at the top; if assignment is disabled it logs, reschedules a LEADER_DO_ASSIGNMENT event via _scheduledExecutor after the configured check period (new scheduleLeaderDoAssignmentWhenReEnabled(...) helper), and returns immediately instead of blocking. The scheduler is guarded so it does not pile up redundant futures.
  • CoordinatorConfig.java — New config brooklin.server.coordinator.assignmentEnabledCheckPeriodMs (default 5000 ms) controlling the re-check interval, with getter getAssignmentEnabledCheckPeriodMs().

Tests

  • TestZkAdapter.javatestIsAssignmentEnabled() covering: absent znode (enabled), "false"/"FALSE" (disabled), "true" (enabled), unrecognized value (enabled), empty value (enabled), and znode deletion restoring the default.
  • TestCoordinatorConfig.javatestAssignmentEnabledCheckPeriodConfig() validating the default (5s) and an override.

Operational usage

  • Disable assignment: create/set /{cluster}/assignmentEnabled to false.
  • Re-enable assignment: set the value to anything else (e.g. true) or delete the znode.

Testing Done

  • Added unit tests for ZkAdapter.isAssignmentEnabled() (all flag states) and the new CoordinatorConfig property (default + override).
  • mint build / mint test on datastream-server.

Risk / Compatibility

Low risk and backward compatible — the flag defaults to enabled when the znode is absent, so existing clusters behave exactly as before until an operator explicitly sets the flag.

Add a dynamic ZooKeeper-backed kill-switch for datastream task
assignment. The leader Coordinator now checks the /{cluster}/assignmentEnabled
znode before performing assignment:
- Absent znode  -> assignment enabled (default)
- Value "false" -> assignment disabled
- Any other value / empty -> assignment enabled
When disabled, the leader blocks in handleLeaderDoAssignment and
re-checks the flag every 5s (configurable via
brooklin.server.coordinator.assignmentEnabledCheckPeriodMs) until it is
re-enabled or the znode is deleted.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@manishGoyalCode
manishGoyalCode marked this pull request as ready for review July 9, 2026 13:46
readData(path, true) already returns null for an absent znode (it catches
ZkNoNodeException internally), so the preceding exists() call was an extra
ZooKeeper round-trip on every assignment. Collapse to a single read.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
_log.warn("Datastream task assignment is disabled via the ZooKeeper assignment-enabled flag. "
+ "Skipping assignment and re-checking in {} ms.", _config.getAssignmentEnabledCheckPeriodMs());
try {
Thread.sleep(_config.getAssignmentEnabledCheckPeriodMs());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

since we are blocking this thread here, this will block the entire CoordinatorEventProcessor thread.
Are there any other important tasks that can be blocked due to this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it is intentional . we want to stop everything. as this will be for small time and we want to stop all operations of the cluster itself.

harshOSS
harshOSS previously approved these changes Jul 14, 2026

@kanishkjaiswal2015 kanishkjaiswal2015 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@manishGoyalCode
manishGoyalCode merged commit bdff09a into linkedin:master Jul 15, 2026
1 check passed
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