HBASE-2219 stop using code mapping for method names in the RPC

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@910316 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan Rawson 2010-02-15 19:47:14 +00:00
parent e743a52a0c
commit 8ccacf36a7
9 changed files with 3 additions and 180 deletions

View File

@ -10,6 +10,7 @@ Release 0.21.0 - Unreleased
HBASE-1360 move up to Thrift 0.2.0 (Kay Kay and Lars Francke via Stack)
HBASE-2212 Refactor out lucene dependencies from HBase
(Kay Kay via Stack)
HBASE-2219 stop using code mapping for method names in the RPC
BUG FIXES
HBASE-1791 Timeout in IndexRecordWriter (Bradford Stephens via Andrew

View File

@ -1,42 +0,0 @@
/**
* Copyright 2010 The Apache Software Foundation
*
* 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
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.ipc;
/**
* Helper class to add RPC-related configs for replication
*/
public class ReplicationRPC {
private static final byte RPC_CODE = 110;
private static boolean initialized = false;
public synchronized static void initialize() {
if (initialized) {
return;
}
HBaseRPC.addToMap(ReplicationRegionInterface.class, RPC_CODE);
initialized = true;
}
private ReplicationRPC() {
// Static helper class;
}
}

View File

@ -26,7 +26,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
import org.apache.hadoop.hbase.ipc.ReplicationRPC;
import org.apache.hadoop.hbase.ipc.ReplicationRegionInterface;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
@ -43,10 +42,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class ReplicationRegionServer extends HRegionServer
implements ReplicationRegionInterface {
static {
ReplicationRPC.initialize();
}
protected static final Log LOG =
LogFactory.getLog(ReplicationRegionServer.class);

View File

@ -36,10 +36,6 @@ import org.apache.hadoop.hbase.ipc.TransactionalRegionInterface;
*
*/
public class TransactionManager {
static {
TransactionalRPC.initialize();
}
static final Log LOG = LogFactory.getLog(TransactionManager.class);
private final HConnection connection;

View File

@ -1,27 +0,0 @@
package org.apache.hadoop.hbase.client.transactional;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.ipc.TransactionalRegionInterface;
/** Simple class for registering the transactional RPC codes.
*
*/
public final class TransactionalRPC {
private static final byte RPC_CODE = 100;
private static boolean initialized = false;
public synchronized static void initialize() {
if (initialized) {
return;
}
HBaseRPC.addToMap(TransactionalRegionInterface.class, RPC_CODE);
initialized = true;
}
private TransactionalRPC() {
// Static helper class;
}
}

View File

@ -41,10 +41,6 @@ import org.apache.hadoop.hbase.util.Bytes;
*/
public class TransactionalTable extends HTable {
static {
TransactionalRPC.initialize();
}
/**
* @param conf
* @param tableName

View File

@ -36,7 +36,6 @@ import org.apache.hadoop.hbase.client.Get;
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.transactional.TransactionalRPC;
import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
import org.apache.hadoop.hbase.ipc.TransactionalRegionInterface;
import org.apache.hadoop.hbase.regionserver.wal.HLog;
@ -54,10 +53,6 @@ import org.apache.hadoop.util.Progressable;
*/
public class TransactionalRegionServer extends HRegionServer implements
TransactionalRegionInterface {
static {
TransactionalRPC.initialize();
}
private static final String LEASE_TIME = "hbase.transaction.leasetime";
private static final int DEFAULT_LEASE_TIME = 60 * 1000;

View File

@ -85,59 +85,8 @@ public class HBaseRPC {
super();
} // no public ctor
// Special code that means 'not-encoded'.
private static final byte NOT_ENCODED = 0;
private static byte code = NOT_ENCODED + 1;
/** Add a new interface to the ipc map.
* @param c Class whose methods we'll add to the map of methods to codes
* (and vice versa).
* @param startCode Current state of the byte code.
* @return State of <code>code</code> when this method is done.
*/
public static byte addToMap(final Class<?> c, final byte startCode) {
if (Invocation.CODE_TO_METHODNAME.get(startCode) != null) {
throw new IllegalArgumentException("Code " + startCode +
"already had entry");
}
byte localCode = startCode;
Method [] methods = c.getMethods();
// There are no guarantees about the order in which items are returned in
// so do a sort (Was seeing that sort was one way on one server and then
// another on different server).
Arrays.sort(methods, new Comparator<Method>() {
public int compare(Method left, Method right) {
return left.getName().compareTo(right.getName());
}
});
for (int i = 0; i < methods.length; i++) {
Invocation.addToMap(methods[i].getName(), localCode++);
}
return localCode;
}
static Collection<String> getMappedMethodNames() {
return Invocation.CODE_TO_METHODNAME.values();
}
static {
code = HBaseRPC.addToMap(VersionedProtocol.class, code);
code = HBaseRPC.addToMap(HMasterInterface.class, code);
code = HBaseRPC.addToMap(HMasterRegionInterface.class, code);
code = HBaseRPC.addToMap(HRegionInterface.class, code);
}
/** A method invocation, including the method name and its parameters.*/
private static class Invocation implements Writable, Configurable {
// Here, for hbase, we maintain two static maps of method names to code and
// vice versa.
static final Map<Byte, String> CODE_TO_METHODNAME =
new HashMap<Byte, String>();
private static final Map<String, Byte> METHODNAME_TO_CODE =
new HashMap<String, Byte>();
// End of hbase modifications.
private String methodName;
@SuppressWarnings("unchecked")
private Class[] parameterClasses;
@ -170,8 +119,7 @@ public class HBaseRPC {
public Object[] getParameters() { return parameters; }
public void readFields(DataInput in) throws IOException {
byte code = in.readByte();
methodName = CODE_TO_METHODNAME.get(Byte.valueOf(code));
methodName = in.readUTF();
parameters = new Object[in.readInt()];
parameterClasses = new Class[parameters.length];
HbaseObjectWritable objectWritable = new HbaseObjectWritable();
@ -183,7 +131,7 @@ public class HBaseRPC {
}
public void write(DataOutput out) throws IOException {
writeMethodNameCode(out, this.methodName);
out.writeUTF(this.methodName);
out.writeInt(parameterClasses.length);
for (int i = 0; i < parameterClasses.length; i++) {
HbaseObjectWritable.writeObject(out, parameters[i], parameterClasses[i],
@ -212,34 +160,6 @@ public class HBaseRPC {
public Configuration getConf() {
return this.conf;
}
// Hbase additions.
static void addToMap(final String name, final byte code) {
if (METHODNAME_TO_CODE.containsKey(name)) {
return;
}
METHODNAME_TO_CODE.put(name, Byte.valueOf(code));
CODE_TO_METHODNAME.put(Byte.valueOf(code), name);
}
/*
* Write out the code byte for passed Class.
* @param out
* @param c
* @throws IOException
*/
static void writeMethodNameCode(final DataOutput out, final String methodname)
throws IOException {
Byte code = METHODNAME_TO_CODE.get(methodname);
if (code == null) {
LOG.error("Unsupported type " + methodname);
throw new UnsupportedOperationException("No code for unexpected " +
methodname);
}
out.writeByte(code.byteValue());
}
// End of hbase additions.
}
/* Cache a client using its socket factory as the hash key */

View File

@ -54,7 +54,6 @@ public class HBaseRpcMetrics implements Updater {
context.registerUpdater(this);
this.initMethods();
rpcStatistics = new HBaseRPCStatistics(this.registry, hostName, port);
}
@ -71,16 +70,6 @@ public class HBaseRpcMetrics implements Updater {
//public Map <String, MetricsTimeVaryingRate> metricsList = Collections.synchronizedMap(new HashMap<String, MetricsTimeVaryingRate>());
/**
* Register metrics for all know RPC methods ahead of time. This helps with
* JMX usage, where trying to retrieve the RPC-method metrics before they're
* incremented could otherwise cause spurious AttributeNotFoundExceptions.
*/
private void initMethods() {
for (String name : HBaseRPC.getMappedMethodNames()) {
create(name);
}
}
private MetricsTimeVaryingRate get(String key) {
return (MetricsTimeVaryingRate) registry.get(key);