HBASE-9382 replicateWALEntry doesn't use the replication handlers

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1519017 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-08-30 16:28:40 +00:00
parent db28d97206
commit 345405ea4d
3 changed files with 72 additions and 5 deletions

View File

@ -133,10 +133,10 @@ public class SimpleRpcScheduler implements RpcScheduler {
RpcServer.Call call = callTask.getCall();
Pair<RPCProtos.RequestHeader, Message> headerAndParam =
new Pair<RPCProtos.RequestHeader, Message>(call.header, call.param);
if (priorityCallQueue != null && getQosLevel(headerAndParam) > highPriorityLevel) {
int level = getQosLevel(headerAndParam);
if (priorityCallQueue != null && level > highPriorityLevel) {
priorityCallQueue.put(callTask);
} else if (replicationQueue != null &&
getQosLevel(headerAndParam) == HConstants.REPLICATION_QOS) {
} else if (replicationQueue != null && level == HConstants.REPLICATION_QOS) {
replicationQueue.put(callTask);
} else {
callQueue.put(callTask); // queue the call; maybe blocked here

View File

@ -99,7 +99,13 @@ class QosFunction implements Function<Pair<RequestHeader, Message>, Integer> {
for (Method m : HRegionServer.class.getMethods()) {
QosPriority p = m.getAnnotation(QosPriority.class);
if (p != null) {
qosMap.put(m.getName(), p.priority());
// Since we protobuf'd, and then subsequently, when we went with pb style, method names
// are capitalized. This meant that this brittle compare of method names gotten by
// reflection no longer matched the method names comeing in over pb. TODO: Get rid of this
// check. For now, workaround is to capitalize the names we got from reflection so they
// have chance of matching the pb ones.
String capitalizedMethodName = capitalize(m.getName());
qosMap.put(capitalizedMethodName, p.priority());
}
}
this.annotatedQos = qosMap;
@ -119,6 +125,12 @@ class QosFunction implements Function<Pair<RequestHeader, Message>, Integer> {
}
}
private String capitalize(final String s) {
StringBuilder strBuilder = new StringBuilder(s);
strBuilder.setCharAt(0, Character.toUpperCase(strBuilder.charAt(0)));
return strBuilder.toString();
}
public boolean isMetaRegion(byte[] regionName) {
HRegion region;
try {
@ -133,7 +145,7 @@ class QosFunction implements Function<Pair<RequestHeader, Message>, Integer> {
public Integer apply(Pair<RequestHeader, Message> headerAndParam) {
RequestHeader header = headerAndParam.getFirst();
String methodName = header.getMethodName();
Integer priorityByAnnotation = annotatedQos.get(header.getMethodName());
Integer priorityByAnnotation = annotatedQos.get(methodName);
if (priorityByAnnotation != null) {
return priorityByAnnotation;
}

View File

@ -0,0 +1,55 @@
package org.apache.hadoop.hbase.regionserver;
/**
* 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.
*/
import static org.junit.Assert.assertEquals;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.SmallTests;
import org.apache.hadoop.hbase.protobuf.generated.RPCProtos.RequestHeader;
import org.apache.hadoop.hbase.util.Pair;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
import com.google.protobuf.Message;
/**
* Basic test that qos function is sort of working; i.e. a change in method naming style
* over in pb doesn't break it.
*/
@Category(SmallTests.class)
public class TestQosFunction {
@Test
public void testPriority() {
HRegionServer hrs = Mockito.mock(HRegionServer.class);
QosFunction qosFunction = new QosFunction(hrs);
// Set method name in pb style with the method name capitalized.
checkMethod("ReplicateWALEntry", HConstants.REPLICATION_QOS, qosFunction);
// Set method name in pb style with the method name capitalized.
checkMethod("OpenRegion", HConstants.HIGH_QOS, qosFunction);
}
private void checkMethod(final String methodName, final int expected, final QosFunction qosf) {
RequestHeader.Builder builder = RequestHeader.newBuilder();
builder.setMethodName(methodName);
Pair<RequestHeader, Message> headerAndParam =
new Pair<RequestHeader, Message>(builder.build(), null);
assertEquals(methodName, expected, qosf.apply(headerAndParam).intValue());
}
}