From 4f3b95b318996aae4f25c78fb1fcc20b8fd80b24 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Thu, 24 Jan 2019 18:31:32 +0800 Subject: [PATCH] HBASE-21762 Move some methods in ClusterConnection to Connection Signed-off-by: Peter Somogyi --- .../hbase/client/ClusterConnection.java | 39 ++------------ .../hadoop/hbase/client/Connection.java | 54 +++++++++++++++++-- .../client/ConnectionImplementation.java | 3 +- .../TestMultiTableInputFormatBase.java | 4 ++ .../mapreduce/TestTableInputFormatBase.java | 4 ++ .../apache/hadoop/hbase/SharedConnection.java | 17 +++++- .../hadoop/hbase/HBaseTestingUtility.java | 3 +- .../regionserver/TestWALEntrySinkFilter.java | 4 ++ .../thrift2/client/ThriftConnection.java | 5 ++ 9 files changed, 92 insertions(+), 41 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java index d3e675c1eb9..9b2222b9f42 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java @@ -107,9 +107,12 @@ public interface ClusterConnection extends Connection { final byte [] row) throws IOException; /** - * Allows flushing the region cache. + * @deprecated {@link #clearRegionLocationCache()} instead. */ - void clearRegionCache(); + @Deprecated + default void clearRegionCache() { + clearRegionLocationCache(); + } void cacheLocation(final TableName tableName, final RegionLocations location); @@ -326,36 +329,4 @@ public interface ClusterConnection extends Connection { * @throws IOException if a remote or network exception occurs */ int getCurrentNrHRS() throws IOException; - - /** - * Retrieve an Hbck implementation to fix an HBase cluster. - * The returned Hbck is not guaranteed to be thread-safe. A new instance should be created by - * each thread. This is a lightweight operation. Pooling or caching of the returned Hbck instance - * is not recommended. - *
- * The caller is responsible for calling {@link Hbck#close()} on the returned Hbck instance. - *
- * This will be used mostly by hbck tool. - * - * @return an Hbck instance for active master. Active master is fetched from the zookeeper. - */ - Hbck getHbck() throws IOException; - - /** - * Retrieve an Hbck implementation to fix an HBase cluster. - * The returned Hbck is not guaranteed to be thread-safe. A new instance should be created by - * each thread. This is a lightweight operation. Pooling or caching of the returned Hbck instance - * is not recommended. - *
- * The caller is responsible for calling {@link Hbck#close()} on the returned Hbck instance. - *
- * This will be used mostly by hbck tool. This may only be used to by pass getting - * registered master from ZK. In situations where ZK is not available or active master is not - * registered with ZK and user can get master address by other means, master can be explicitly - * specified. - * - * @param masterServer explicit {@link ServerName} for master server - * @return an Hbck instance for a specified master server - */ - Hbck getHbck(ServerName masterServer) throws IOException; } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Connection.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Connection.java index 1d28777ee08..90891f411ba 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Connection.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Connection.java @@ -1,5 +1,4 @@ -/* - * +/** * 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 @@ -21,9 +20,10 @@ package org.apache.hadoop.hbase.client; import java.io.Closeable; import java.io.IOException; import java.util.concurrent.ExecutorService; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Abortable; +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.yetus.audience.InterfaceAudience; @@ -154,6 +154,16 @@ public interface Connection extends Abortable, Closeable { */ RegionLocator getRegionLocator(TableName tableName) throws IOException; + /** + * Clear all the entries in the region location cache, for all the tables. + *

+ * If you only want to clear the cache for a specific table, use + * {@link RegionLocator#clearRegionLocationCache()}. + *

+ * This may cause performance issue so use it with caution. + */ + void clearRegionLocationCache(); + /** * Retrieve an Admin implementation to administer an HBase cluster. * The returned Admin is not guaranteed to be thread-safe. A new instance should be created for @@ -182,4 +192,42 @@ public interface Connection extends Abortable, Closeable { * @param pool the thread pool to use for requests like batch and scan */ TableBuilder getTableBuilder(TableName tableName, ExecutorService pool); + + /** + * Retrieve an Hbck implementation to fix an HBase cluster. + * The returned Hbck is not guaranteed to be thread-safe. A new instance should be created by + * each thread. This is a lightweight operation. Pooling or caching of the returned Hbck instance + * is not recommended. + *
+ * The caller is responsible for calling {@link Hbck#close()} on the returned Hbck instance. + *
+ * This will be used mostly by hbck tool. + * + * @return an Hbck instance for active master. Active master is fetched from the zookeeper. + */ + @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.HBCK) + default Hbck getHbck() throws IOException { + throw new UnsupportedOperationException("Not implemented"); + } + + /** + * Retrieve an Hbck implementation to fix an HBase cluster. + * The returned Hbck is not guaranteed to be thread-safe. A new instance should be created by + * each thread. This is a lightweight operation. Pooling or caching of the returned Hbck instance + * is not recommended. + *
+ * The caller is responsible for calling {@link Hbck#close()} on the returned Hbck instance. + *
+ * This will be used mostly by hbck tool. This may only be used to by pass getting + * registered master from ZK. In situations where ZK is not available or active master is not + * registered with ZK and user can get master address by other means, master can be explicitly + * specified. + * + * @param masterServer explicit {@link ServerName} for master server + * @return an Hbck instance for a specified master server + */ + @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.HBCK) + default Hbck getHbck(ServerName masterServer) throws IOException { + throw new UnsupportedOperationException("Not implemented"); + } } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java index e86052213a2..70f058805eb 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java @@ -89,6 +89,7 @@ import org.apache.hbase.thirdparty.com.google.common.base.Throwables; import org.apache.hbase.thirdparty.com.google.protobuf.BlockingRpcChannel; import org.apache.hbase.thirdparty.com.google.protobuf.RpcController; import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException; + import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter; import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos; @@ -993,7 +994,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable { } @Override - public void clearRegionCache() { + public void clearRegionLocationCache() { metaCache.clearCache(); } diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestMultiTableInputFormatBase.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestMultiTableInputFormatBase.java index efc59c7844a..906abca05c9 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestMultiTableInputFormatBase.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestMultiTableInputFormatBase.java @@ -236,5 +236,9 @@ public class TestMultiTableInputFormatBase { public TableBuilder getTableBuilder(TableName tableName, ExecutorService pool) { return Mockito.mock(TableBuilder.class); } + + @Override + public void clearRegionLocationCache() { + } } } diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableInputFormatBase.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableInputFormatBase.java index 29a92ee75c0..4436ee10918 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableInputFormatBase.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableInputFormatBase.java @@ -286,5 +286,9 @@ public class TestTableInputFormatBase { public TableBuilder getTableBuilder(TableName tableName, ExecutorService pool) { throw new UnsupportedOperationException(); } + + @Override + public void clearRegionLocationCache() { + } } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/SharedConnection.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/SharedConnection.java index 9ad55b71776..de0c39b422d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/SharedConnection.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/SharedConnection.java @@ -19,12 +19,12 @@ package org.apache.hadoop.hbase; import java.io.IOException; import java.util.concurrent.ExecutorService; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.BufferedMutator; import org.apache.hadoop.hbase.client.BufferedMutatorParams; import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.Hbck; import org.apache.hadoop.hbase.client.RegionLocator; import org.apache.hadoop.hbase.client.TableBuilder; import org.apache.yetus.audience.InterfaceAudience; @@ -90,4 +90,19 @@ public class SharedConnection implements Connection { public TableBuilder getTableBuilder(TableName tableName, ExecutorService pool) { return this.conn.getTableBuilder(tableName, pool); } + + @Override + public void clearRegionLocationCache() { + conn.clearRegionLocationCache(); + } + + @Override + public Hbck getHbck() throws IOException { + return conn.getHbck(); + } + + @Override + public Hbck getHbck(ServerName masterServer) throws IOException { + return conn.getHbck(masterServer); + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 796dbc30e4d..92ea58ea8e5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -64,7 +64,6 @@ import org.apache.hadoop.hbase.Waiter.ExplainingPredicate; import org.apache.hadoop.hbase.Waiter.Predicate; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.BufferedMutator; -import org.apache.hadoop.hbase.client.ClusterConnection; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Connection; @@ -3072,7 +3071,7 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { * Returns an {@link Hbck} instance. Needs be closed when done. */ public Hbck getHbck() throws IOException { - return ((ClusterConnection) getConnection()).getHbck(); + return getConnection().getHbck(); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntrySinkFilter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntrySinkFilter.java index fd9ff2924bb..aa624702877 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntrySinkFilter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntrySinkFilter.java @@ -546,6 +546,10 @@ public class TestWALEntrySinkFilter { } }; } + + @Override + public void clearRegionLocationCache() { + } } } diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/client/ThriftConnection.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/client/ThriftConnection.java index a0f902a8116..cc186aa8fee 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/client/ThriftConnection.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/client/ThriftConnection.java @@ -319,4 +319,9 @@ public class ThriftConnection implements Connection { public RegionLocator getRegionLocator(TableName tableName) throws IOException { throw new NotImplementedException("batchCoprocessorService not supported in ThriftTable"); } + + @Override + public void clearRegionLocationCache() { + throw new NotImplementedException("clearRegionLocationCache not supported in ThriftTable"); + } }