HADOOP-16192. Fix CallQueue backoff bugs: perform backoff when add() is used and update backoff when refreshed.

(cherry-picked from 8c95cb9d6bef369fef6a8364f0c0764eba90e44a)
(cherry-picked from 0de8b55a095ada2b98c0a41899651bd8e524f42e)
(cherry-picked from d4fbbc83ad8c4d818deccf62b4c54cead1d17a8f)
(cherry-picked from e172fc62ce3fa10a36582bc6667edec931fea9fa)
This commit is contained in:
Erik Krogen 2019-03-14 10:12:58 -07:00
parent 525f4e52f3
commit c3973c9ae6
4 changed files with 28 additions and 3 deletions

View File

@ -221,12 +221,21 @@ public void put(E e) throws InterruptedException {
} else if (shouldBackOff(e)) { } else if (shouldBackOff(e)) {
throwBackoff(); throwBackoff();
} else { } else {
add(e); // No need to re-check backoff criteria since they were just checked
addInternal(e, false);
} }
} }
@Override @Override
public boolean add(E e) { public boolean add(E e) {
return addInternal(e, true);
}
@VisibleForTesting
boolean addInternal(E e, boolean checkBackoff) {
if (checkBackoff && isClientBackoffEnabled() && shouldBackOff(e)) {
throwBackoff();
}
try { try {
return putRef.get().add(e); return putRef.get().add(e);
} catch (CallQueueOverflowException ex) { } catch (CallQueueOverflowException ex) {

View File

@ -661,6 +661,7 @@ public synchronized void refreshCallQueue(Configuration conf) {
CommonConfigurationKeys.IPC_SERVER_HANDLER_QUEUE_SIZE_DEFAULT); CommonConfigurationKeys.IPC_SERVER_HANDLER_QUEUE_SIZE_DEFAULT);
callQueue.swapQueue(getSchedulerClass(prefix, conf), callQueue.swapQueue(getSchedulerClass(prefix, conf),
getQueueClass(prefix, conf), maxQueueSize, prefix, conf); getQueueClass(prefix, conf), maxQueueSize, prefix, conf);
callQueue.setClientBackoffEnabled(getClientBackoffEnable(prefix, conf));
} }
/** /**

View File

@ -434,5 +434,18 @@ public void testCallQueueOverflowExceptions() throws Exception {
} }
verify(queue, times(0)).put(call); verify(queue, times(0)).put(call);
verify(queue, times(0)).add(call); verify(queue, times(0)).add(call);
// backoff is enabled, add + scheduler backoff = overflow exception.
reset(queue);
cqm.setClientBackoffEnabled(true);
doReturn(Boolean.TRUE).when(cqm).shouldBackOff(call);
try {
cqm.add(call);
fail("didn't fail");
} catch (Exception ex) {
assertTrue(ex.toString(), ex instanceof CallQueueOverflowException);
}
verify(queue, times(0)).put(call);
verify(queue, times(0)).add(call);
} }
} }

View File

@ -1135,7 +1135,8 @@ public Void call() throws ServiceException, InterruptedException {
return null; return null;
} }
})); }));
verify(spy, timeout(500).times(i + 1)).add(Mockito.<Call>anyObject()); verify(spy, timeout(500).times(i + 1)).addInternal(
Mockito.<Call>anyObject(), Mockito.eq(false));
} }
try { try {
proxy.sleep(null, newSleepRequest(100)); proxy.sleep(null, newSleepRequest(100));
@ -1206,7 +1207,8 @@ public Void call() throws ServiceException, InterruptedException {
return null; return null;
} }
})); }));
verify(spy, timeout(500).times(i + 1)).add(Mockito.<Call>anyObject()); verify(spy, timeout(500).times(i + 1)).addInternal(
Mockito.<Call>anyObject(), Mockito.eq(false));
} }
// Start another sleep RPC call and verify the call is backed off due to // Start another sleep RPC call and verify the call is backed off due to
// avg response time(3s) exceeds threshold (2s). // avg response time(3s) exceeds threshold (2s).