diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerLoad.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerLoad.java index 2a56e57cef2..7509a8511af 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerLoad.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerLoad.java @@ -23,6 +23,7 @@ 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; @@ -403,7 +404,7 @@ public class ServerLoad implements ServerMetrics { } @Override - public List getCoprocessorNames() { + public Set getCoprocessorNames() { return metrics.getCoprocessorNames(); } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerMetrics.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerMetrics.java index 1ef3126de3c..f33e9782054 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerMetrics.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerMetrics.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase; import edu.umd.cs.findbugs.annotations.Nullable; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.hadoop.hbase.replication.ReplicationLoadSink; import org.apache.hadoop.hbase.replication.ReplicationLoadSource; import org.apache.yetus.audience.InterfaceAudience; @@ -73,9 +74,9 @@ public interface ServerMetrics { /** * Return the RegionServer-level and Region-level coprocessors - * @return string list of loaded RegionServer-level and Region-level coprocessors + * @return string set of loaded RegionServer-level and Region-level coprocessors */ - List getCoprocessorNames(); + Set getCoprocessorNames(); /** * @return the timestamp (server side) of generating this metrics diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerMetricsBuilder.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerMetricsBuilder.java index e501c439806..2d71f80ac96 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerMetricsBuilder.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerMetricsBuilder.java @@ -18,10 +18,13 @@ package org.apache.hadoop.hbase; import edu.umd.cs.findbugs.annotations.Nullable; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import java.util.stream.Collectors; import org.apache.hadoop.hbase.replication.ReplicationLoadSink; import org.apache.hadoop.hbase.replication.ReplicationLoadSource; @@ -73,7 +76,7 @@ public final class ServerMetricsBuilder { .build(); } - public static List toCoprocessor(List names) { + public static List toCoprocessor(Collection names) { return names.stream() .map(n -> HBaseProtos.Coprocessor.newBuilder().setName(n).build()) .collect(Collectors.toList()); @@ -116,7 +119,7 @@ public final class ServerMetricsBuilder { @Nullable private ReplicationLoadSink sink = null; private final Map regionStatus = new TreeMap<>(Bytes.BYTES_COMPARATOR); - private List coprocessorNames = Collections.emptyList(); + private final Set coprocessorNames = new TreeSet<>(); private long reportTimestamp = System.currentTimeMillis(); private long lastReportTimestamp = 0; private ServerMetricsBuilder(ServerName serverName) { @@ -164,7 +167,7 @@ public final class ServerMetricsBuilder { } public ServerMetricsBuilder setCoprocessorNames(List value) { - this.coprocessorNames = value; + coprocessorNames.addAll(value); return this; } @@ -205,14 +208,14 @@ public final class ServerMetricsBuilder { @Nullable private final ReplicationLoadSink sink; private final Map regionStatus; - private final List coprocessorNames; + private final Set coprocessorNames; private final long reportTimestamp; private final long lastReportTimestamp; ServerMetricsImpl(ServerName serverName, long requestCountPerSecond, long requestCount, Size usedHeapSize, Size maxHeapSize, int infoServerPort, List sources, ReplicationLoadSink sink, Map regionStatus, - List coprocessorNames, long reportTimestamp, long lastReportTimestamp) { + Set coprocessorNames, long reportTimestamp, long lastReportTimestamp) { this.serverName = Preconditions.checkNotNull(serverName); this.requestCountPerSecond = requestCountPerSecond; this.requestCount = requestCount; @@ -272,8 +275,8 @@ public final class ServerMetricsBuilder { } @Override - public List getCoprocessorNames() { - return Collections.unmodifiableList(coprocessorNames); + public Set getCoprocessorNames() { + return Collections.unmodifiableSet(coprocessorNames); } @Override diff --git a/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorTableEndpoint.java b/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorTableEndpoint.java index 07831319b19..cd022de8005 100644 --- a/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorTableEndpoint.java +++ b/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorTableEndpoint.java @@ -73,7 +73,7 @@ public class TestCoprocessorTableEndpoint { } @Test - public void testCoprocessorTableEndpoint() throws Throwable { + public void testCoprocessorTableEndpoint() throws Throwable { final TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor desc = new HTableDescriptor(tableName);