HBASE-19077 Have Region*CoprocessorEnvironment provide an ImmutableOnlineRegions

Change name of Interface OnlineRegions to MutableOnlineRegions.
Change name of Interface ImmutableOnlineRegions to OnlineRegions.
Did this since OnlineRegions is for consumer other than internals.

Add a getOnlineRegions to the RegionCoprocessorEnvironment and to
RegionServerCoprocessorEnvironment so CPs can 'access' local
Regions directly.
This commit is contained in:
Michael Stack 2017-10-24 15:37:32 -07:00
parent f6ba8185ea
commit 1b49081ed2
No known key found for this signature in database
GPG Key ID: 9816C7FC8ACC93D2
9 changed files with 77 additions and 47 deletions

View File

@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.metrics.MetricRegistry; import org.apache.hadoop.hbase.metrics.MetricRegistry;
import org.apache.hadoop.hbase.regionserver.OnlineRegions;
import org.apache.hadoop.hbase.regionserver.Region; import org.apache.hadoop.hbase.regionserver.Region;
import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability; import org.apache.yetus.audience.InterfaceStability;
@ -40,6 +41,11 @@ public interface RegionCoprocessorEnvironment extends CoprocessorEnvironment<Reg
/** @return region information for the region this coprocessor is running on */ /** @return region information for the region this coprocessor is running on */
RegionInfo getRegionInfo(); RegionInfo getRegionInfo();
/**
* @return Interface to Map of regions online on this RegionServer {@link #getServerName()}}.
*/
OnlineRegions getOnlineRegions();
/** @return shared data between all instances of this coprocessor */ /** @return shared data between all instances of this coprocessor */
ConcurrentMap<String, Object> getSharedData(); ConcurrentMap<String, Object> getSharedData();

View File

@ -23,6 +23,7 @@ import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.metrics.MetricRegistry; import org.apache.hadoop.hbase.metrics.MetricRegistry;
import org.apache.hadoop.hbase.regionserver.OnlineRegions;
import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability; import org.apache.yetus.audience.InterfaceStability;
@ -35,6 +36,11 @@ public interface RegionServerCoprocessorEnvironment
*/ */
ServerName getServerName(); ServerName getServerName();
/**
* @return Interface to Map of regions online on this RegionServer {@link #getServerName()}}.
*/
OnlineRegions getOnlineRegions();
/** /**
* Be careful RPC'ing from a Coprocessor context. * Be careful RPC'ing from a Coprocessor context.
* RPC's will fail, stall, retry, and/or crawl because the remote side is not online, is * RPC's will fail, stall, retry, and/or crawl because the remote side is not online, is

View File

@ -18,43 +18,27 @@
*/ */
package org.apache.hadoop.hbase.regionserver; package org.apache.hadoop.hbase.regionserver;
import java.io.IOException; import org.apache.hadoop.hbase.ServerName;
import java.util.List;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.TableName;
import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
/** /**
* Interface to Map of online regions. In the Map, the key is the region's * Interface to Map of online regions. In the Map, the key is the region's
* encoded name and the value is an {@link Region} instance. * encoded name and the value is an {@link Region} instance.
*/ */
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) @InterfaceAudience.Private
@InterfaceStability.Evolving public interface MutableOnlineRegions extends OnlineRegions {
public interface ImmutableOnlineRegions {
/** /**
* Return {@link Region} instance. * Add to online regions.
* Only works if caller is in same context, in same JVM. Region is not * @param r
* serializable.
* @param encodedRegionName
* @return Region for the passed encoded <code>encodedRegionName</code> or
* null if named region is not member of the online regions.
*/ */
Region getRegion(String encodedRegionName); void addRegion(final HRegion r);
/** /**
* Get all online regions of a table in this RS. * Removes the given Region from the list of onlineRegions.
* @param tableName * @param r Region to remove.
* @return List of Region * @param destination Destination, if any, null otherwise.
* @throws java.io.IOException * @return True if we removed a region from online list.
*/ */
List<? extends Region> getRegions(TableName tableName) throws IOException; boolean removeRegion(final HRegion r, ServerName destination);
/**
* Get all online regions in this RS.
* @return List of online Region
*/
List<? extends Region> getRegions();
} }

View File

@ -18,28 +18,43 @@
*/ */
package org.apache.hadoop.hbase.regionserver; package org.apache.hadoop.hbase.regionserver;
import org.apache.hadoop.hbase.ServerName; import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.TableName;
import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
/** /**
* Interface to Map of online regions. In the Map, the key is the region's * Provides read-only access to the Regions presently online on the
* encoded name and the value is an {@link Region} instance. * current RegionServer
*/ */
@InterfaceAudience.Private @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
public interface OnlineRegions extends ImmutableOnlineRegions { @InterfaceStability.Evolving
public interface OnlineRegions {
/** /**
* Add to online regions. * Return {@link Region} instance.
* @param r * Only works if caller is in same context, in same JVM. Region is not
* serializable.
* @param encodedRegionName
* @return Region for the passed encoded <code>encodedRegionName</code> or
* null if named region is not member of the online regions.
*/ */
void addRegion(final HRegion r); Region getRegion(String encodedRegionName);
/** /**
* This method removes Region corresponding to hri from the Map of onlineRegions. * Get all online regions of a table in this RS.
* * @param tableName
* @param r Region to remove. * @return List of Region
* @param destination Destination, if any, null otherwise. * @throws java.io.IOException
* @return True if we removed a region from online list. */
*/ List<? extends Region> getRegions(TableName tableName) throws IOException;
boolean removeRegion(final HRegion r, ServerName destination);
/**
* Get all online regions in this RS.
* @return List of online Region
*/
List<? extends Region> getRegions();
} }

