YARN-7962. Race Condition When Stopping DelegationTokenRenewer causes RM crash during failover. (BELUGA BEHR via wangda)

Change-Id: I617e2645f60a57080058ad5f06af860fb3f682c8
This commit is contained in:
Wangda Tan 2018-06-01 14:00:18 -07:00
parent 3a6bd77550
commit 931f78718f
2 changed files with 33 additions and 1 deletions

View File

@ -209,7 +209,15 @@ public class DelegationTokenRenewer extends AbstractService {
} }
appTokens.clear(); appTokens.clear();
allTokens.clear(); allTokens.clear();
this.renewerService.shutdown();
serviceStateLock.writeLock().lock();
try {
isServiceStarted = false;
this.renewerService.shutdown();
} finally {
serviceStateLock.writeLock().unlock();
}
dtCancelThread.interrupt(); dtCancelThread.interrupt();
try { try {
dtCancelThread.join(1000); dtCancelThread.join(1000);

View File

@ -1420,4 +1420,28 @@ public class TestDelegationTokenRenewer {
delegationTokenRenewer.setTimerForTokenRenewal(mockDttr); delegationTokenRenewer.setTimerForTokenRenewal(mockDttr);
assertNull(mockDttr.timerTask); assertNull(mockDttr.timerTask);
} }
/**
* Test that the DelegationTokenRenewer class can gracefully handle
* interactions that occur when it has been stopped.
*/
@Test
public void testShutDown() {
DelegationTokenRenewer dtr = createNewDelegationTokenRenewer(conf, counter);
RMContext mockContext = mock(RMContext.class);
when(mockContext.getSystemCredentialsForApps()).thenReturn(
new ConcurrentHashMap<ApplicationId, ByteBuffer>());
ClientRMService mockClientRMService = mock(ClientRMService.class);
when(mockContext.getClientRMService()).thenReturn(mockClientRMService);
InetSocketAddress sockAddr =
InetSocketAddress.createUnresolved("localhost", 1234);
when(mockClientRMService.getBindAddress()).thenReturn(sockAddr);
dtr.setRMContext(mockContext);
when(mockContext.getDelegationTokenRenewer()).thenReturn(dtr);
dtr.init(conf);
dtr.start();
delegationTokenRenewer.stop();
delegationTokenRenewer.applicationFinished(
BuilderUtils.newApplicationId(0, 1));
}
} }