-
Notifications
You must be signed in to change notification settings - Fork 610
[server] Support DescribeTabletServers API for safe scaling and upgrades #3743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
morazow
wants to merge
3
commits into
apache:main
Choose a base branch
from
morazow:describe-tablet-servers-3570
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
158 changes: 158 additions & 0 deletions
158
fluss-client/src/main/java/org/apache/fluss/client/admin/TabletServerDescription.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.fluss.client.admin; | ||
|
|
||
| import org.apache.fluss.annotation.PublicEvolving; | ||
| import org.apache.fluss.cluster.rebalance.ServerTag; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * Per tablet server replica load returned by {@link Admin#describeTabletServers()}. | ||
| * | ||
| * <p>It reports the replica counters of a single tablet server: how many replicas it hosts, how | ||
| * many of those are in sync, how many buckets it leads, and how many of those leaders are active. | ||
| * The {@link ClusterHealth} aggregates the same counters across all tablet servers. | ||
| * | ||
| * <p>Operational tooling can derive from it: | ||
| * | ||
| * <ul> | ||
| * <li>a scale-in safety gate: the server is empty and safe to remove iff {@code numReplicas == | ||
| * 0}; | ||
| * <li>a per-server health (green) predicate for rolling upgrades: {@code inSyncReplicas == | ||
| * numReplicas && activeLeaderReplicas == numLeaderReplicas}. | ||
| * </ul> | ||
| * | ||
| * <p>Note: a bucket without an elected leader is attributed to no server's {@code | ||
| * numLeaderReplicas}, so the per-server values sum to the cluster-wide {@link | ||
| * ClusterHealth#getNumLeaderReplicas()} only when every bucket has an elected leader. Such a bucket | ||
| * does not always surface through {@code inSyncReplicas < numReplicas}: when the last ISR member | ||
| * goes offline, it is kept in the ISR so that a leader can be re-elected later, and the assigned | ||
| * servers still look green by the predicate above. A rolling-upgrade gate should therefore | ||
| * additionally require {@link Admin#getClusterHealth()} to not report {@link | ||
| * ClusterHealthStatus#RED}, which counts leaderless buckets unconditionally. | ||
| * | ||
| * @since 1.0 | ||
| */ | ||
| @PublicEvolving | ||
| public final class TabletServerDescription { | ||
|
|
||
| private final int serverId; | ||
| private final int numReplicas; | ||
| private final int inSyncReplicas; | ||
| private final int numLeaderReplicas; | ||
| private final int activeLeaderReplicas; | ||
| private final @Nullable ServerTag serverTag; | ||
|
|
||
| public TabletServerDescription( | ||
| int serverId, | ||
| int numReplicas, | ||
| int inSyncReplicas, | ||
| int numLeaderReplicas, | ||
| int activeLeaderReplicas, | ||
| @Nullable ServerTag serverTag) { | ||
| this.serverId = serverId; | ||
| this.numReplicas = numReplicas; | ||
| this.inSyncReplicas = inSyncReplicas; | ||
| this.numLeaderReplicas = numLeaderReplicas; | ||
| this.activeLeaderReplicas = activeLeaderReplicas; | ||
| this.serverTag = serverTag; | ||
| } | ||
|
|
||
| public int getServerId() { | ||
| return serverId; | ||
| } | ||
|
|
||
| /** Number of replicas assigned to this tablet server. */ | ||
| public int getNumReplicas() { | ||
| return numReplicas; | ||
| } | ||
|
|
||
| /** Number of assigned replicas that are in the ISR of their bucket. */ | ||
| public int getInSyncReplicas() { | ||
| return inSyncReplicas; | ||
| } | ||
|
|
||
| /** Number of hosted replicas that are the elected leader of their bucket. */ | ||
| public int getNumLeaderReplicas() { | ||
| return numLeaderReplicas; | ||
| } | ||
|
|
||
| /** Number of leader replicas on this server that are currently active. */ | ||
| public int getActiveLeaderReplicas() { | ||
| return activeLeaderReplicas; | ||
| } | ||
|
|
||
| /** | ||
| * The {@link ServerTag} set on this server via {@link Admin#addServerTag}, or empty if the | ||
| * server is untagged. A tagged server is being drained, so it is reported even when it is dead | ||
| * and hosts no replicas. | ||
| */ | ||
| public Optional<ServerTag> getServerTag() { | ||
| return Optional.ofNullable(serverTag); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (!(o instanceof TabletServerDescription)) { | ||
| return false; | ||
| } | ||
| TabletServerDescription that = (TabletServerDescription) o; | ||
| return serverId == that.serverId | ||
| && numReplicas == that.numReplicas | ||
| && inSyncReplicas == that.inSyncReplicas | ||
| && numLeaderReplicas == that.numLeaderReplicas | ||
| && activeLeaderReplicas == that.activeLeaderReplicas | ||
| && serverTag == that.serverTag; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash( | ||
| serverId, | ||
| numReplicas, | ||
| inSyncReplicas, | ||
| numLeaderReplicas, | ||
| activeLeaderReplicas, | ||
| serverTag); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "TabletServerDescription{" | ||
| + "serverId=" | ||
| + serverId | ||
| + ", numReplicas=" | ||
| + numReplicas | ||
| + ", inSyncReplicas=" | ||
| + inSyncReplicas | ||
| + ", numLeaderReplicas=" | ||
| + numLeaderReplicas | ||
| + ", activeLeaderReplicas=" | ||
| + activeLeaderReplicas | ||
| + ", serverTag=" | ||
| + serverTag | ||
| + '}'; | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A leaderless bucket is counted by cluster health but by no server here, so these sums can differ while every server still looks green. The waitUntil above doesn't rule that out. testPerServerSumsReconcileWithClusterHealth already covers this.
Do we need it?