1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.master;
19
20 import com.google.protobuf.Message;
21 import org.apache.hadoop.hbase.HConstants;
22 import org.apache.hadoop.hbase.TableName;
23 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
24 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
25 import org.apache.hadoop.hbase.protobuf.generated.RPCProtos;
26 import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos;
27 import org.apache.hadoop.hbase.regionserver.AnnotationReadingPriorityFunction;
28 import org.apache.hadoop.hbase.regionserver.RSRpcServices;
29 import org.apache.hadoop.hbase.security.User;
30
31 /**
32 * Priority function specifically for the master.
33 *
34 * This doesn't make the super users always priority since that would make everything
35 * to the master into high priority.
36 *
37 * Specifically when reporting that a region is in transition master will try and edit the meta
38 * table. That edit will block the thread until successful. However if at the same time meta is
39 * also moving then we need to ensure that the regular region that's moving isn't blocking
40 * processing of the request to online meta. To accomplish this this priority function makes sure
41 * that all requests to transition meta are handled in different threads from other report region
42 * in transition calls.
43 */
44 public class MasterAnnotationReadingPriorityFunction extends AnnotationReadingPriorityFunction {
45 public MasterAnnotationReadingPriorityFunction(final RSRpcServices rpcServices) {
46 this(rpcServices, rpcServices.getClass());
47 }
48
49
50 public MasterAnnotationReadingPriorityFunction(RSRpcServices rpcServices,
51 Class<? extends RSRpcServices> clz) {
52 super(rpcServices, clz);
53 }
54
55 public int getPriority(RPCProtos.RequestHeader header, Message param, User user) {
56 // Yes this is copy pasted from the base class but it keeps from having to look in the
57 // annotatedQos table twice something that could get costly since this is called for
58 // every single RPC request.
59 int priorityByAnnotation = getAnnotatedPriority(header);
60 if (priorityByAnnotation >= 0) {
61 return priorityByAnnotation;
62 }
63
64 // If meta is moving then all the other of reports of state transitions will be
65 // un able to edit meta. Those blocked reports should not keep the report that opens meta from
66 // running. Hence all reports of meta transitioning should always be in a different thread.
67 // This keeps from deadlocking the cluster.
68 if (param instanceof RegionServerStatusProtos.ReportRegionStateTransitionRequest) {
69 // Regions are moving. Lets see which ones.
70 RegionServerStatusProtos.ReportRegionStateTransitionRequest
71 tRequest = (RegionServerStatusProtos.ReportRegionStateTransitionRequest) param;
72 for (RegionServerStatusProtos.RegionStateTransition rst : tRequest.getTransitionList()) {
73 if (rst.getRegionInfoList() != null) {
74 for (HBaseProtos.RegionInfo info : rst.getRegionInfoList()) {
75 TableName tn = ProtobufUtil.toTableName(info.getTableName());
76 if (tn.isSystemTable()) {
77 return HConstants.SYSTEMTABLE_QOS;
78 }
79 }
80 }
81 }
82 return HConstants.NORMAL_QOS;
83 }
84
85 // Handle the rest of the different reasons to change priority.
86 return getBasePriority(header, param);
87 }
88 }