Revert "HBASE-22744 Removed deprecated status and load classes in client module"
This reverts commit 4a61c8b10a
.
This commit is contained in:
parent
caa05356a1
commit
24b970ec51
|
@ -0,0 +1,400 @@
|
|||
/**
|
||||
*
|
||||
* 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.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.hadoop.hbase.master.RegionState;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* Status information on the HBase cluster.
|
||||
* <p>
|
||||
* <tt>ClusterStatus</tt> provides clients with information such as:
|
||||
* <ul>
|
||||
* <li>The count and names of region servers in the cluster.</li>
|
||||
* <li>The count and names of dead region servers in the cluster.</li>
|
||||
* <li>The name of the active master for the cluster.</li>
|
||||
* <li>The name(s) of the backup master(s) for the cluster, if they exist.</li>
|
||||
* <li>The average cluster load.</li>
|
||||
* <li>The number of regions deployed on the cluster.</li>
|
||||
* <li>The number of requests since last report.</li>
|
||||
* <li>Detailed region server loading and resource usage information,
|
||||
* per server and per region.</li>
|
||||
* <li>Regions in transition at master</li>
|
||||
* <li>The unique cluster ID</li>
|
||||
* </ul>
|
||||
* <tt>{@link ClusterMetrics.Option}</tt> provides a way to get desired ClusterStatus information.
|
||||
* The following codes will get all the cluster information.
|
||||
* <pre>
|
||||
* {@code
|
||||
* // Original version still works
|
||||
* Admin admin = connection.getAdmin();
|
||||
* ClusterStatus status = admin.getClusterStatus();
|
||||
* // or below, a new version which has the same effects
|
||||
* ClusterStatus status = admin.getClusterStatus(EnumSet.allOf(Option.class));
|
||||
* }
|
||||
* </pre>
|
||||
* If information about live servers is the only wanted.
|
||||
* then codes in the following way:
|
||||
* <pre>
|
||||
* {@code
|
||||
* Admin admin = connection.getAdmin();
|
||||
* ClusterStatus status = admin.getClusterStatus(EnumSet.of(Option.LIVE_SERVERS));
|
||||
* }
|
||||
* </pre>
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link ClusterMetrics} instead.
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@Deprecated
|
||||
public class ClusterStatus implements ClusterMetrics {
|
||||
|
||||
// TODO: remove this in 3.0
|
||||
private static final byte VERSION = 2;
|
||||
|
||||
private final ClusterMetrics metrics;
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
public ClusterStatus(final String hbaseVersion, final String clusterid,
|
||||
final Map<ServerName, ServerLoad> servers,
|
||||
final Collection<ServerName> deadServers,
|
||||
final ServerName master,
|
||||
final Collection<ServerName> backupMasters,
|
||||
final List<RegionState> rit,
|
||||
final String[] masterCoprocessors,
|
||||
final Boolean balancerOn,
|
||||
final int masterInfoPort) {
|
||||
// TODO: make this constructor private
|
||||
this(ClusterMetricsBuilder.newBuilder().setHBaseVersion(hbaseVersion)
|
||||
.setDeadServerNames(new ArrayList<>(deadServers))
|
||||
.setLiveServerMetrics(servers.entrySet().stream()
|
||||
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())))
|
||||
.setBackerMasterNames(new ArrayList<>(backupMasters)).setBalancerOn(balancerOn)
|
||||
.setClusterId(clusterid)
|
||||
.setMasterCoprocessorNames(Arrays.asList(masterCoprocessors))
|
||||
.setMasterName(master)
|
||||
.setMasterInfoPort(masterInfoPort)
|
||||
.setRegionsInTransition(rit)
|
||||
.build());
|
||||
}
|
||||
|
||||
@InterfaceAudience.Private
|
||||
public ClusterStatus(ClusterMetrics metrics) {
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the names of region servers on the dead list
|
||||
*/
|
||||
@Override
|
||||
public List<ServerName> getDeadServerNames() {
|
||||
return metrics.getDeadServerNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ServerName, ServerMetrics> getLiveServerMetrics() {
|
||||
return metrics.getLiveServerMetrics();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of region servers in the cluster
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getLiveServerMetrics()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getServersSize() {
|
||||
return metrics.getLiveServerMetrics().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of dead region servers in the cluster
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* (<a href="https://issues.apache.org/jira/browse/HBASE-13656">HBASE-13656</a>).
|
||||
* Use {@link #getDeadServerNames()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getDeadServers() {
|
||||
return getDeadServersSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of dead region servers in the cluster
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getDeadServerNames()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getDeadServersSize() {
|
||||
return metrics.getDeadServerNames().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of regions deployed on the cluster
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionCount()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getRegionsCount() {
|
||||
return getRegionCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of requests since last report
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRequestCount()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getRequestsCount() {
|
||||
return (int) getRequestCount();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ServerName getMasterName() {
|
||||
return metrics.getMasterName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServerName> getBackupMasterNames() {
|
||||
return metrics.getBackupMasterNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RegionState> getRegionStatesInTransition() {
|
||||
return metrics.getRegionStatesInTransition();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the HBase version string as reported by the HMaster
|
||||
*/
|
||||
public String getHBaseVersion() {
|
||||
return metrics.getHBaseVersion();
|
||||
}
|
||||
|
||||
private Map<ServerName, ServerLoad> getLiveServerLoads() {
|
||||
return metrics.getLiveServerMetrics().entrySet().stream()
|
||||
.collect(Collectors.toMap(e -> e.getKey(), e -> new ServerLoad(e.getValue())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof ClusterStatus)) {
|
||||
return false;
|
||||
}
|
||||
ClusterStatus other = (ClusterStatus) o;
|
||||
return Objects.equal(getHBaseVersion(), other.getHBaseVersion()) &&
|
||||
Objects.equal(getLiveServerLoads(), other.getLiveServerLoads()) &&
|
||||
getDeadServerNames().containsAll(other.getDeadServerNames()) &&
|
||||
Arrays.equals(getMasterCoprocessors(), other.getMasterCoprocessors()) &&
|
||||
Objects.equal(getMaster(), other.getMaster()) &&
|
||||
getBackupMasters().containsAll(other.getBackupMasters()) &&
|
||||
Objects.equal(getClusterId(), other.getClusterId()) &&
|
||||
getMasterInfoPort() == other.getMasterInfoPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return metrics.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the object version number
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
public byte getVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getLiveServerMetrics()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Collection<ServerName> getServers() {
|
||||
return metrics.getLiveServerMetrics().keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns detailed information about the current master {@link ServerName}.
|
||||
* @return current master information if it exists
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getMasterName} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public ServerName getMaster() {
|
||||
return metrics.getMasterName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of backup masters in the cluster
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getBackupMasterNames} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getBackupMastersSize() {
|
||||
return metrics.getBackupMasterNames().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the names of backup masters
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getBackupMasterNames} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public List<ServerName> getBackupMasters() {
|
||||
return metrics.getBackupMasterNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sn
|
||||
* @return Server's load or null if not found.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getLiveServerMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public ServerLoad getLoad(final ServerName sn) {
|
||||
ServerMetrics serverMetrics = metrics.getLiveServerMetrics().get(sn);
|
||||
return serverMetrics == null ? null : new ServerLoad(serverMetrics);
|
||||
}
|
||||
|
||||
public String getClusterId() {
|
||||
return metrics.getClusterId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMasterCoprocessorNames() {
|
||||
return metrics.getMasterCoprocessorNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getMasterCoprocessorNames} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String[] getMasterCoprocessors() {
|
||||
List<String> rval = metrics.getMasterCoprocessorNames();
|
||||
return rval.toArray(new String[rval.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getLastMajorCompactionTimestamp(TableName)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getLastMajorCompactionTsForTable(TableName table) {
|
||||
return metrics.getLastMajorCompactionTimestamp(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getLastMajorCompactionTimestamp(byte[])} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getLastMajorCompactionTsForRegion(final byte[] region) {
|
||||
return metrics.getLastMajorCompactionTimestamp(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* No flag in 2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isBalancerOn() {
|
||||
return metrics.getBalancerOn() != null && metrics.getBalancerOn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getBalancerOn() {
|
||||
return metrics.getBalancerOn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMasterInfoPort() {
|
||||
return metrics.getMasterInfoPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServerName> getServersName() {
|
||||
return metrics.getServersName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(1024);
|
||||
sb.append("Master: " + metrics.getMasterName());
|
||||
|
||||
int backupMastersSize = getBackupMastersSize();
|
||||
sb.append("\nNumber of backup masters: " + backupMastersSize);
|
||||
if (backupMastersSize > 0) {
|
||||
for (ServerName serverName: metrics.getBackupMasterNames()) {
|
||||
sb.append("\n " + serverName);
|
||||
}
|
||||
}
|
||||
|
||||
int serversSize = getServersSize();
|
||||
int serversNameSize = getServersName().size();
|
||||
sb.append("\nNumber of live region servers: "
|
||||
+ (serversSize > 0 ? serversSize : serversNameSize));
|
||||
if (serversSize > 0) {
|
||||
for (ServerName serverName : metrics.getLiveServerMetrics().keySet()) {
|
||||
sb.append("\n " + serverName.getServerName());
|
||||
}
|
||||
} else if (serversNameSize > 0) {
|
||||
for (ServerName serverName : getServersName()) {
|
||||
sb.append("\n " + serverName.getServerName());
|
||||
}
|
||||
}
|
||||
|
||||
int deadServerSize = metrics.getDeadServerNames().size();
|
||||
sb.append("\nNumber of dead region servers: " + deadServerSize);
|
||||
if (deadServerSize > 0) {
|
||||
for (ServerName serverName : metrics.getDeadServerNames()) {
|
||||
sb.append("\n " + serverName);
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("\nAverage load: " + getAverageLoad());
|
||||
sb.append("\nNumber of requests: " + getRequestCount());
|
||||
sb.append("\nNumber of regions: " + getRegionsCount());
|
||||
|
||||
int ritSize = metrics.getRegionStatesInTransition().size();
|
||||
sb.append("\nNumber of regions in transition: " + ritSize);
|
||||
if (ritSize > 0) {
|
||||
for (RegionState state: metrics.getRegionStatesInTransition()) {
|
||||
sb.append("\n " + state.toDescriptiveString());
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,421 @@
|
|||
/**
|
||||
* 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 java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.hadoop.hbase.util.Strings;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos;
|
||||
|
||||
/**
|
||||
* Encapsulates per-region load metrics.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link RegionMetrics} instead.
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@Deprecated
|
||||
public class RegionLoad implements RegionMetrics {
|
||||
// DONT use this pb object since the byte array backed may be modified in rpc layer
|
||||
// we keep this pb object for BC.
|
||||
protected ClusterStatusProtos.RegionLoad regionLoadPB;
|
||||
private final RegionMetrics metrics;
|
||||
|
||||
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||
public RegionLoad(ClusterStatusProtos.RegionLoad regionLoadPB) {
|
||||
this.regionLoadPB = regionLoadPB;
|
||||
this.metrics = RegionMetricsBuilder.toRegionMetrics(regionLoadPB);
|
||||
}
|
||||
|
||||
RegionLoad(RegionMetrics metrics) {
|
||||
this.metrics = metrics;
|
||||
this.regionLoadPB = RegionMetricsBuilder.toRegionLoad(metrics);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the region name
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionName} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public byte[] getName() {
|
||||
return metrics.getRegionName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getRegionName() {
|
||||
return metrics.getRegionName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoreCount() {
|
||||
return metrics.getStoreCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoreFileCount() {
|
||||
return metrics.getStoreFileCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getStoreFileSize() {
|
||||
return metrics.getStoreFileSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getMemStoreSize() {
|
||||
return metrics.getMemStoreSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getReadRequestCount() {
|
||||
return metrics.getReadRequestCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCpRequestCount() {
|
||||
return metrics.getCpRequestCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFilteredReadRequestCount() {
|
||||
return metrics.getFilteredReadRequestCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getStoreFileIndexSize() {
|
||||
return metrics.getStoreFileIndexSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getWriteRequestCount() {
|
||||
return metrics.getWriteRequestCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getStoreFileRootLevelIndexSize() {
|
||||
return metrics.getStoreFileRootLevelIndexSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getStoreFileUncompressedDataIndexSize() {
|
||||
return metrics.getStoreFileUncompressedDataIndexSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getBloomFilterSize() {
|
||||
return metrics.getBloomFilterSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCompactingCellCount() {
|
||||
return metrics.getCompactingCellCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCompactedCellCount() {
|
||||
return metrics.getCompactedCellCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCompletedSequenceId() {
|
||||
return metrics.getCompletedSequenceId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<byte[], Long> getStoreSequenceId() {
|
||||
return metrics.getStoreSequenceId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getUncompressedStoreFileSize() {
|
||||
return metrics.getUncompressedStoreFileSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of stores
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getStoreCount} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStores() {
|
||||
return metrics.getStoreCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of storefiles
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getStoreFileCount} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStorefiles() {
|
||||
return metrics.getStoreFileCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the total size of the storefiles, in MB
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getStoreFileSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStorefileSizeMB() {
|
||||
return (int) metrics.getStoreFileSize().get(Size.Unit.MEGABYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the memstore size, in MB
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getMemStoreSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMemStoreSizeMB() {
|
||||
return (int) metrics.getMemStoreSize().get(Size.Unit.MEGABYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* ((<a href="https://issues.apache.org/jira/browse/HBASE-3935">HBASE-3935</a>)).
|
||||
* Use {@link #getStoreFileRootLevelIndexSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStorefileIndexSizeMB() {
|
||||
// Return value divided by 1024
|
||||
return (getRootIndexSizeKB() >> 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getStoreFileRootLevelIndexSize()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStorefileIndexSizeKB() {
|
||||
return getRootIndexSizeKB();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of requests made to region
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRequestCount()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getRequestsCount() {
|
||||
return metrics.getRequestCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of read requests made to region
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getReadRequestCount} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getReadRequestsCount() {
|
||||
return metrics.getReadRequestCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of filtered read requests made to region
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getFilteredReadRequestCount} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getFilteredReadRequestsCount() {
|
||||
return metrics.getFilteredReadRequestCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of write requests made to region
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getWriteRequestCount} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getWriteRequestsCount() {
|
||||
return metrics.getWriteRequestCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current total size of root-level indexes for the region, in KB.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getStoreFileRootLevelIndexSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getRootIndexSizeKB() {
|
||||
return (int) metrics.getStoreFileRootLevelIndexSize().get(Size.Unit.KILOBYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The total size of all index blocks, not just the root level, in KB.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getStoreFileUncompressedDataIndexSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getTotalStaticIndexSizeKB() {
|
||||
return (int) metrics.getStoreFileUncompressedDataIndexSize().get(Size.Unit.KILOBYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The total size of all Bloom filter blocks, not just loaded into the
|
||||
* block cache, in KB.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getBloomFilterSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getTotalStaticBloomSizeKB() {
|
||||
return (int) metrics.getBloomFilterSize().get(Size.Unit.KILOBYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the total number of kvs in current compaction
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getCompactingCellCount} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getTotalCompactingKVs() {
|
||||
return metrics.getCompactingCellCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of already compacted kvs in current compaction
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getCompactedCellCount} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getCurrentCompactedKVs() {
|
||||
return metrics.getCompactedCellCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* This does not really belong inside RegionLoad but its being done in the name of expediency.
|
||||
* @return the completed sequence Id for the region
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getCompletedSequenceId} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getCompleteSequenceId() {
|
||||
return metrics.getCompletedSequenceId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return completed sequence id per store.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getStoreSequenceId} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public List<ClusterStatusProtos.StoreSequenceId> getStoreCompleteSequenceId() {
|
||||
return metrics.getStoreSequenceId().entrySet().stream()
|
||||
.map(s -> ClusterStatusProtos.StoreSequenceId.newBuilder()
|
||||
.setFamilyName(UnsafeByteOperations.unsafeWrap(s.getKey()))
|
||||
.setSequenceId(s.getValue())
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the uncompressed size of the storefiles in MB.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getUncompressedStoreFileSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStoreUncompressedSizeMB() {
|
||||
return (int) metrics.getUncompressedStoreFileSize().get(Size.Unit.KILOBYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the data locality of region in the regionserver.
|
||||
*/
|
||||
@Override
|
||||
public float getDataLocality() {
|
||||
return metrics.getDataLocality();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastMajorCompactionTimestamp() {
|
||||
return metrics.getLastMajorCompactionTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the timestamp of the oldest hfile for any store of this region.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getLastMajorCompactionTimestamp} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getLastMajorCompactionTs() {
|
||||
return metrics.getLastMajorCompactionTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reference count for the stores of this region
|
||||
*/
|
||||
public int getStoreRefCount() {
|
||||
return metrics.getStoreRefCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "numberOfStores",
|
||||
this.getStores());
|
||||
Strings.appendKeyValue(sb, "numberOfStorefiles", this.getStorefiles());
|
||||
Strings.appendKeyValue(sb, "storeRefCount", this.getStoreRefCount());
|
||||
Strings.appendKeyValue(sb, "storefileUncompressedSizeMB",
|
||||
this.getStoreUncompressedSizeMB());
|
||||
Strings.appendKeyValue(sb, "lastMajorCompactionTimestamp",
|
||||
this.getLastMajorCompactionTs());
|
||||
Strings.appendKeyValue(sb, "storefileSizeMB", this.getStorefileSizeMB());
|
||||
if (this.getStoreUncompressedSizeMB() != 0) {
|
||||
Strings.appendKeyValue(sb, "compressionRatio",
|
||||
String.format("%.4f", (float) this.getStorefileSizeMB() /
|
||||
(float) this.getStoreUncompressedSizeMB()));
|
||||
}
|
||||
Strings.appendKeyValue(sb, "memstoreSizeMB",
|
||||
this.getMemStoreSizeMB());
|
||||
Strings.appendKeyValue(sb, "readRequestsCount",
|
||||
this.getReadRequestsCount());
|
||||
Strings.appendKeyValue(sb, "writeRequestsCount",
|
||||
this.getWriteRequestsCount());
|
||||
Strings.appendKeyValue(sb, "rootIndexSizeKB",
|
||||
this.getRootIndexSizeKB());
|
||||
Strings.appendKeyValue(sb, "totalStaticIndexSizeKB",
|
||||
this.getTotalStaticIndexSizeKB());
|
||||
Strings.appendKeyValue(sb, "totalStaticBloomSizeKB",
|
||||
this.getTotalStaticBloomSizeKB());
|
||||
Strings.appendKeyValue(sb, "totalCompactingKVs",
|
||||
this.getTotalCompactingKVs());
|
||||
Strings.appendKeyValue(sb, "currentCompactedKVs",
|
||||
this.getCurrentCompactedKVs());
|
||||
float compactionProgressPct = Float.NaN;
|
||||
if (this.getTotalCompactingKVs() > 0) {
|
||||
compactionProgressPct = ((float) this.getCurrentCompactedKVs() /
|
||||
(float) this.getTotalCompactingKVs());
|
||||
}
|
||||
Strings.appendKeyValue(sb, "compactionProgressPct",
|
||||
compactionProgressPct);
|
||||
Strings.appendKeyValue(sb, "completeSequenceId",
|
||||
this.getCompleteSequenceId());
|
||||
Strings.appendKeyValue(sb, "dataLocality",
|
||||
this.getDataLocality());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,596 @@
|
|||
/**
|
||||
* 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.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.hadoop.hbase.replication.ReplicationLoadSink;
|
||||
import org.apache.hadoop.hbase.replication.ReplicationLoadSource;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.util.Strings;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.common.base.Objects;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos;
|
||||
|
||||
/**
|
||||
* This class is used for exporting current state of load on a RegionServer.
|
||||
*
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link ServerMetrics} instead.
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@Deprecated
|
||||
public class ServerLoad implements ServerMetrics {
|
||||
private final ServerMetrics metrics;
|
||||
private int stores = 0;
|
||||
private int storefiles = 0;
|
||||
private int storeUncompressedSizeMB = 0;
|
||||
private int storefileSizeMB = 0;
|
||||
private int memstoreSizeMB = 0;
|
||||
private long storefileIndexSizeKB = 0;
|
||||
private long readRequestsCount = 0;
|
||||
private long cpRequestsCount = 0;
|
||||
private long filteredReadRequestsCount = 0;
|
||||
private long writeRequestsCount = 0;
|
||||
private int rootIndexSizeKB = 0;
|
||||
private int totalStaticIndexSizeKB = 0;
|
||||
private int totalStaticBloomSizeKB = 0;
|
||||
private long totalCompactingKVs = 0;
|
||||
private long currentCompactedKVs = 0;
|
||||
|
||||
/**
|
||||
* DONT USE this construction. It make a fake server name;
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
public ServerLoad(ClusterStatusProtos.ServerLoad serverLoad) {
|
||||
this(ServerName.valueOf("localhost,1,1"), serverLoad);
|
||||
}
|
||||
|
||||
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||
@InterfaceAudience.Private
|
||||
public ServerLoad(ServerName name, ClusterStatusProtos.ServerLoad serverLoad) {
|
||||
this(ServerMetricsBuilder.toServerMetrics(name, serverLoad));
|
||||
this.serverLoad = serverLoad;
|
||||
}
|
||||
|
||||
@InterfaceAudience.Private
|
||||
public ServerLoad(ServerMetrics metrics) {
|
||||
this.metrics = metrics;
|
||||
this.serverLoad = ServerMetricsBuilder.toServerLoad(metrics);
|
||||
for (RegionMetrics rl : metrics.getRegionMetrics().values()) {
|
||||
stores += rl.getStoreCount();
|
||||
storefiles += rl.getStoreFileCount();
|
||||
storeUncompressedSizeMB += rl.getUncompressedStoreFileSize().get(Size.Unit.MEGABYTE);
|
||||
storefileSizeMB += rl.getStoreFileSize().get(Size.Unit.MEGABYTE);
|
||||
memstoreSizeMB += rl.getMemStoreSize().get(Size.Unit.MEGABYTE);
|
||||
readRequestsCount += rl.getReadRequestCount();
|
||||
cpRequestsCount += rl.getCpRequestCount();
|
||||
filteredReadRequestsCount += rl.getFilteredReadRequestCount();
|
||||
writeRequestsCount += rl.getWriteRequestCount();
|
||||
storefileIndexSizeKB += rl.getStoreFileIndexSize().get(Size.Unit.KILOBYTE);
|
||||
rootIndexSizeKB += rl.getStoreFileRootLevelIndexSize().get(Size.Unit.KILOBYTE);
|
||||
totalStaticIndexSizeKB += rl.getStoreFileUncompressedDataIndexSize().get(Size.Unit.KILOBYTE);
|
||||
totalStaticBloomSizeKB += rl.getBloomFilterSize().get(Size.Unit.KILOBYTE);
|
||||
totalCompactingKVs += rl.getCompactingCellCount();
|
||||
currentCompactedKVs += rl.getCompactedCellCount();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: Function name cannot start with "get" because then an OpenDataException is thrown because
|
||||
* HBaseProtos.ServerLoad cannot be converted to an open data type(see HBASE-5967).
|
||||
* @return the underlying ServerLoad protobuf object
|
||||
* @deprecated DONT use this pb object since the byte array backed may be modified in rpc layer
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
@Deprecated
|
||||
public ClusterStatusProtos.ServerLoad obtainServerLoadPB() {
|
||||
return serverLoad;
|
||||
}
|
||||
|
||||
protected ClusterStatusProtos.ServerLoad serverLoad;
|
||||
|
||||
/**
|
||||
* @return number of requests since last report.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
|
||||
* Use {@link #getRequestCountPerSecond} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getNumberOfRequests() {
|
||||
return getRequestCountPerSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* No flag in 2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasNumberOfRequests() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return total Number of requests from the start of the region server.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
|
||||
* Use {@link #getRequestCount} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getTotalNumberOfRequests() {
|
||||
return getRequestCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* No flag in 2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasTotalNumberOfRequests() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount of used heap, in MB.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
|
||||
* Use {@link #getUsedHeapSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getUsedHeapMB() {
|
||||
return (int) getUsedHeapSize().get(Size.Unit.MEGABYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* No flag in 2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasUsedHeapMB() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum allowable size of the heap, in MB.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getMaxHeapSize} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMaxHeapMB() {
|
||||
return (int) getMaxHeapSize().get(Size.Unit.MEGABYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* No flag in 2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasMaxHeapMB() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStores() {
|
||||
return stores;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStorefiles() {
|
||||
return storefiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStoreUncompressedSizeMB() {
|
||||
return storeUncompressedSizeMB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStorefileSizeInMB() {
|
||||
return storefileSizeMB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStorefileSizeMB() {
|
||||
return storefileSizeMB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMemstoreSizeInMB() {
|
||||
return memstoreSizeMB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMemStoreSizeMB() {
|
||||
return memstoreSizeMB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStorefileIndexSizeInMB() {
|
||||
// Return value divided by 1024
|
||||
return (int) (getStorefileIndexSizeKB() >> 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getStorefileIndexSizeKB() {
|
||||
return storefileIndexSizeKB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getReadRequestsCount() {
|
||||
return readRequestsCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getCpRequestsCount() {
|
||||
return cpRequestsCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getFilteredReadRequestsCount() {
|
||||
return filteredReadRequestsCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getWriteRequestsCount() {
|
||||
return writeRequestsCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getRootIndexSizeKB() {
|
||||
return rootIndexSizeKB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getTotalStaticIndexSizeKB() {
|
||||
return totalStaticIndexSizeKB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getTotalStaticBloomSizeKB() {
|
||||
return totalStaticBloomSizeKB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getTotalCompactingKVs() {
|
||||
return totalCompactingKVs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getCurrentCompactedKVs() {
|
||||
return currentCompactedKVs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getNumberOfRegions() {
|
||||
return metrics.getRegionMetrics().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return metrics.getServerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRequestCountPerSecond() {
|
||||
return metrics.getRequestCountPerSecond();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRequestCount() {
|
||||
return metrics.getRequestCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getUsedHeapSize() {
|
||||
return metrics.getUsedHeapSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getMaxHeapSize() {
|
||||
return metrics.getMaxHeapSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInfoServerPort() {
|
||||
return metrics.getInfoServerPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call directly from client such as hbase shell
|
||||
* @return the list of ReplicationLoadSource
|
||||
*/
|
||||
@Override
|
||||
public List<ReplicationLoadSource> getReplicationLoadSourceList() {
|
||||
return metrics.getReplicationLoadSourceList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call directly from client such as hbase shell
|
||||
* @return a map of ReplicationLoadSource list per peer id
|
||||
*/
|
||||
@Override
|
||||
public Map<String, List<ReplicationLoadSource>> getReplicationLoadSourceMap() {
|
||||
return metrics.getReplicationLoadSourceMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call directly from client such as hbase shell
|
||||
* @return ReplicationLoadSink
|
||||
*/
|
||||
@Override
|
||||
public ReplicationLoadSink getReplicationLoadSink() {
|
||||
return metrics.getReplicationLoadSink();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<byte[], RegionMetrics> getRegionMetrics() {
|
||||
return metrics.getRegionMetrics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCoprocessorNames() {
|
||||
return metrics.getCoprocessorNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getReportTimestamp() {
|
||||
return metrics.getReportTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastReportTimestamp() {
|
||||
return metrics.getLastReportTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Originally, this method factored in the effect of requests going to the
|
||||
* server as well. However, this does not interact very well with the current
|
||||
* region rebalancing code, which only factors number of regions. For the
|
||||
* interim, until we can figure out how to make rebalancing use all the info
|
||||
* available, we're just going to make load purely the number of regions.
|
||||
*
|
||||
* @return load factor for this server.
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getNumberOfRegions} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getLoad() {
|
||||
// See above comment
|
||||
// int load = numberOfRequests == 0 ? 1 : numberOfRequests;
|
||||
// load *= numberOfRegions == 0 ? 1 : numberOfRegions;
|
||||
// return load;
|
||||
return getNumberOfRegions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRegionMetrics} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Map<byte[], RegionLoad> getRegionsLoad() {
|
||||
return getRegionMetrics().entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> new RegionLoad(e.getValue()),
|
||||
(v1, v2) -> {
|
||||
throw new RuntimeException("key collisions?");
|
||||
}, () -> new TreeMap<>(Bytes.BYTES_COMPARATOR)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getCoprocessorNames} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String[] getRegionServerCoprocessors() {
|
||||
return getCoprocessorNames().toArray(new String[getCoprocessorNames().size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getCoprocessorNames} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String[] getRsCoprocessors() {
|
||||
return getRegionServerCoprocessors();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getRequestCountPerSecond} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public double getRequestsPerSecond() {
|
||||
return getRequestCountPerSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "requestsPerSecond",
|
||||
Double.valueOf(getRequestsPerSecond()));
|
||||
Strings.appendKeyValue(sb, "numberOfOnlineRegions", Integer.valueOf(getNumberOfRegions()));
|
||||
Strings.appendKeyValue(sb, "usedHeapMB", Integer.valueOf(this.getUsedHeapMB()));
|
||||
Strings.appendKeyValue(sb, "maxHeapMB", Integer.valueOf(getMaxHeapMB()));
|
||||
Strings.appendKeyValue(sb, "numberOfStores", Integer.valueOf(this.stores));
|
||||
Strings.appendKeyValue(sb, "numberOfStorefiles", Integer.valueOf(this.storefiles));
|
||||
Strings.appendKeyValue(sb, "storefileUncompressedSizeMB",
|
||||
Integer.valueOf(this.storeUncompressedSizeMB));
|
||||
Strings.appendKeyValue(sb, "storefileSizeMB", Integer.valueOf(this.storefileSizeMB));
|
||||
if (this.storeUncompressedSizeMB != 0) {
|
||||
Strings.appendKeyValue(sb, "compressionRatio", String.format("%.4f",
|
||||
(float) this.storefileSizeMB / (float) this.storeUncompressedSizeMB));
|
||||
}
|
||||
Strings.appendKeyValue(sb, "memstoreSizeMB", Integer.valueOf(this.memstoreSizeMB));
|
||||
Strings.appendKeyValue(sb, "storefileIndexSizeKB",
|
||||
Long.valueOf(this.storefileIndexSizeKB));
|
||||
Strings.appendKeyValue(sb, "readRequestsCount", Long.valueOf(this.readRequestsCount));
|
||||
Strings.appendKeyValue(sb, "cpRequestsCount", Long.valueOf(this.cpRequestsCount));
|
||||
Strings.appendKeyValue(sb, "filteredReadRequestsCount",
|
||||
Long.valueOf(this.filteredReadRequestsCount));
|
||||
Strings.appendKeyValue(sb, "writeRequestsCount", Long.valueOf(this.writeRequestsCount));
|
||||
Strings.appendKeyValue(sb, "rootIndexSizeKB", Integer.valueOf(this.rootIndexSizeKB));
|
||||
Strings.appendKeyValue(sb, "totalStaticIndexSizeKB",
|
||||
Integer.valueOf(this.totalStaticIndexSizeKB));
|
||||
Strings.appendKeyValue(sb, "totalStaticBloomSizeKB",
|
||||
Integer.valueOf(this.totalStaticBloomSizeKB));
|
||||
Strings.appendKeyValue(sb, "totalCompactingKVs", Long.valueOf(this.totalCompactingKVs));
|
||||
Strings.appendKeyValue(sb, "currentCompactedKVs", Long.valueOf(this.currentCompactedKVs));
|
||||
float compactionProgressPct = Float.NaN;
|
||||
if (this.totalCompactingKVs > 0) {
|
||||
compactionProgressPct =
|
||||
Float.valueOf((float) this.currentCompactedKVs / this.totalCompactingKVs);
|
||||
}
|
||||
Strings.appendKeyValue(sb, "compactionProgressPct", compactionProgressPct);
|
||||
|
||||
String[] coprocessorStrings = getRsCoprocessors();
|
||||
if (coprocessorStrings != null) {
|
||||
Strings.appendKeyValue(sb, "coprocessors", Arrays.toString(coprocessorStrings));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link ServerMetricsBuilder#of(ServerName)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final ServerLoad EMPTY_SERVERLOAD =
|
||||
new ServerLoad(ServerName.valueOf("localhost,1,1"),
|
||||
ClusterStatusProtos.ServerLoad.newBuilder().build());
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getReportTimestamp} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getReportTime() {
|
||||
return getReportTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects
|
||||
.hashCode(stores, storefiles, storeUncompressedSizeMB, storefileSizeMB, memstoreSizeMB,
|
||||
storefileIndexSizeKB, readRequestsCount, cpRequestsCount, filteredReadRequestsCount,
|
||||
writeRequestsCount, rootIndexSizeKB, totalStaticIndexSizeKB, totalStaticBloomSizeKB,
|
||||
totalCompactingKVs, currentCompactedKVs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) return true;
|
||||
if (other instanceof ServerLoad) {
|
||||
ServerLoad sl = ((ServerLoad) other);
|
||||
return stores == sl.stores && storefiles == sl.storefiles
|
||||
&& storeUncompressedSizeMB == sl.storeUncompressedSizeMB
|
||||
&& storefileSizeMB == sl.storefileSizeMB && memstoreSizeMB == sl.memstoreSizeMB
|
||||
&& storefileIndexSizeKB == sl.storefileIndexSizeKB
|
||||
&& readRequestsCount == sl.readRequestsCount
|
||||
&& cpRequestsCount == sl.cpRequestsCount
|
||||
&& filteredReadRequestsCount == sl.filteredReadRequestsCount
|
||||
&& writeRequestsCount == sl.writeRequestsCount && rootIndexSizeKB == sl.rootIndexSizeKB
|
||||
&& totalStaticIndexSizeKB == sl.totalStaticIndexSizeKB
|
||||
&& totalStaticBloomSizeKB == sl.totalStaticBloomSizeKB
|
||||
&& totalCompactingKVs == sl.totalCompactingKVs
|
||||
&& currentCompactedKVs == sl.currentCompactedKVs;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -131,6 +131,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetOnlineRe
|
|||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetOnlineRegionResponse;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionLoadResponse;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetServerInfoRequest;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetServerInfoResponse;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetStoreFileRequest;
|
||||
|
@ -1733,6 +1734,16 @@ public final class ProtobufUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static List<org.apache.hadoop.hbase.RegionLoad> getRegionLoadInfo(
|
||||
GetRegionLoadResponse regionLoadResponse) {
|
||||
List<org.apache.hadoop.hbase.RegionLoad> regionLoadList =
|
||||
new ArrayList<>(regionLoadResponse.getRegionLoadsCount());
|
||||
for (RegionLoad regionLoad : regionLoadResponse.getRegionLoadsList()) {
|
||||
regionLoadList.add(new org.apache.hadoop.hbase.RegionLoad(regionLoad));
|
||||
}
|
||||
return regionLoadList;
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper to close a region given a region name
|
||||
* using admin protocol.
|
||||
|
|
|
@ -100,7 +100,7 @@ public class TestStatusResource {
|
|||
TEST_UTIL.waitFor(6000, new Waiter.Predicate<IOException>() {
|
||||
@Override
|
||||
public boolean evaluate() throws IOException {
|
||||
return TEST_UTIL.getMiniHBaseCluster().getClusterMetrics().getAverageLoad() > 0;
|
||||
return TEST_UTIL.getMiniHBaseCluster().getClusterStatus().getAverageLoad() > 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class MiniHBaseCluster extends HBaseCluster {
|
|||
CompatibilityFactory.getInstance(MetricsAssertHelper.class).init();
|
||||
|
||||
init(numMasters, numRegionServers, rsPorts, masterClass, regionserverClass);
|
||||
this.initialClusterStatus = getClusterMetrics();
|
||||
this.initialClusterStatus = getClusterStatus();
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
|
@ -435,9 +435,9 @@ public class MiniHBaseCluster extends HBaseCluster {
|
|||
ServerName rsServerName = t.getRegionServer().getServerName();
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
ClusterMetrics clusterStatus = getClusterMetrics();
|
||||
ClusterStatus clusterStatus = getClusterStatus();
|
||||
while ((System.currentTimeMillis() - start) < timeout) {
|
||||
if (clusterStatus != null && clusterStatus.getLiveServerMetrics().containsKey(rsServerName)) {
|
||||
if (clusterStatus != null && clusterStatus.getServers().contains(rsServerName)) {
|
||||
return t;
|
||||
}
|
||||
Threads.sleep(100);
|
||||
|
@ -659,6 +659,16 @@ public class MiniHBaseCluster extends HBaseCluster {
|
|||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
|
||||
* Use {@link #getClusterMetrics()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public ClusterStatus getClusterStatus() throws IOException {
|
||||
HMaster master = getMaster();
|
||||
return master == null ? null : new ClusterStatus(master.getClusterMetrics());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterMetrics getClusterMetrics() throws IOException {
|
||||
HMaster master = getMaster();
|
||||
|
|
|
@ -89,6 +89,8 @@ public class TestClientClusterStatus {
|
|||
// or more requests than expected.
|
||||
Assert.assertEquals(status0.getLiveServerMetrics().size(),
|
||||
status1.getLiveServerMetrics().size());
|
||||
checkPbObjectNotNull(new ClusterStatus(status0));
|
||||
checkPbObjectNotNull(new ClusterStatus(status1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -107,26 +109,28 @@ public class TestClientClusterStatus {
|
|||
Waiter.waitFor(CLUSTER.getConfiguration(), 10 * 1000, 100, new Predicate<Exception>() {
|
||||
@Override
|
||||
public boolean evaluate() throws Exception {
|
||||
ClusterMetrics status = ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
|
||||
ClusterStatus status
|
||||
= new ClusterStatus(ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)));
|
||||
Assert.assertNotNull(status);
|
||||
return status.getRegionCount() > 0;
|
||||
return status.getRegionsCount() > 0;
|
||||
}
|
||||
});
|
||||
// Retrieve live servers and dead servers info.
|
||||
EnumSet<Option> options =
|
||||
EnumSet.of(Option.LIVE_SERVERS, Option.DEAD_SERVERS, Option.SERVERS_NAME);
|
||||
ClusterMetrics status = ADMIN.getClusterMetrics(options);
|
||||
ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(options));
|
||||
checkPbObjectNotNull(status);
|
||||
Assert.assertNotNull(status);
|
||||
Assert.assertNotNull(status.getLiveServerMetrics().keySet());
|
||||
Assert.assertNotNull(status.getServers());
|
||||
// exclude a dead region server
|
||||
Assert.assertEquals(SLAVES -1, numRs);
|
||||
// live servers = nums of regionservers
|
||||
// By default, HMaster don't carry any regions so it won't report its load.
|
||||
// Hence, it won't be in the server list.
|
||||
Assert.assertEquals(status.getLiveServerMetrics().keySet().size(), numRs);
|
||||
Assert.assertTrue(status.getRegionCount() > 0);
|
||||
Assert.assertEquals(status.getServers().size(), numRs);
|
||||
Assert.assertTrue(status.getRegionsCount() > 0);
|
||||
Assert.assertNotNull(status.getDeadServerNames());
|
||||
Assert.assertEquals(1, status.getDeadServerNames().size());
|
||||
Assert.assertEquals(1, status.getDeadServersSize());
|
||||
ServerName deadServerName = status.getDeadServerNames().iterator().next();
|
||||
Assert.assertEquals(DEAD.getServerName(), deadServerName);
|
||||
Assert.assertNotNull(status.getServersName());
|
||||
|
@ -154,9 +158,9 @@ public class TestClientClusterStatus {
|
|||
Assert.assertEquals(MASTERS, masterThreads.size());
|
||||
// Retrieve master and backup masters infos only.
|
||||
EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS);
|
||||
ClusterMetrics status = ADMIN.getClusterMetrics(options);
|
||||
Assert.assertTrue(status.getMasterName().equals(activeName));
|
||||
Assert.assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
|
||||
ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(options));
|
||||
Assert.assertTrue(status.getMaster().equals(activeName));
|
||||
Assert.assertEquals(MASTERS - 1, status.getBackupMastersSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -164,8 +168,8 @@ public class TestClientClusterStatus {
|
|||
EnumSet<Option> options =
|
||||
EnumSet.of(Option.MASTER_COPROCESSORS, Option.HBASE_VERSION,
|
||||
Option.CLUSTER_ID, Option.BALANCER_ON);
|
||||
ClusterMetrics status = ADMIN.getClusterMetrics(options);
|
||||
Assert.assertTrue(status.getMasterCoprocessorNames().size() == 1);
|
||||
ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(options));
|
||||
Assert.assertTrue(status.getMasterCoprocessors().length == 1);
|
||||
Assert.assertNotNull(status.getHBaseVersion());
|
||||
Assert.assertNotNull(status.getClusterId());
|
||||
Assert.assertTrue(status.getAverageLoad() == 0.0);
|
||||
|
@ -188,6 +192,21 @@ public class TestClientClusterStatus {
|
|||
Assert.assertEquals(postCount + 1, MyObserver.POST_COUNT.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* HBASE-19496 do the refactor for ServerLoad and RegionLoad so the inner pb object is useless
|
||||
* now. However, they are Public classes, and consequently we must make sure the all pb objects
|
||||
* have initialized.
|
||||
*/
|
||||
private static void checkPbObjectNotNull(ClusterStatus status) {
|
||||
for (ServerName name : status.getLiveServerMetrics().keySet()) {
|
||||
ServerLoad load = status.getLoad(name);
|
||||
Assert.assertNotNull(load.obtainServerLoadPB());
|
||||
for (RegionLoad rl : load.getRegionsLoad().values()) {
|
||||
Assert.assertNotNull(rl.regionLoadPB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyObserver implements MasterCoprocessor, MasterObserver {
|
||||
private static final AtomicInteger PRE_COUNT = new AtomicInteger(0);
|
||||
private static final AtomicInteger POST_COUNT = new AtomicInteger(0);
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.hadoop.hbase.ClusterMetrics.Option;
|
||||
import org.apache.hadoop.hbase.client.Admin;
|
||||
import org.apache.hadoop.hbase.client.RegionInfo;
|
||||
import org.apache.hadoop.hbase.client.Table;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
|
||||
|
||||
@Category({MiscTests.class, MediumTests.class})
|
||||
public class TestRegionLoad {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestRegionLoad.class);
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TestRegionLoad.class);
|
||||
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
|
||||
private static Admin admin;
|
||||
|
||||
private static final TableName TABLE_1 = TableName.valueOf("table_1");
|
||||
private static final TableName TABLE_2 = TableName.valueOf("table_2");
|
||||
private static final TableName TABLE_3 = TableName.valueOf("table_3");
|
||||
private static final TableName[] tables = new TableName[]{TABLE_1, TABLE_2, TABLE_3};
|
||||
private static final int MSG_INTERVAL = 500; // ms
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
// Make servers report eagerly. This test is about looking at the cluster status reported.
|
||||
// Make it so we don't have to wait around too long to see change.
|
||||
UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", MSG_INTERVAL);
|
||||
UTIL.startMiniCluster(4);
|
||||
admin = UTIL.getAdmin();
|
||||
admin.balancerSwitch(false, true);
|
||||
createTables();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
private static void createTables() throws IOException, InterruptedException {
|
||||
byte[][] FAMILIES = new byte [][] {Bytes.toBytes("f")};
|
||||
for (TableName tableName : tables) {
|
||||
Table table =
|
||||
UTIL.createTable(tableName, FAMILIES, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
||||
UTIL.waitTableAvailable(tableName);
|
||||
UTIL.loadTable(table, FAMILIES[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionLoad() throws Exception {
|
||||
|
||||
// Check if regions match with the regionLoad from the server
|
||||
for (ServerName serverName : admin
|
||||
.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) {
|
||||
List<RegionInfo> regions = admin.getRegions(serverName);
|
||||
LOG.info("serverName=" + serverName + ", regions=" +
|
||||
regions.stream().map(r -> r.getRegionNameAsString()).collect(Collectors.toList()));
|
||||
Collection<RegionLoad> regionLoads = admin.getRegionMetrics(serverName)
|
||||
.stream().map(r -> new RegionLoad(r)).collect(Collectors.toList());
|
||||
LOG.info("serverName=" + serverName + ", regionLoads=" +
|
||||
regionLoads.stream().map(r -> Bytes.toString(r.getRegionName())).
|
||||
collect(Collectors.toList()));
|
||||
checkRegionsAndRegionLoads(regions, regionLoads);
|
||||
}
|
||||
|
||||
// Check if regionLoad matches the table's regions and nothing is missed
|
||||
for (TableName table : new TableName[]{TABLE_1, TABLE_2, TABLE_3}) {
|
||||
List<RegionInfo> tableRegions = admin.getRegions(table);
|
||||
|
||||
List<RegionLoad> regionLoads = Lists.newArrayList();
|
||||
for (ServerName serverName : admin
|
||||
.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) {
|
||||
regionLoads.addAll(admin.getRegionMetrics(serverName, table)
|
||||
.stream().map(r -> new RegionLoad(r)).collect(Collectors.toList()));
|
||||
}
|
||||
checkRegionsAndRegionLoads(tableRegions, regionLoads);
|
||||
}
|
||||
|
||||
// Just wait here. If this fixes the test, come back and do a better job.
|
||||
// Would have to redo the below so can wait on cluster status changing.
|
||||
// Admin#getClusterMetrics retrieves data from HMaster. Admin#getRegionMetrics, by contrast,
|
||||
// get the data from RS. Hence, it will fail if we do the assert check before RS has done
|
||||
// the report.
|
||||
TimeUnit.MILLISECONDS.sleep(3 * MSG_INTERVAL);
|
||||
|
||||
// Check RegionLoad matches the regionLoad from ClusterStatus
|
||||
ClusterStatus clusterStatus
|
||||
= new ClusterStatus(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)));
|
||||
for (ServerName serverName : clusterStatus.getServers()) {
|
||||
ServerLoad serverLoad = clusterStatus.getLoad(serverName);
|
||||
Map<byte[], RegionLoad> regionLoads = admin.getRegionMetrics(serverName).stream()
|
||||
.collect(Collectors.toMap(e -> e.getRegionName(), e -> new RegionLoad(e),
|
||||
(v1, v2) -> {
|
||||
throw new RuntimeException("impossible!!");
|
||||
}, () -> new TreeMap<>(Bytes.BYTES_COMPARATOR)));
|
||||
LOG.debug("serverName=" + serverName + ", getRegionLoads=" +
|
||||
serverLoad.getRegionsLoad().keySet().stream().map(r -> Bytes.toString(r)).
|
||||
collect(Collectors.toList()));
|
||||
LOG.debug("serverName=" + serverName + ", regionLoads=" +
|
||||
regionLoads.keySet().stream().map(r -> Bytes.toString(r)).
|
||||
collect(Collectors.toList()));
|
||||
compareRegionLoads(serverLoad.getRegionsLoad(), regionLoads);
|
||||
}
|
||||
}
|
||||
|
||||
private void compareRegionLoads(Map<byte[], RegionLoad> regionLoadCluster,
|
||||
Map<byte[], RegionLoad> regionLoads) {
|
||||
|
||||
assertEquals("No of regionLoads from clusterStatus and regionloads from RS doesn't match",
|
||||
regionLoadCluster.size(), regionLoads.size());
|
||||
|
||||
// The contents of region load from cluster and server should match
|
||||
for (byte[] regionName : regionLoadCluster.keySet()) {
|
||||
regionLoads.remove(regionName);
|
||||
}
|
||||
assertEquals("regionLoads from SN should be empty", 0, regionLoads.size());
|
||||
}
|
||||
|
||||
private void checkRegionsAndRegionLoads(Collection<RegionInfo> regions,
|
||||
Collection<RegionLoad> regionLoads) {
|
||||
for (RegionLoad load : regionLoads) {
|
||||
assertNotNull(load.regionLoadPB);
|
||||
}
|
||||
|
||||
assertEquals("No of regions and regionloads doesn't match", regions.size(), regionLoads.size());
|
||||
|
||||
Map<byte[], RegionLoad> regionLoadMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
|
||||
for (RegionLoad regionLoad : regionLoads) {
|
||||
regionLoadMap.put(regionLoad.getName(), regionLoad);
|
||||
}
|
||||
for (RegionInfo info : regions) {
|
||||
assertTrue("Region not in regionLoadMap region:" + info.getRegionNameAsString() +
|
||||
" regionMap: " + regionLoadMap, regionLoadMap.containsKey(info.getRegionName()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.ByteString;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
|
||||
|
||||
@Category({ MiscTests.class, SmallTests.class })
|
||||
public class TestServerLoad {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestServerLoad.class);
|
||||
|
||||
@Test
|
||||
public void testRegionLoadAggregation() {
|
||||
ServerLoad sl = new ServerLoad(ServerName.valueOf("localhost,1,1"), createServerLoadProto());
|
||||
assertEquals(13, sl.getStores());
|
||||
assertEquals(114, sl.getStorefiles());
|
||||
assertEquals(129, sl.getStoreUncompressedSizeMB());
|
||||
assertEquals(504, sl.getRootIndexSizeKB());
|
||||
assertEquals(820, sl.getStorefileSizeMB());
|
||||
assertEquals(82, sl.getStorefileIndexSizeKB());
|
||||
assertEquals(((long) Integer.MAX_VALUE) * 2, sl.getReadRequestsCount());
|
||||
assertEquals(300, sl.getFilteredReadRequestsCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
ServerLoad sl = new ServerLoad(ServerName.valueOf("localhost,1,1"), createServerLoadProto());
|
||||
String slToString = sl.toString();
|
||||
assertNotNull(sl.obtainServerLoadPB());
|
||||
assertTrue(slToString.contains("numberOfStores=13"));
|
||||
assertTrue(slToString.contains("numberOfStorefiles=114"));
|
||||
assertTrue(slToString.contains("storefileUncompressedSizeMB=129"));
|
||||
assertTrue(slToString.contains("storefileSizeMB=820"));
|
||||
assertTrue(slToString.contains("rootIndexSizeKB=504"));
|
||||
assertTrue(slToString.contains("coprocessors=[]"));
|
||||
assertTrue(slToString.contains("filteredReadRequestsCount=300"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionLoadWrapAroundAggregation() {
|
||||
ServerLoad sl = new ServerLoad(ServerName.valueOf("localhost,1,1"), createServerLoadProto());
|
||||
assertNotNull(sl.obtainServerLoadPB());
|
||||
long totalCount = ((long) Integer.MAX_VALUE) * 2;
|
||||
assertEquals(totalCount, sl.getReadRequestsCount());
|
||||
assertEquals(totalCount, sl.getWriteRequestsCount());
|
||||
}
|
||||
|
||||
private ClusterStatusProtos.ServerLoad createServerLoadProto() {
|
||||
HBaseProtos.RegionSpecifier rSpecOne = HBaseProtos.RegionSpecifier.newBuilder()
|
||||
.setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
|
||||
.setValue(ByteString.copyFromUtf8("ASDFGQWERT")).build();
|
||||
HBaseProtos.RegionSpecifier rSpecTwo = HBaseProtos.RegionSpecifier.newBuilder()
|
||||
.setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
|
||||
.setValue(ByteString.copyFromUtf8("QWERTYUIOP")).build();
|
||||
|
||||
ClusterStatusProtos.RegionLoad rlOne =
|
||||
ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecOne).setStores(10)
|
||||
.setStorefiles(101).setStoreUncompressedSizeMB(106).setStorefileSizeMB(520)
|
||||
.setFilteredReadRequestsCount(100).setStorefileIndexSizeKB(42).setRootIndexSizeKB(201)
|
||||
.setReadRequestsCount(Integer.MAX_VALUE).setWriteRequestsCount(Integer.MAX_VALUE).build();
|
||||
ClusterStatusProtos.RegionLoad rlTwo =
|
||||
ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecTwo).setStores(3)
|
||||
.setStorefiles(13).setStoreUncompressedSizeMB(23).setStorefileSizeMB(300)
|
||||
.setFilteredReadRequestsCount(200).setStorefileIndexSizeKB(40).setRootIndexSizeKB(303)
|
||||
.setReadRequestsCount(Integer.MAX_VALUE).setWriteRequestsCount(Integer.MAX_VALUE).build();
|
||||
|
||||
ClusterStatusProtos.ServerLoad sl =
|
||||
ClusterStatusProtos.ServerLoad.newBuilder().addRegionLoads(rlOne).
|
||||
addRegionLoads(rlTwo).build();
|
||||
return sl;
|
||||
}
|
||||
|
||||
}
|
|
@ -33,8 +33,8 @@ import org.apache.hadoop.hbase.ClusterMetrics.Option;
|
|||
import org.apache.hadoop.hbase.CompareOperator;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.RegionMetrics;
|
||||
import org.apache.hadoop.hbase.ServerMetrics;
|
||||
import org.apache.hadoop.hbase.RegionLoad;
|
||||
import org.apache.hadoop.hbase.ServerLoad;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.client.Admin;
|
||||
|
@ -170,23 +170,22 @@ public class TestRegionServerReadRequestMetrics {
|
|||
requestsMapPrev.put(metric, requestsMap.get(metric));
|
||||
}
|
||||
|
||||
ServerMetrics serverMetrics = null;
|
||||
RegionMetrics regionMetricsOuter = null;
|
||||
ServerLoad serverLoad = null;
|
||||
RegionLoad regionLoadOuter = null;
|
||||
boolean metricsUpdated = false;
|
||||
for (int i = 0; i < MAX_TRY; i++) {
|
||||
for (ServerName serverName : serverNames) {
|
||||
serverMetrics = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))
|
||||
.getLiveServerMetrics().get(serverName);
|
||||
serverLoad = new ServerLoad(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))
|
||||
.getLiveServerMetrics().get(serverName));
|
||||
|
||||
Map<byte[], RegionMetrics> regionMetrics = serverMetrics.getRegionMetrics();
|
||||
RegionMetrics regionMetric = regionMetrics.get(regionInfo.getRegionName());
|
||||
if (regionMetric != null) {
|
||||
regionMetricsOuter = regionMetric;
|
||||
Map<byte[], RegionLoad> regionsLoad = serverLoad.getRegionsLoad();
|
||||
RegionLoad regionLoad = regionsLoad.get(regionInfo.getRegionName());
|
||||
if (regionLoad != null) {
|
||||
regionLoadOuter = regionLoad;
|
||||
for (Metric metric : Metric.values()) {
|
||||
if (getReadRequest(serverMetrics, regionMetric, metric) > requestsMapPrev.get(metric)) {
|
||||
if (getReadRequest(serverLoad, regionLoad, metric) > requestsMapPrev.get(metric)) {
|
||||
for (Metric metricInner : Metric.values()) {
|
||||
requestsMap.put(metricInner, getReadRequest(serverMetrics, regionMetric,
|
||||
metricInner));
|
||||
requestsMap.put(metricInner, getReadRequest(serverLoad, regionLoad, metricInner));
|
||||
}
|
||||
metricsUpdated = true;
|
||||
break;
|
||||
|
@ -201,24 +200,21 @@ public class TestRegionServerReadRequestMetrics {
|
|||
}
|
||||
if (!metricsUpdated) {
|
||||
for (Metric metric : Metric.values()) {
|
||||
requestsMap.put(metric, getReadRequest(serverMetrics, regionMetricsOuter, metric));
|
||||
requestsMap.put(metric, getReadRequest(serverLoad, regionLoadOuter, metric));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long getReadRequest(ServerMetrics serverMetrics, RegionMetrics regionMetrics,
|
||||
Metric metric) {
|
||||
private static long getReadRequest(ServerLoad serverLoad, RegionLoad regionLoad, Metric metric) {
|
||||
switch (metric) {
|
||||
case REGION_READ:
|
||||
return regionMetrics.getReadRequestCount();
|
||||
return regionLoad.getReadRequestsCount();
|
||||
case SERVER_READ:
|
||||
return serverMetrics.getRegionMetrics().get(regionMetrics.getRegionName())
|
||||
.getReadRequestCount();
|
||||
return serverLoad.getReadRequestsCount();
|
||||
case FILTERED_REGION_READ:
|
||||
return regionMetrics.getFilteredReadRequestCount();
|
||||
return regionLoad.getFilteredReadRequestsCount();
|
||||
case FILTERED_SERVER_READ:
|
||||
return serverMetrics.getRegionMetrics().get(regionMetrics.getRegionName())
|
||||
.getFilteredReadRequestCount();
|
||||
return serverLoad.getFilteredReadRequestsCount();
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
@ -459,16 +455,15 @@ public class TestRegionServerReadRequestMetrics {
|
|||
|
||||
private void testReadRequests(byte[] regionName, int expectedReadRequests) throws Exception {
|
||||
for (ServerName serverName : serverNames) {
|
||||
ServerMetrics serverMetrics = admin.getClusterMetrics(
|
||||
EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().get(serverName);
|
||||
Map<byte[], RegionMetrics> regionMetrics = serverMetrics.getRegionMetrics();
|
||||
RegionMetrics regionMetric = regionMetrics.get(regionName);
|
||||
if (regionMetric != null) {
|
||||
LOG.debug("server read request is "
|
||||
+ serverMetrics.getRegionMetrics().get(regionName).getReadRequestCount()
|
||||
+ ", region read request is " + regionMetric.getReadRequestCount());
|
||||
assertEquals(3, serverMetrics.getRegionMetrics().get(regionName).getReadRequestCount());
|
||||
assertEquals(3, regionMetric.getReadRequestCount());
|
||||
ServerLoad serverLoad = new ServerLoad(admin.getClusterMetrics(
|
||||
EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().get(serverName));
|
||||
Map<byte[], RegionLoad> regionsLoad = serverLoad.getRegionsLoad();
|
||||
RegionLoad regionLoad = regionsLoad.get(regionName);
|
||||
if (regionLoad != null) {
|
||||
LOG.debug("server read request is " + serverLoad.getReadRequestsCount()
|
||||
+ ", region read request is " + regionLoad.getReadRequestsCount());
|
||||
assertEquals(3, serverLoad.getReadRequestsCount());
|
||||
assertEquals(3, regionLoad.getReadRequestsCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos;
|
|||
|
||||
/**
|
||||
* Tracker on cluster settings up in zookeeper.
|
||||
* This is not related to {@link org.apache.hadoop.hbase.ClusterMetrics}. That class
|
||||
* This is not related to {@link org.apache.hadoop.hbase.ClusterStatus}. That class
|
||||
* is a data structure that holds snapshot of current view on cluster. This class
|
||||
* is about tracking cluster attributes up in zookeeper.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue