diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java index 1c246a1..c3021cc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java @@ -133,10 +133,10 @@ public class SimpleRpcScheduler implements RpcScheduler { RpcServer.Call call = callTask.getCall(); Pair headerAndParam = new Pair(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 diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java index e4ff9f5..b3775e9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java @@ -99,7 +99,13 @@ class QosFunction implements Function, 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, 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, Integer> { public Integer apply(Pair 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; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java new file mode 100644 index 0000000..c4983ea --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java @@ -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 headerAndParam = + new Pair(builder.build(), null); + assertEquals(methodName, expected, qosf.apply(headerAndParam).intValue()); + } +} \ No newline at end of file