hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1519017 - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java
Date Fri, 30 Aug 2013 16:28:40 GMT
Author: stack
Date: Fri Aug 30 16:28:40 2013
New Revision: 1519017

URL: http://svn.apache.org/r1519017
Log:
HBASE-9382 replicateWALEntry doesn't use the replication handlers

Added:
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java
Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java?rev=1519017&r1=1519016&r2=1519017&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java
Fri Aug 30 16:28:40 2013
@@ -133,10 +133,10 @@ public class SimpleRpcScheduler implemen
     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

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java?rev=1519017&r1=1519016&r2=1519017&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/QosFunction.java
Fri Aug 30 16:28:40 2013
@@ -99,7 +99,13 @@ class QosFunction implements Function<Pa
     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<Pa
     }
   }
 
+  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<Pa
   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;
     }

Added: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java?rev=1519017&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java
(added)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java
Fri Aug 30 16:28:40 2013
@@ -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());
+  }
+}
\ No newline at end of file



Mime
View raw message