View File

@ -117,6 +117,7 @@ public class RegionCoprocessorHost
private final MetricRegistry metricRegistry; private final MetricRegistry metricRegistry;
private final Connection connection; private final Connection connection;
private final ServerName serverName; private final ServerName serverName;
private final OnlineRegions onlineRegions;
/** /**
* Constructor * Constructor
@ -132,6 +133,7 @@ public class RegionCoprocessorHost
this.connection = services != null? services.getConnection(): null; this.connection = services != null? services.getConnection(): null;
this.serverName = services != null? services.getServerName(): null; this.serverName = services != null? services.getServerName(): null;
this.sharedData = sharedData; this.sharedData = sharedData;
this.onlineRegions = services;
this.metricRegistry = this.metricRegistry =
MetricsCoprocessor.createRegistryForRegionCoprocessor(impl.getClass().getName()); MetricsCoprocessor.createRegistryForRegionCoprocessor(impl.getClass().getName());
} }
@ -142,6 +144,10 @@ public class RegionCoprocessorHost
return region; return region;
} }
public OnlineRegions getOnlineRegions() {
return this.onlineRegions;
}
@Override @Override
public Connection getConnection() { public Connection getConnection() {
return this.connection; return this.connection;

View File

@ -206,6 +206,7 @@ public class RegionServerCoprocessorHost extends
private final MetricRegistry metricRegistry; private final MetricRegistry metricRegistry;
private final Connection connection; private final Connection connection;
private final ServerName serverName; private final ServerName serverName;
private final OnlineRegions onlineRegions;
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="BC_UNCONFIRMED_CAST", @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="BC_UNCONFIRMED_CAST",
justification="Intentional; FB has trouble detecting isAssignableFrom") justification="Intentional; FB has trouble detecting isAssignableFrom")
@ -216,12 +217,18 @@ public class RegionServerCoprocessorHost extends
for (Service service : impl.getServices()) { for (Service service : impl.getServices()) {
services.registerService(service); services.registerService(service);
} }
this.onlineRegions = services;
this.connection = services.getConnection(); this.connection = services.getConnection();
this.serverName = services.getServerName(); this.serverName = services.getServerName();
this.metricRegistry = this.metricRegistry =
MetricsCoprocessor.createRegistryForRSCoprocessor(impl.getClass().getName()); MetricsCoprocessor.createRegistryForRSCoprocessor(impl.getClass().getName());
} }
@Override
public OnlineRegions getOnlineRegions() {
return this.onlineRegions;
}
@Override @Override
public ServerName getServerName() { public ServerName getServerName() {
return this.serverName; return this.serverName;

View File

@ -48,7 +48,7 @@ import com.google.protobuf.Service;
* the code base. * the code base.
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public interface RegionServerServices extends Server, OnlineRegions, FavoredNodesForRegion { public interface RegionServerServices extends Server, MutableOnlineRegions, FavoredNodesForRegion {
/** @return the WAL for a particular region. Pass null for getting the /** @return the WAL for a particular region. Pass null for getting the
* default (common) WAL */ * default (common) WAL */

View File

@ -121,7 +121,7 @@ public class OpenRegionHandler extends EventHandler {
return; return;
} }
// Successful region open, and add it to OnlineRegions // Successful region open, and add it to MutableOnlineRegions
this.rsServices.addRegion(region); this.rsServices.addRegion(region);
openSuccessful = true; openSuccessful = true;

View File

@ -59,6 +59,7 @@ import org.apache.hadoop.hbase.ipc.SimpleRpcServer;
import org.apache.hadoop.hbase.metrics.MetricRegistry; import org.apache.hadoop.hbase.metrics.MetricRegistry;
import org.apache.hadoop.hbase.protobuf.generated.AuthenticationProtos; import org.apache.hadoop.hbase.protobuf.generated.AuthenticationProtos;
import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.OnlineRegions;
import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.security.SecurityInfo; import org.apache.hadoop.hbase.security.SecurityInfo;
import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.security.User;
@ -272,6 +273,11 @@ public class TestTokenAuthentication {
@Override @Override
public HRegion getRegion() { return null; } public HRegion getRegion() { return null; }
@Override
public OnlineRegions getOnlineRegions() {
return null;
}
@Override @Override
public void startup() throws IOException {} public void startup() throws IOException {}