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.RegionInfo;
import org.apache.hadoop.hbase.metrics.MetricRegistry;
import org.apache.hadoop.hbase.regionserver.OnlineRegions;
import org.apache.hadoop.hbase.regionserver.Region;
import org.apache.yetus.audience.InterfaceAudience;
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 */
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 */
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.client.Connection;
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.InterfaceStability;
@ -35,6 +36,11 @@ public interface RegionServerCoprocessorEnvironment
*/
ServerName getServerName();
/**
* @return Interface to Map of regions online on this RegionServer {@link #getServerName()}}.
*/
OnlineRegions getOnlineRegions();
/**
* 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

View File

@ -18,43 +18,27 @@
*/
package org.apache.hadoop.hbase.regionserver;
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ServerName;
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
* encoded name and the value is an {@link Region} instance.
*/
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
@InterfaceStability.Evolving
public interface ImmutableOnlineRegions {
@InterfaceAudience.Private
public interface MutableOnlineRegions extends OnlineRegions {
/**
* Return {@link Region} instance.
* 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.
* Add to online regions.
* @param r
*/
Region getRegion(String encodedRegionName);
void addRegion(final HRegion r);
/**
* Get all online regions of a table in this RS.
* @param tableName
* @return List of Region
* @throws java.io.IOException
*/
List<? extends Region> getRegions(TableName tableName) throws IOException;
/**
* Get all online regions in this RS.
* @return List of online Region
*/
List<? extends Region> getRegions();
/**
* Removes the given Region from the list of onlineRegions.
* @param r Region to remove.
* @param destination Destination, if any, null otherwise.
* @return True if we removed a region from online list.
*/
boolean removeRegion(final HRegion r, ServerName destination);
}

View File

@ -18,28 +18,43 @@
*/
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.InterfaceStability;
/**
* 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.
* Provides read-only access to the Regions presently online on the
* current RegionServer
*/
@InterfaceAudience.Private
public interface OnlineRegions extends ImmutableOnlineRegions {
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
@InterfaceStability.Evolving
public interface OnlineRegions {
/**
* Add to online regions.
* @param r
* Return {@link Region} instance.
* 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.
*
* @param r Region to remove.
* @param destination Destination, if any, null otherwise.
* @return True if we removed a region from online list.
*/
boolean removeRegion(final HRegion r, ServerName destination);
/**
* Get all online regions of a table in this RS.
* @param tableName
* @return List of Region
* @throws java.io.IOException
*/
List<? extends Region> getRegions(TableName tableName) throws IOException;
/**
* 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 Connection connection;
private final ServerName serverName;
private final OnlineRegions onlineRegions;
/**
* Constructor
@ -132,6 +133,7 @@ public class RegionCoprocessorHost
this.connection = services != null? services.getConnection(): null;
this.serverName = services != null? services.getServerName(): null;
this.sharedData = sharedData;
this.onlineRegions = services;
this.metricRegistry =
MetricsCoprocessor.createRegistryForRegionCoprocessor(impl.getClass().getName());
}
@ -142,6 +144,10 @@ public class RegionCoprocessorHost
return region;
}
public OnlineRegions getOnlineRegions() {
return this.onlineRegions;
}
@Override
public Connection getConnection() {
return this.connection;

View File

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

View File

@ -48,7 +48,7 @@ import com.google.protobuf.Service;
* the code base.
*/
@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
* default (common) WAL */

View File

@ -121,7 +121,7 @@ public class OpenRegionHandler extends EventHandler {
return;
}
// Successful region open, and add it to OnlineRegions
// Successful region open, and add it to MutableOnlineRegions
this.rsServices.addRegion(region);
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.protobuf.generated.AuthenticationProtos;
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.security.SecurityInfo;
import org.apache.hadoop.hbase.security.User;
@ -272,6 +273,11 @@ public class TestTokenAuthentication {
@Override
public HRegion getRegion() { return null; }
@Override
public OnlineRegions getOnlineRegions() {
return null;
}
@Override
public void startup() throws IOException {}