@Override public long getDeadline(RequestHeader header, Message param) { return priority.getDeadline(header, param); }
@Override public int getPriority(RequestHeader header, Message param, User user) { return priority.getPriority(header, param, user); }
when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS); when(hugeCall.getHeader()).thenReturn(hugeHead); when(priority.getDeadline(eq(smallHead), any())).thenReturn(0L); when(priority.getDeadline(eq(largeHead), any())).thenReturn(50L); when(priority.getDeadline(eq(hugeHead), any())).thenReturn(100L);
when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS); when(hugeCall.getHeader()).thenReturn(hugeHead); when(priority.getDeadline(eq(smallHead), any())).thenReturn(0L); when(priority.getDeadline(eq(largeHead), any())).thenReturn(50L); when(priority.getDeadline(eq(hugeHead), any())).thenReturn(100L);
@Test public void testScanQueueWithZeroScanRatio() throws Exception { Configuration schedConf = HBaseConfiguration.create(); schedConf.setFloat(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 1.0f); schedConf.setFloat(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0.5f); schedConf.setFloat(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0f); PriorityFunction priority = mock(PriorityFunction.class); when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS); RpcScheduler scheduler = new SimpleRpcScheduler(schedConf, 2, 1, 1, priority, HConstants.QOS_THRESHOLD); assertNotEquals(null, scheduler); }
@Override public int compare(CallRunner a, CallRunner b) { RpcCall callA = a.getRpcCall(); RpcCall callB = b.getRpcCall(); long deadlineA = priority.getDeadline(callA.getHeader(), callA.getParam()); long deadlineB = priority.getDeadline(callB.getHeader(), callB.getParam()); deadlineA = callA.getReceiveTime() + Math.min(deadlineA, maxDelay); deadlineB = callB.getReceiveTime() + Math.min(deadlineB, maxDelay); return Long.compare(deadlineA, deadlineB); } }
@Override public boolean dispatch(CallRunner callTask) throws InterruptedException { RpcCall call = callTask.getRpcCall(); int level = priority.getPriority(call.getHeader(), call.getParam(), call.getRequestUser().orElse(null)); if (level == HConstants.PRIORITY_UNSET) { level = HConstants.NORMAL_QOS; } if (metaTransitionExecutor != null && level == HConstants.META_QOS) { return metaTransitionExecutor.dispatch(callTask); } else if (priorityExecutor != null && level > highPriorityLevel) { return priorityExecutor.dispatch(callTask); } else if (replicationExecutor != null && level == HConstants.REPLICATION_QOS) { return replicationExecutor.dispatch(callTask); } else { return callExecutor.dispatch(callTask); } }
@Override public long getDeadline(RequestHeader header, Message param) { return priority.getDeadline(header, param); }
when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS); SimpleRpcScheduler scheduler = new SimpleRpcScheduler(schedConf, 0, 0, 0, priority, HConstants.QOS_THRESHOLD);
@Override public int compare(CallRunner a, CallRunner b) { RpcServer.Call callA = a.getCall(); RpcServer.Call callB = b.getCall(); long deadlineA = priority.getDeadline(callA.getHeader(), callA.param); long deadlineB = priority.getDeadline(callB.getHeader(), callB.param); deadlineA = callA.timestamp + Math.min(deadlineA, maxDelay); deadlineB = callB.timestamp + Math.min(deadlineB, maxDelay); return (int)(deadlineA - deadlineB); } }
int qos = priority.getPriority(header, scanRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[]{"somegroup"})); assertTrue ("" + qos, qos == HConstants.NORMAL_QOS); assertEquals(HConstants.SYSTEMTABLE_QOS, priority.getPriority(header, scanRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[]{"somegroup"}))); assertEquals(HConstants.NORMAL_QOS, priority.getPriority(header, scanRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[]{"somegroup"})));
when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS);
RpcExecutor.CALL_QUEUE_TYPE_CODEL_CONF_VALUE); PriorityFunction priority = mock(PriorityFunction.class); when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS); SimpleRpcScheduler scheduler = new SimpleRpcScheduler(schedConf, 1, 1, 1, priority, HConstants.QOS_THRESHOLD);
scheduler.start(); for (CallRunner task : tasks) { when(qosFunction.getPriority(any(), any(), any())).thenReturn(qos.get(task)); scheduler.dispatch(task);
assertEquals(HConstants.SYSTEMTABLE_QOS, priority.getPriority(header, getRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[]{"somegroup"})));
@Test public void testQosFunctionWithoutKnownArgument() throws IOException { //The request is not using any of the //known argument classes (it uses one random request class) //(known argument classes are listed in //HRegionServer.QosFunctionImpl.knownArgumentClasses) RequestHeader.Builder headerBuilder = RequestHeader.newBuilder(); headerBuilder.setMethodName("foo"); RequestHeader header = headerBuilder.build(); PriorityFunction qosFunc = regionServer.rpcServices.getPriority(); assertEquals(HConstants.NORMAL_QOS, qosFunc.getPriority(header, null, User.createUserForTesting(regionServer.conf, "someuser", new String[]{"somegroup"}))); }
@Override public int getPriority(RequestHeader header, Message param, User user) { return priority.getPriority(header, param, user); }
@Test public void testScanQueueWithZeroScanRatio() throws Exception { Configuration schedConf = HBaseConfiguration.create(); schedConf.setFloat(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 1.0f); schedConf.setFloat(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0.5f); schedConf.setFloat(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0f); PriorityFunction priority = mock(PriorityFunction.class); when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS); RpcScheduler scheduler = new SimpleRpcScheduler(schedConf, 2, 1, 1, priority, HConstants.QOS_THRESHOLD); assertNotEquals(null, scheduler); }
@Override public boolean dispatch(CallRunner callTask) throws InterruptedException { RpcServer.Call call = callTask.getCall(); int level = priority.getPriority(call.getHeader(), call.param, call.getRequestUser()); if (priorityExecutor != null && level > highPriorityLevel) { return priorityExecutor.dispatch(callTask); } else if (replicationExecutor != null && level == HConstants.REPLICATION_QOS) { return replicationExecutor.dispatch(callTask); } else { return callExecutor.dispatch(callTask); } }
when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS); SimpleRpcScheduler scheduler = new SimpleRpcScheduler(schedConf, 0, 0, 0, priority, HConstants.QOS_THRESHOLD);