From 9a3b006685f25c340107075b76f2c65bf5c39f93 Mon Sep 17 00:00:00 2001 From: bibinchundatt Date: Mon, 30 Jul 2018 21:31:47 +0530 Subject: [PATCH] YARN-8558. NM recovery level db not cleaned up properly on container finish. Contributed by Bibin A Chundatt. --- .../recovery/NMLeveldbStateStoreService.java | 13 +++++++++---- .../recovery/TestNMLeveldbStateStoreService.java | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/recovery/NMLeveldbStateStoreService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/recovery/NMLeveldbStateStoreService.java index d3e3cf8f7df..f00ac830907 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/recovery/NMLeveldbStateStoreService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/recovery/NMLeveldbStateStoreService.java @@ -137,9 +137,9 @@ public class NMLeveldbStateStoreService extends NMStateStoreService { NM_TOKENS_KEY_PREFIX + PREV_MASTER_KEY_SUFFIX; private static final String CONTAINER_TOKENS_KEY_PREFIX = "ContainerTokens/"; - private static final String CONTAINER_TOKENS_CURRENT_MASTER_KEY = + private static final String CONTAINER_TOKEN_SECRETMANAGER_CURRENT_MASTER_KEY = CONTAINER_TOKENS_KEY_PREFIX + CURRENT_MASTER_KEY_SUFFIX; - private static final String CONTAINER_TOKENS_PREV_MASTER_KEY = + private static final String CONTAINER_TOKEN_SECRETMANAGER_PREV_MASTER_KEY = CONTAINER_TOKENS_KEY_PREFIX + PREV_MASTER_KEY_SUFFIX; private static final String LOG_DELETER_KEY_PREFIX = "LogDeleters/"; @@ -567,6 +567,11 @@ public class NMLeveldbStateStoreService extends NMStateStoreService { batch.delete(bytes(keyPrefix + CONTAINER_KILLED_KEY_SUFFIX)); batch.delete(bytes(keyPrefix + CONTAINER_EXIT_CODE_KEY_SUFFIX)); batch.delete(bytes(keyPrefix + CONTAINER_UPDATE_TOKEN_SUFFIX)); + batch.delete(bytes(keyPrefix + CONTAINER_START_TIME_KEY_SUFFIX)); + batch.delete(bytes(keyPrefix + CONTAINER_LOG_DIR_KEY_SUFFIX)); + batch.delete(bytes(keyPrefix + CONTAINER_VERSION_KEY_SUFFIX)); + batch.delete(bytes(keyPrefix + CONTAINER_REMAIN_RETRIES_KEY_SUFFIX)); + batch.delete(bytes(keyPrefix + CONTAINER_WORK_DIR_KEY_SUFFIX)); List unknownKeysForContainer = containerUnknownKeySuffixes .removeAll(containerId); for (String unknownKeySuffix : unknownKeysForContainer) { @@ -1068,13 +1073,13 @@ public class NMLeveldbStateStoreService extends NMStateStoreService { @Override public void storeContainerTokenCurrentMasterKey(MasterKey key) throws IOException { - storeMasterKey(CONTAINER_TOKENS_CURRENT_MASTER_KEY, key); + storeMasterKey(CONTAINER_TOKEN_SECRETMANAGER_CURRENT_MASTER_KEY, key); } @Override public void storeContainerTokenPreviousMasterKey(MasterKey key) throws IOException { - storeMasterKey(CONTAINER_TOKENS_PREV_MASTER_KEY, key); + storeMasterKey(CONTAINER_TOKEN_SECRETMANAGER_PREV_MASTER_KEY, key); } @Override diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java index 3ab02ebe246..85fcfdd1770 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java @@ -25,9 +25,12 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.isNull; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.io.File; @@ -369,6 +372,11 @@ public class TestNMLeveldbStateStoreService { restartStateStore(); recoveredContainers = stateStore.loadContainersState(); assertTrue(recoveredContainers.isEmpty()); + // recover again to check remove clears all containers + restartStateStore(); + NMStateStoreService nmStoreSpy = spy(stateStore); + nmStoreSpy.loadContainersState(); + verify(nmStoreSpy, times(0)).removeContainer(any(ContainerId.class)); } private StartContainerRequest createContainerRequest(