|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.fluss.client.admin; |
| 19 | + |
| 20 | +import org.apache.fluss.annotation.PublicEvolving; |
| 21 | + |
| 22 | +import java.util.Objects; |
| 23 | + |
| 24 | +/** |
| 25 | + * Per tablet server replica load returned by {@link Admin#describeTabletServers()}. |
| 26 | + * |
| 27 | + * <p>It reports the replica counters of a single tablet server: how many replicas it hosts, how |
| 28 | + * many of those are in sync, how many buckets it leads, and how many of those leaders are active. |
| 29 | + * The {@link ClusterHealth} aggregates the same counters across all tablet servers. |
| 30 | + * |
| 31 | + * <p>Operational tooling can derive from it: |
| 32 | + * |
| 33 | + * <ul> |
| 34 | + * <li>a scale-in safety gate: the server is empty and safe to remove iff {@code numReplicas == |
| 35 | + * 0}; |
| 36 | + * <li>a per-server health (green) predicate for rolling upgrades: {@code inSyncReplicas == |
| 37 | + * numReplicas && activeLeaderReplicas == numLeaderReplicas}. |
| 38 | + * </ul> |
| 39 | + * |
| 40 | + * <p>Note: a bucket without an elected leader is attributed to no server's {@code |
| 41 | + * numLeaderReplicas}, so the per-server values sum to the cluster-wide {@link |
| 42 | + * ClusterHealth#getNumLeaderReplicas()} only when every bucket has an elected leader. Such buckets |
| 43 | + * still surface through {@code inSyncReplicas < numReplicas} on the assigned servers. |
| 44 | + * |
| 45 | + * @since 1.0 |
| 46 | + */ |
| 47 | +@PublicEvolving |
| 48 | +public final class TabletServerDescription { |
| 49 | + |
| 50 | + private final int serverId; |
| 51 | + private final int numReplicas; |
| 52 | + private final int inSyncReplicas; |
| 53 | + private final int numLeaderReplicas; |
| 54 | + private final int activeLeaderReplicas; |
| 55 | + |
| 56 | + public TabletServerDescription( |
| 57 | + int serverId, |
| 58 | + int numReplicas, |
| 59 | + int inSyncReplicas, |
| 60 | + int numLeaderReplicas, |
| 61 | + int activeLeaderReplicas) { |
| 62 | + this.serverId = serverId; |
| 63 | + this.numReplicas = numReplicas; |
| 64 | + this.inSyncReplicas = inSyncReplicas; |
| 65 | + this.numLeaderReplicas = numLeaderReplicas; |
| 66 | + this.activeLeaderReplicas = activeLeaderReplicas; |
| 67 | + } |
| 68 | + |
| 69 | + public int getServerId() { |
| 70 | + return serverId; |
| 71 | + } |
| 72 | + |
| 73 | + /** Number of replicas assigned to this tablet server. */ |
| 74 | + public int getNumReplicas() { |
| 75 | + return numReplicas; |
| 76 | + } |
| 77 | + |
| 78 | + /** Number of assigned replicas that are in the ISR of their bucket. */ |
| 79 | + public int getInSyncReplicas() { |
| 80 | + return inSyncReplicas; |
| 81 | + } |
| 82 | + |
| 83 | + /** Number of hosted replicas that are the elected leader of their bucket. */ |
| 84 | + public int getNumLeaderReplicas() { |
| 85 | + return numLeaderReplicas; |
| 86 | + } |
| 87 | + |
| 88 | + /** Number of leader replicas on this server that are currently active. */ |
| 89 | + public int getActiveLeaderReplicas() { |
| 90 | + return activeLeaderReplicas; |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public boolean equals(Object o) { |
| 95 | + if (this == o) { |
| 96 | + return true; |
| 97 | + } |
| 98 | + if (!(o instanceof TabletServerDescription)) { |
| 99 | + return false; |
| 100 | + } |
| 101 | + TabletServerDescription that = (TabletServerDescription) o; |
| 102 | + return serverId == that.serverId |
| 103 | + && numReplicas == that.numReplicas |
| 104 | + && inSyncReplicas == that.inSyncReplicas |
| 105 | + && numLeaderReplicas == that.numLeaderReplicas |
| 106 | + && activeLeaderReplicas == that.activeLeaderReplicas; |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public int hashCode() { |
| 111 | + return Objects.hash( |
| 112 | + serverId, numReplicas, inSyncReplicas, numLeaderReplicas, activeLeaderReplicas); |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public String toString() { |
| 117 | + return "TabletServerDescription{" |
| 118 | + + "serverId=" |
| 119 | + + serverId |
| 120 | + + ", numReplicas=" |
| 121 | + + numReplicas |
| 122 | + + ", inSyncReplicas=" |
| 123 | + + inSyncReplicas |
| 124 | + + ", numLeaderReplicas=" |
| 125 | + + numLeaderReplicas |
| 126 | + + ", activeLeaderReplicas=" |
| 127 | + + activeLeaderReplicas |
| 128 | + + '}'; |
| 129 | + } |
| 130 | +} |
0 commit comments