Gate leader task assignment behind a dynamic ZooKeeper flag#1044
Open
manishGoyalCode wants to merge 2 commits into
Open
Gate leader task assignment behind a dynamic ZooKeeper flag#1044manishGoyalCode wants to merge 2 commits into
manishGoyalCode wants to merge 2 commits into
Conversation
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>
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>
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.
Gate leader task assignment behind a dynamic ZooKeeper flag
Summary
Adds a dynamic ZooKeeper-backed kill-switch for datastream task assignment. The leader
Coordinatornow consults a/{cluster}/assignmentEnabledznode 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}/assignmentEnabledis interpreted as:"false"(case-insensitive)"true","yes")When assignment is disabled, the leader blocks inside
handleLeaderDoAssignmentand re-checks the flag every 5s (configurable). It resumes automatically once the flag is re-enabled, the znode is deleted, the instance loses leadership, or the thread is interrupted.Changes
Production code
KeyBuilder.java— NewassignmentEnabled(String cluster)helper returning the/{cluster}/assignmentEnabledznode path, with Javadoc describing the flag semantics.ZkAdapter.java— NewisAssignmentEnabled()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 theexists()check and read (returnNullIfPathNotExists=true).Coordinator.java— AddedblockUntilAssignmentEnabled(), invoked at the start ofhandleLeaderDoAssignment. It loops while the instance is leader and assignment is disabled, sleeping for the configured check period between checks, and logs when assignment is paused and resumed.CoordinatorConfig.java— New configbrooklin.server.coordinator.assignmentEnabledCheckPeriodMs(default 5000 ms) controlling the re-check interval, with gettergetAssignmentEnabledCheckPeriodMs().Tests
TestZkAdapter.java—testIsAssignmentEnabled()covering: absent znode (enabled),"false"/"FALSE"(disabled),"true"(enabled), unrecognized value (enabled), empty value (enabled), and znode deletion restoring the default.TestCoordinatorConfig.java—testAssignmentEnabledCheckPeriodConfig()validating the default (5s) and an override.Operational usage
/{cluster}/assignmentEnabledtofalse.true) or delete the znode.Testing Done
ZkAdapter.isAssignmentEnabled()(all flag states) and the newCoordinatorConfigproperty (default + override).mint build/mint testondatastream-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.