From f45fe9ade72c0eb5a6ab121e0cfff03fac3126f1 Mon Sep 17 00:00:00 2001 From: niuyulin Date: Thu, 3 Jun 2021 15:10:41 +0800 Subject: [PATCH] HBASE-25950 add basic compaction server metric --- .../hadoop/hbase/CompactionServerMetrics.java | 63 +++++ .../hbase/CompactionServerMetricsBuilder.java | 231 ++++++++++++++++++ .../main/protobuf/server/ClusterStatus.proto | 29 +++ .../server/CompactionServerStatus.proto | 2 + .../master/CompactionServerListTmpl.jamon | 69 ++++-- .../hbase/master/MasterRpcServices.java | 7 +- .../compaction/CompactionOffloadManager.java | 19 +- 7 files changed, 398 insertions(+), 22 deletions(-) create mode 100644 hbase-client/src/main/java/org/apache/hadoop/hbase/CompactionServerMetrics.java create mode 100644 hbase-client/src/main/java/org/apache/hadoop/hbase/CompactionServerMetricsBuilder.java diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/CompactionServerMetrics.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/CompactionServerMetrics.java new file mode 100644 index 000000000000..9a454b8c93d1 --- /dev/null +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/CompactionServerMetrics.java @@ -0,0 +1,63 @@ +/** + * Copyright The Apache Software Foundation + * 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.hadoop.hbase; + +import java.util.List; +import org.apache.yetus.audience.InterfaceAudience; + +/** + * This class is used for exporting current state of load on a CompactionServer. + */ +@InterfaceAudience.Public +public interface CompactionServerMetrics { + + ServerName getServerName(); + + /** + * @return the version number of a compaction server. + */ + default int getVersionNumber() { + return 0; + } + /** + * @return the string type version of a compaction server. + */ + default String getVersion() { + return "0.0.0"; + } + + int getInfoServerPort(); + + long getCompactingCellCount(); + + long getCompactedCellCount(); + + List getCompactionTasks(); + + long getTotalNumberOfRequests(); + /** + * @return the timestamp (server side) of generating this metrics + */ + long getReportTimestamp(); + + /** + * @return the last timestamp (server side) of generating this metrics + */ + long getLastReportTimestamp(); + +} diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/CompactionServerMetricsBuilder.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/CompactionServerMetricsBuilder.java new file mode 100644 index 000000000000..c1e057c0d50a --- /dev/null +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/CompactionServerMetricsBuilder.java @@ -0,0 +1,231 @@ +/** + * Copyright The Apache Software Foundation + * 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.hadoop.hbase; + +import edu.umd.cs.findbugs.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import org.apache.hadoop.hbase.util.Strings; +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.hbase.thirdparty.com.google.common.base.Preconditions; +import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos; + + +@InterfaceAudience.Private +public final class CompactionServerMetricsBuilder { + + /** + * @param sn the server name + * @return a empty metrics + */ + public static CompactionServerMetrics of(ServerName sn) { + return newBuilder(sn).build(); + } + + public static CompactionServerMetrics of(ServerName sn, int versionNumber, String version) { + return newBuilder(sn).setVersionNumber(versionNumber).setVersion(version).build(); + } + + public static CompactionServerMetrics toCompactionServerMetrics(ServerName serverName, + ClusterStatusProtos.CompactionServerLoad serverLoadPB) { + return toCompactionServerMetrics(serverName, 0, "0.0.0", serverLoadPB); + } + + public static CompactionServerMetrics toCompactionServerMetrics(ServerName serverName, + int versionNumber, String version, ClusterStatusProtos.CompactionServerLoad serverLoadPB) { + return CompactionServerMetricsBuilder.newBuilder(serverName) + .setInfoServerPort(serverLoadPB.getInfoServerPort()) + .setCompactedCellCount(serverLoadPB.getCompactedCells()) + .setCompactingCellCount(serverLoadPB.getCompactingCells()) + .addCompactionTasks(serverLoadPB.getCompactionTasksList()) + .setTotalNumberOfRequests(serverLoadPB.getTotalNumberOfRequests()) + .setLastReportTimestamp(serverLoadPB.getReportStartTime()).setVersionNumber(versionNumber) + .setVersion(version).build(); + } + + public static CompactionServerMetricsBuilder newBuilder(ServerName sn) { + return new CompactionServerMetricsBuilder(sn); + } + + private final ServerName serverName; + private int versionNumber; + private String version = "0.0.0"; + private int infoServerPort; + private long compactingCellCount; + private long compactedCellCount; + private long totalNumberOfRequests; + @Nullable + private List compactionTasks = new ArrayList<>(); + private long reportTimestamp = System.currentTimeMillis(); + private long lastReportTimestamp = 0; + private CompactionServerMetricsBuilder(ServerName serverName) { + this.serverName = serverName; + } + + public CompactionServerMetricsBuilder setVersionNumber(int versionNumber) { + this.versionNumber = versionNumber; + return this; + } + + public CompactionServerMetricsBuilder setVersion(String version) { + this.version = version; + return this; + } + + + public CompactionServerMetricsBuilder addCompactionTasks(List compactionTasks) { + this.compactionTasks.addAll(compactionTasks); + return this; + } + + public CompactionServerMetricsBuilder setTotalNumberOfRequests(long totalNumberOfRequests) { + this.totalNumberOfRequests = totalNumberOfRequests; + return this; + } + + public CompactionServerMetricsBuilder setInfoServerPort(int value) { + this.infoServerPort = value; + return this; + } + + + public CompactionServerMetricsBuilder setCompactingCellCount(long value) { + this.compactingCellCount = value; + return this; + } + + public CompactionServerMetricsBuilder setCompactedCellCount(long value) { + this.compactedCellCount = value; + return this; + } + + public CompactionServerMetricsBuilder setReportTimestamp(long value) { + this.reportTimestamp = value; + return this; + } + + public CompactionServerMetricsBuilder setLastReportTimestamp(long value) { + this.lastReportTimestamp = value; + return this; + } + + public CompactionServerMetrics build() { + return new CompactionServerMetricsImpl( + serverName, + versionNumber, + version, + infoServerPort, + compactingCellCount, + compactedCellCount, + compactionTasks, + totalNumberOfRequests, + reportTimestamp, + lastReportTimestamp); + } + + private static class CompactionServerMetricsImpl implements CompactionServerMetrics { + private final ServerName serverName; + private final int versionNumber; + private final String version; + private final int infoServerPort; + private final long compactingCellCount; + private final long compactedCellCount; + private final List compactionTasks = new ArrayList<>(); + private final long totalNumberOfRequests; + @Nullable + private final long reportTimestamp; + private final long lastReportTimestamp; + + CompactionServerMetricsImpl(ServerName serverName, int versionNumber, String version, + int infoServerPort, long compactingCellCount, long compactedCellCount, + List compactionTasks, long totalNumberOfRequests, long reportTimestamp, + long lastReportTimestamp) { + this.serverName = Preconditions.checkNotNull(serverName); + this.versionNumber = versionNumber; + this.version = version; + this.infoServerPort = infoServerPort; + this.compactingCellCount = compactingCellCount; + this.compactedCellCount = compactedCellCount; + this.totalNumberOfRequests = totalNumberOfRequests; + this.reportTimestamp = reportTimestamp; + this.lastReportTimestamp = lastReportTimestamp; + this.compactionTasks.addAll(compactionTasks); + } + + @Override + public ServerName getServerName() { + return serverName; + } + + @Override + public int getVersionNumber() { + return versionNumber; + } + + public String getVersion() { + return version; + } + + public long getCompactingCellCount() { + return compactingCellCount; + } + + public long getCompactedCellCount() { + return compactedCellCount; + } + + public List getCompactionTasks() { + return compactionTasks; + } + + public long getTotalNumberOfRequests() { + return totalNumberOfRequests; + } + + @Override + public int getInfoServerPort() { + return infoServerPort; + } + + @Override + public long getReportTimestamp() { + return reportTimestamp; + } + + @Override + public long getLastReportTimestamp() { + return lastReportTimestamp; + } + + @Override + public String toString() { + StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "totalCompactingKVs", + Double.valueOf(compactingCellCount)); + Strings.appendKeyValue(sb, "currentCompactedKVs", compactedCellCount); + float compactionProgressPct = Float.NaN; + if (compactingCellCount > 0) { + compactionProgressPct = Float.valueOf((float) compactedCellCount / compactingCellCount); + } + Strings.appendKeyValue(sb, "compactionProgressPct", compactionProgressPct); + Strings.appendKeyValue(sb, "compactionTaskNum", compactionTasks.size()); + Strings.appendKeyValue(sb, "totalNumberOfRequests", totalNumberOfRequests); + return sb.toString(); + } + } +} diff --git a/hbase-protocol-shaded/src/main/protobuf/server/ClusterStatus.proto b/hbase-protocol-shaded/src/main/protobuf/server/ClusterStatus.proto index dc875daf7976..c232aef98f18 100644 --- a/hbase-protocol-shaded/src/main/protobuf/server/ClusterStatus.proto +++ b/hbase-protocol-shaded/src/main/protobuf/server/ClusterStatus.proto @@ -287,6 +287,35 @@ message ServerLoad { repeated UserLoad userLoads = 12; } +message CompactionServerLoad { + required int64 compacting_cells = 1; + required int64 compacted_cells = 2; + repeated string compaction_tasks = 3; + + /** Total Number of requests from the start of the compaction server. */ + optional uint64 total_number_of_requests = 4; + + /** + * Time when incremental (non-total) counts began being calculated (e.g. number_of_requests) + * time is measured as the difference, measured in milliseconds, between the current time + * and midnight, January 1, 1970 UTC. + */ + optional uint64 report_start_time = 5; + + /** + * Time when report was generated. + * time is measured as the difference, measured in milliseconds, between the current time + * and midnight, January 1, 1970 UTC. + */ + optional uint64 report_end_time = 6; + + /** + * The port number that this compaction server is hosing an info server on. + */ + optional uint32 info_server_port = 7; + +} + message LiveServerInfo { required ServerName server = 1; required ServerLoad server_load = 2; diff --git a/hbase-protocol-shaded/src/main/protobuf/server/CompactionServerStatus.proto b/hbase-protocol-shaded/src/main/protobuf/server/CompactionServerStatus.proto index 0d45f317de52..990f36c4052a 100644 --- a/hbase-protocol-shaded/src/main/protobuf/server/CompactionServerStatus.proto +++ b/hbase-protocol-shaded/src/main/protobuf/server/CompactionServerStatus.proto @@ -32,6 +32,8 @@ import "server/ErrorHandling.proto"; message CompactionServerReportRequest { required ServerName server = 1; + /** load the server is under */ + optional CompactionServerLoad load = 2; } message CompactionServerReportResponse { diff --git a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/CompactionServerListTmpl.jamon b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/CompactionServerListTmpl.jamon index c94e68f106af..995d2babc76d 100644 --- a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/CompactionServerListTmpl.jamon +++ b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/CompactionServerListTmpl.jamon @@ -27,9 +27,7 @@ HMaster master; java.util.*; org.apache.hadoop.hbase.master.HMaster; org.apache.hadoop.hbase.procedure2.util.StringUtils; - org.apache.hadoop.hbase.replication.ReplicationLoadSource; - org.apache.hadoop.hbase.RegionMetrics; - org.apache.hadoop.hbase.ServerMetrics; + org.apache.hadoop.hbase.CompactionServerMetrics; org.apache.hadoop.hbase.ServerName; org.apache.hadoop.hbase.Size; org.apache.hadoop.hbase.util.VersionInfo; @@ -47,11 +45,15 @@ Arrays.sort(serverNames);
<& baseStats; serverNames = serverNames; &>
+
+ <& compactionStats; serverNames = serverNames; &> +
@@ -72,27 +74,18 @@ Arrays.sort(serverNames); <%java> - int totalRegions = 0; - int totalRequestsPerSecond = 0; int inconsistentNodeNum = 0; String masterVersion = VersionInfo.getVersion(); - for (ServerName serverName: serverNames) { - ServerMetrics sl = master.getServerManager().getLoad(serverName); + for (ServerName serverName: serverNames) { + CompactionServerMetrics sl = master.getCompactionOffloadManager().getLoad(serverName); String version = master.getCompactionServerVersion(serverName); if (!masterVersion.equals(version)) { inconsistentNodeNum ++; } - double requestsPerSecond = 0.0; - int numRegionsOnline = 0; long lastContact = 0; - if (sl != null) { - requestsPerSecond = sl.getRequestCountPerSecond(); - numRegionsOnline = sl.getRegionMetrics().size(); - totalRegions += sl.getRegionMetrics().size(); - totalRequestsPerSecond += sl.getRequestCountPerSecond(); lastContact = (System.currentTimeMillis() - sl.getReportTimestamp())/1000; } long startcode = serverName.getStartcode(); @@ -120,6 +113,54 @@ Arrays.sort(serverNames); +<%def compactionStats> +<%args> + ServerName [] serverNames; + + + + + + + + + + + + +<%java> +for (ServerName serverName: serverNames) { + +CompactionServerMetrics sl = master.getCompactionOffloadManager().getLoad(serverName); +if (sl != null) { +long totalCompactingCells = sl.getCompactingCellCount(); +long totalCompactedCells = sl.getCompactedCellCount(); +long compactionTaskNum = sl.getCompactionTasks().size(); +String percentDone = ""; +if (totalCompactingCells > 0) { + percentDone = String.format("%.2f", 100 * + ((float) totalCompactedCells / totalCompactingCells)) + "%"; +} + + + + + + + + +<%java> + } else { + +<& emptyStat; serverName=serverName; &> +<%java> + } +} + + +
ServerNameNum. Compacting CellsNum. Compacted CellsCompaction ProgressNum. Compaction Tasks
<& serverNameLink; serverName=serverName; &><% String.format("%,d", totalCompactingCells) %><% String.format("%,d", totalCompactedCells) %><% percentDone %><% String.format("%,d", compactionTaskNum) %>
+ + <%def serverNameLink> <%args> ServerName serverName; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java index a74458845a17..bcf5e76a4eba 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java @@ -39,6 +39,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.ClusterMetricsBuilder; +import org.apache.hadoop.hbase.CompactionServerMetrics; +import org.apache.hadoop.hbase.CompactionServerMetricsBuilder; import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -670,8 +672,9 @@ public CompactionServerReportResponse compactionServerReport(RpcController contr versionNumber = VersionInfoUtil.getVersionNumber(versionInfo); } ServerName serverName = ProtobufUtil.toServerName(request.getServer()); - ServerMetrics newLoad = ServerMetricsBuilder.toServerMetrics(serverName, versionNumber, - version, ClusterStatusProtos.ServerLoad.newBuilder().build()); + CompactionServerMetrics newLoad = + CompactionServerMetricsBuilder.toCompactionServerMetrics(serverName, versionNumber, + version, request.getLoad()); master.getCompactionOffloadManager().compactionServerReport(serverName, newLoad); } catch (IOException ioe) { throw new ServiceException(ioe); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/compaction/CompactionOffloadManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/compaction/CompactionOffloadManager.java index 9ea8e213684f..03f6829ea99f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/compaction/CompactionOffloadManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/compaction/CompactionOffloadManager.java @@ -24,8 +24,8 @@ import java.util.Map; import java.util.concurrent.TimeUnit; +import org.apache.hadoop.hbase.CompactionServerMetrics; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.ServerMetrics; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch; @@ -47,7 +47,7 @@ public class CompactionOffloadManager { private final MasterServices masterServices; /** Map of registered servers to their current load */ - private final Cache onlineServers; + private final Cache onlineServers; private CompactionOffloadSwitchStorage compactionOffloadSwitchStorage; private static final Logger LOG = LoggerFactory.getLogger(CompactionOffloadManager.class.getName()); @@ -64,7 +64,7 @@ public CompactionOffloadManager(final MasterServices master) { masterServices.getZooKeeper(), masterServices.getConfiguration()); } - public void compactionServerReport(ServerName sn, ServerMetrics sl) { + public void compactionServerReport(ServerName sn, CompactionServerMetrics sl) { this.onlineServers.put(sn, sl); } @@ -78,7 +78,7 @@ public List getOnlineServersList() { /** * @return Read-only map of servers to serverinfo */ - public Map getOnlineServers() { + public Map getOnlineServers() { return Collections.unmodifiableMap(this.onlineServers.asMap()); } @@ -86,15 +86,22 @@ public Map getOnlineServers() { * May return "0.0.0" when server is not online */ public String getVersion(ServerName serverName) { - ServerMetrics serverMetrics = onlineServers.asMap().get(serverName); + CompactionServerMetrics serverMetrics = onlineServers.asMap().get(serverName); return serverMetrics != null ? serverMetrics.getVersion() : "0.0.0"; } public int getInfoPort(ServerName serverName) { - ServerMetrics serverMetrics = onlineServers.asMap().get(serverName); + CompactionServerMetrics serverMetrics = onlineServers.asMap().get(serverName); return serverMetrics != null ? serverMetrics.getInfoServerPort() : 0; } + /** + * @return CompactionServerMetrics if serverName is known else null + */ + public CompactionServerMetrics getLoad(final ServerName serverName) { + return this.onlineServers.asMap().get(serverName); + } + public IsCompactionOffloadEnabledResponse isCompactionOffloadEnabled(IsCompactionOffloadEnabledRequest request) throws IOException { masterServices.getMasterCoprocessorHost().preIsCompactionOffloadEnabled();