Skip to content

Commit

Permalink
HBASE-25950 add basic compaction server metric (#3350)
Browse files Browse the repository at this point in the history
Signed-off-by: Duo Zhang <zhangduo@apache.org>
  • Loading branch information
nyl3532016 authored Jun 9, 2021
1 parent 997af02 commit 6afca94
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> 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();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/**
* 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.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;
private final List<String> 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<String> 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<String> compactionTasks = new ArrayList<>();
private final long totalNumberOfRequests;
private final long reportTimestamp;
private final long lastReportTimestamp;

CompactionServerMetricsImpl(ServerName serverName, int versionNumber, String version,
int infoServerPort, long compactingCellCount, long compactedCellCount,
List<String> 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<String> 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();
}
}
}
29 changes: 29 additions & 0 deletions hbase-protocol-shaded/src/main/protobuf/server/ClusterStatus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 6afca94

Please sign in to comment.