HBASE-3522 Unbundle our RPC versioning; rather than a global for all 4 Interfaces -- region, master, region to master, and coprocesssors -- instead version each individually

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1069551 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-02-10 20:12:19 +00:00
parent 6988077609
commit e692a54414
11 changed files with 85 additions and 41 deletions

View File

@ -69,6 +69,9 @@ Release 0.91.0 - Unreleased
HBASE-3305 Allow round-robin distribution for table created with
multiple regions (ted yu via jgray)
HBASE-3496 HFile CLI Improvements
HBASE-3522 Unbundle our RPC versioning; rather than a global for all 4
Interfaces -- region, master, region to master, and
coprocesssors -- instead version each individually
NEW FEATURES

View File

@ -349,7 +349,7 @@ public class HConnectionManager {
}
HMasterInterface tryMaster = (HMasterInterface)HBaseRPC.getProxy(
HMasterInterface.class, HBaseRPCProtocolVersion.versionID,
HMasterInterface.class, HMasterInterface.VERSION,
masterLocation.getInetSocketAddress(), this.conf, this.rpcTimeout);
if (tryMaster.isMasterRunning()) {
@ -945,7 +945,7 @@ public class HConnectionManager {
if (server == null) { // Get a connection
try {
server = (HRegionInterface)HBaseRPC.waitForProxy(
serverInterfaceClass, HBaseRPCProtocolVersion.versionID,
serverInterfaceClass, HRegionInterface.VERSION,
regionServer.getInetSocketAddress(), this.conf,
this.maxRPCAttempts, this.rpcTimeout, this.rpcTimeout);
} catch (RemoteException e) {

View File

@ -19,8 +19,7 @@ package org.apache.hadoop.hbase.coprocessor;
import java.io.IOException;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.ipc.VersionedProtocol;
/**
* This abstract class provides default implementation of an Endpoint.
@ -33,15 +32,17 @@ import org.apache.hadoop.hbase.regionserver.HRegion;
* the region related resource, i.e., CoprocessorEnvironment.
*/
public abstract class BaseEndpointCoprocessor implements Coprocessor,
CoprocessorProtocol {
private CoprocessorEnvironment env;
CoprocessorProtocol, VersionedProtocol {
/**
* @param e Coprocessor environment.
* This Interfaces' version. Version changes when the Interface changes.
*/
private void setEnvironment(CoprocessorEnvironment e) {
env = e;
}
// All HBase Interfaces used derive from HBaseRPCProtocolVersion. It
// maintained a single global version number on all HBase Interfaces. This
// meant all HBase RPC was broke though only one of the three RPC Interfaces
// had changed. This has since been undone.
public static final long VERSION = 28L;
private CoprocessorEnvironment env;
/**
* @return env Coprocessor environment.
@ -59,7 +60,8 @@ public abstract class BaseEndpointCoprocessor implements Coprocessor,
public void stop(CoprocessorEnvironment env) { }
@Override
public long getProtocolVersion(String protocol, long clientVersion) throws IOException {
return HBaseRPCProtocolVersion.versionID;
public long getProtocolVersion(String protocol, long clientVersion)
throws IOException {
return VERSION;
}
}

View File

@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.ipc;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.ipc.VersionedProtocol;
import org.apache.hadoop.metrics.MetricsContext;
import org.apache.hadoop.metrics.MetricsRecord;
import org.apache.hadoop.metrics.MetricsUtil;
@ -79,7 +80,7 @@ public class HBaseRpcMetrics implements Updater {
//public Map <String, MetricsTimeVaryingRate> metricsList = Collections.synchronizedMap(new HashMap<String, MetricsTimeVaryingRate>());
private void initMethods(Class<? extends HBaseRPCProtocolVersion> protocol) {
private void initMethods(Class<? extends VersionedProtocol> protocol) {
for (Method m : protocol.getDeclaredMethods()) {
if (get(m.getName()) == null)
create(m.getName());

View File

@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.UnknownRegionException;
import org.apache.hadoop.ipc.VersionedProtocol;
/**
* Clients interact with the HMasterInterface to gain access to meta-level
@ -35,7 +36,15 @@ import org.apache.hadoop.hbase.UnknownRegionException;
* number in HBaseRPCProtocolVersion
*
*/
public interface HMasterInterface extends HBaseRPCProtocolVersion {
public interface HMasterInterface extends VersionedProtocol {
/**
* This Interfaces' version. Version changes when the Interface changes.
*/
// All HBase Interfaces used derive from HBaseRPCProtocolVersion. It
// maintained a single global version number on all HBase Interfaces. This
// meant all HBase RPC was broke though only one of the three RPC Interfaces
// had changed. This has since been undone.
public static final long VERSION = 28L;
/** @return true if master is available */
public boolean isMasterRunning();

View File

@ -23,6 +23,7 @@ import org.apache.hadoop.hbase.HMsg;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HServerInfo;
import org.apache.hadoop.io.MapWritable;
import org.apache.hadoop.ipc.VersionedProtocol;
import java.io.IOException;
@ -35,7 +36,15 @@ import java.io.IOException;
* number in HBaseRPCProtocolVersion
*
*/
public interface HMasterRegionInterface extends HBaseRPCProtocolVersion {
public interface HMasterRegionInterface extends VersionedProtocol {
/**
* This Interfaces' version. Version changes when the Interface changes.
*/
// All HBase Interfaces used derive from HBaseRPCProtocolVersion. It
// maintained a single global version number on all HBase Interfaces. This
// meant all HBase RPC was broke though only one of the three RPC Interfaces
// had changed. This has since been undone.
public static final long VERSION = 28L;
/**
* Called when a region server first starts

View File

@ -22,7 +22,6 @@ package org.apache.hadoop.hbase.ipc;
import java.io.IOException;
import java.net.ConnectException;
import java.util.List;
import java.util.NavigableSet;
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.HRegionInfo;
@ -30,8 +29,6 @@ import org.apache.hadoop.hbase.HServerInfo;
import org.apache.hadoop.hbase.NotServingRegionException;
import org.apache.hadoop.hbase.Stoppable;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.coprocessor.Exec;
import org.apache.hadoop.hbase.client.coprocessor.ExecResult;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Increment;
import org.apache.hadoop.hbase.client.MultiAction;
@ -41,8 +38,11 @@ import org.apache.hadoop.hbase.client.MultiResponse;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.coprocessor.Exec;
import org.apache.hadoop.hbase.client.coprocessor.ExecResult;
import org.apache.hadoop.hbase.regionserver.wal.HLog;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.ipc.VersionedProtocol;
/**
* Clients interact with HRegionServers using a handle to the HRegionInterface.
@ -50,7 +50,16 @@ import org.apache.hadoop.ipc.RemoteException;
* <p>NOTE: if you change the interface, you must change the RPC version
* number in HBaseRPCProtocolVersion
*/
public interface HRegionInterface extends HBaseRPCProtocolVersion, Stoppable, Abortable {
public interface HRegionInterface extends VersionedProtocol, Stoppable, Abortable {
/**
* This Interfaces' version. Version changes when the Interface changes.
*/
// All HBase Interfaces used derive from HBaseRPCProtocolVersion. It
// maintained a single global version number on all HBase Interfaces. This
// meant all HBase RPC was broke though only one of the three RPC Interfaces
// had changed. This has since been undone.
public static final long VERSION = 28L;
/**
* Get metainfo about an HRegion
*

View File

@ -60,7 +60,6 @@ import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
import org.apache.hadoop.hbase.executor.ExecutorService;
import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorType;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
import org.apache.hadoop.hbase.ipc.HBaseServer;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.HMasterRegionInterface;
@ -472,7 +471,7 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server {
}
public long getProtocolVersion(String protocol, long clientVersion) {
return HBaseRPCProtocolVersion.versionID;
return HMasterInterface.VERSION;
}
/** @return InfoServer object. Maybe null.*/

View File

@ -101,7 +101,6 @@ import org.apache.hadoop.hbase.io.hfile.LruBlockCache.CacheStats;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.ipc.HBaseRPCErrorHandler;
import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
import org.apache.hadoop.hbase.ipc.HBaseRpcMetrics;
import org.apache.hadoop.hbase.ipc.HMasterRegionInterface;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
@ -1447,7 +1446,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
// Do initial RPC setup. The final argument indicates that the RPC
// should retry indefinitely.
master = (HMasterRegionInterface) HBaseRPC.waitForProxy(
HMasterRegionInterface.class, HBaseRPCProtocolVersion.versionID,
HMasterRegionInterface.class, HMasterRegionInterface.VERSION,
masterAddress.getInetSocketAddress(), this.conf, -1,
this.rpcTimeout, this.rpcTimeout);
} catch (IOException e) {
@ -2452,7 +2451,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
public long getProtocolVersion(final String protocol, final long clientVersion)
throws IOException {
if (protocol.equals(HRegionInterface.class.getName())) {
return HBaseRPCProtocolVersion.versionID;
return HRegionInterface.VERSION;
}
throw new IOException("Unknown protocol to name node: " + protocol);
}

View File

@ -28,7 +28,6 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.ipc.RemoteException;
import org.junit.Test;
@ -48,7 +47,7 @@ public class TestHMasterRPCException {
try {
HMasterInterface inf =
(HMasterInterface) HBaseRPC.getProxy(
HMasterInterface.class, HBaseRPCProtocolVersion.versionID,
HMasterInterface.class, HMasterInterface.VERSION,
hma.getInetSocketAddress(), conf, 100);
inf.isMasterRunning();
fail();

View File

@ -19,22 +19,35 @@
*/
package org.apache.hadoop.hbase.regionserver;
import com.google.common.collect.Lists;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.client.coprocessor.Batch;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
import org.junit.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.MiniHBaseCluster;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.coprocessor.Batch;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
import org.apache.hadoop.ipc.VersionedProtocol;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.common.collect.Lists;
public class TestServerCustomProtocol {
/* Test protocol */
private static interface PingProtocol extends CoprocessorProtocol {
@ -45,8 +58,9 @@ public class TestServerCustomProtocol {
}
/* Test protocol implementation */
private static class PingHandler implements PingProtocol,
HBaseRPCProtocolVersion {
private static class PingHandler implements PingProtocol, VersionedProtocol {
static int VERSION = 1;
private int counter = 0;
@Override
public String ping() {
@ -72,7 +86,7 @@ public class TestServerCustomProtocol {
@Override
public long getProtocolVersion(String s, long l) throws IOException {
return versionID;
return VERSION;
}
}