diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 06b97e47c9f..ef78ad0d52f 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -42,6 +42,9 @@ Release 2.8.0 - UNRELEASED YARN-3463. Integrate OrderingPolicy Framework with CapacityScheduler. (Craig Welch via wangda) + YARN-3410. YARN admin should be able to remove individual application + records from RMStateStore. (Rohith Sharmaks via wangda) + IMPROVEMENTS YARN-1880. Cleanup TestApplicationClientProtocolOnHA diff --git a/hadoop-yarn-project/hadoop-yarn/bin/yarn b/hadoop-yarn-project/hadoop-yarn/bin/yarn index fa6fec4259d..d8bd0779a89 100644 --- a/hadoop-yarn-project/hadoop-yarn/bin/yarn +++ b/hadoop-yarn-project/hadoop-yarn/bin/yarn @@ -69,8 +69,10 @@ function print_usage(){ echo " CLASSNAME run the class named CLASSNAME" echo " or" echo " where COMMAND is one of:" - echo " resourcemanager -format-state-store deletes the RMStateStore" echo " resourcemanager run the ResourceManager" + echo " Use -format-state-store for deleting the RMStateStore." + echo " Use -remove-application-from-state-store for " + echo " removing application from RMStateStore." echo " nodemanager run a nodemanager on each slave" echo " timelineserver run the timeline server" echo " rmadmin admin tools" diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java index 8bd8e2161c2..130cfd4a4e8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java @@ -93,6 +93,7 @@ import org.apache.hadoop.yarn.server.webproxy.AppReportFetcher; import org.apache.hadoop.yarn.server.webproxy.ProxyUriUtils; import org.apache.hadoop.yarn.server.webproxy.WebAppProxy; import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServlet; +import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.hadoop.yarn.webapp.WebApp; import org.apache.hadoop.yarn.webapp.WebApps; import org.apache.hadoop.yarn.webapp.WebApps.Builder; @@ -100,6 +101,7 @@ import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import java.io.IOException; import java.io.InputStream; +import java.io.PrintStream; import java.net.InetSocketAddress; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; @@ -1197,8 +1199,15 @@ public class ResourceManager extends CompositeService implements Recoverable { GenericOptionsParser hParser = new GenericOptionsParser(conf, argv); argv = hParser.getRemainingArgs(); // If -format-state-store, then delete RMStateStore; else startup normally - if (argv.length == 1 && argv[0].equals("-format-state-store")) { - deleteRMStateStore(conf); + if (argv.length >= 1) { + if (argv[0].equals("-format-state-store")) { + deleteRMStateStore(conf); + } else if (argv[0].equals("-remove-application-from-state-store") + && argv.length == 2) { + removeApplication(conf, argv[1]); + } else { + printUsage(System.err); + } } else { ResourceManager resourceManager = new ResourceManager(); ShutdownHookManager.get().addShutdownHook( @@ -1275,4 +1284,25 @@ public class ResourceManager extends CompositeService implements Recoverable { rmStore.stop(); } } + + private static void removeApplication(Configuration conf, String applicationId) + throws Exception { + RMStateStore rmStore = RMStateStoreFactory.getStore(conf); + rmStore.init(conf); + rmStore.start(); + try { + ApplicationId removeAppId = ConverterUtils.toApplicationId(applicationId); + LOG.info("Deleting application " + removeAppId + " from state store"); + rmStore.removeApplication(removeAppId); + LOG.info("Application is deleted from state store"); + } finally { + rmStore.stop(); + } + } + + private static void printUsage(PrintStream out) { + out.println("Usage: java ResourceManager [-format-state-store]"); + out.println(" " + + "[-remove-application-from-state-store ]" + "\n"); + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/FileSystemRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/FileSystemRMStateStore.java index 7652a070189..68d26bba952 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/FileSystemRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/FileSystemRMStateStore.java @@ -559,6 +559,15 @@ public class FileSystemRMStateStore extends RMStateStore { } } + @Override + public synchronized void removeApplication(ApplicationId removeAppId) + throws Exception { + Path nodeRemovePath = getAppDir(rmAppRoot, removeAppId); + if (existsWithRetries(nodeRemovePath)) { + deleteFileWithRetries(nodeRemovePath); + } + } + private Path getAppDir(Path root, ApplicationId appId) { return getNodePath(root, appId.toString()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/LeveldbRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/LeveldbRMStateStore.java index 2c927146480..46a3459f99b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/LeveldbRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/LeveldbRMStateStore.java @@ -659,6 +659,18 @@ public class LeveldbRMStateStore extends RMStateStore { fs.delete(root, true); } + @Override + public synchronized void removeApplication(ApplicationId removeAppId) + throws IOException { + String appKey = getApplicationNodeKey(removeAppId); + LOG.info("Removing state for app " + removeAppId); + try { + db.delete(bytes(appKey)); + } catch (DBException e) { + throw new IOException(e); + } + } + @VisibleForTesting int getNumEntriesInDatabase() throws IOException { int numEntries = 0; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/MemoryRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/MemoryRMStateStore.java index 8cd776e6044..609f4031d27 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/MemoryRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/MemoryRMStateStore.java @@ -251,4 +251,8 @@ public class MemoryRMStateStore extends RMStateStore { public void deleteStore() throws Exception { } + @Override + public void removeApplication(ApplicationId removeAppId) throws Exception { + } + } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/NullRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/NullRMStateStore.java index d2c1e9d71f3..92c07cd3ba0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/NullRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/NullRMStateStore.java @@ -150,4 +150,9 @@ public class NullRMStateStore extends RMStateStore { // Do nothing } + @Override + public void removeApplication(ApplicationId removeAppId) throws Exception { + // Do nothing + } + } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStore.java index bccde53ddff..cc4edd7abae 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStore.java @@ -907,6 +907,15 @@ public abstract class RMStateStore extends AbstractService { */ public abstract void deleteStore() throws Exception; + /** + * Derived classes must implement this method to remove application from the + * state store + * + * @throws Exception + */ + public abstract void removeApplication(ApplicationId removeAppId) + throws Exception; + public void setResourceManager(ResourceManager rm) { this.resourceManager = rm; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java index e8891a2233d..9da6400a42f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java @@ -823,6 +823,15 @@ public class ZKRMStateStore extends RMStateStore { } } + @Override + public synchronized void removeApplication(ApplicationId removeAppId) + throws Exception { + String appIdRemovePath = getNodePath(rmAppRoot, removeAppId.toString()); + if (existsWithRetries(appIdRemovePath, true) != null) { + deleteWithRetries(appIdRemovePath, true); + } + } + // ZK related code /** * Watcher implementation which forward events to the ZKRMStateStore This diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java index 5b53a0235af..3bc0709c76a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java @@ -591,6 +591,21 @@ public class RMStateStoreTestBase extends ClientBaseWithFixes{ } } + public void testRemoveApplication(RMStateStoreHelper stateStoreHelper) + throws Exception { + RMStateStore store = stateStoreHelper.getRMStateStore(); + int noOfApps = 2; + ArrayList appList = + createAndStoreApps(stateStoreHelper, store, noOfApps); + + RMApp rmApp1 = appList.get(0); + store.removeApplication(rmApp1.getApplicationId()); + Assert.assertFalse(stateStoreHelper.appExists(rmApp1)); + + RMApp rmApp2 = appList.get(1); + Assert.assertTrue(stateStoreHelper.appExists(rmApp2)); + } + protected void modifyAppState() throws Exception { } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java index c5f557855b4..b1e7a0b1116 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java @@ -171,6 +171,7 @@ public class TestFSRMStateStore extends RMStateStoreTestBase { testEpoch(fsTester); testAppDeletion(fsTester); testDeleteStore(fsTester); + testRemoveApplication(fsTester); testAMRMTokenSecretManagerStateStore(fsTester); } finally { cluster.shutdown(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestLeveldbRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestLeveldbRMStateStore.java index ae885d2df48..17cffa02d8a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestLeveldbRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestLeveldbRMStateStore.java @@ -90,6 +90,12 @@ public class TestLeveldbRMStateStore extends RMStateStoreTestBase { testDeleteStore(tester); } + @Test(timeout = 60000) + public void testRemoveApplication() throws Exception { + LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); + testRemoveApplication(tester); + } + @Test(timeout = 60000) public void testAMTokens() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java index 608adbee781..6b09d3920ec 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java @@ -146,6 +146,7 @@ public class TestZKRMStateStore extends RMStateStoreTestBase { testEpoch(zkTester); testAppDeletion(zkTester); testDeleteStore(zkTester); + testRemoveApplication(zkTester); testAMRMTokenSecretManagerStateStore(zkTester); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md index db8201a8923..1169d14c420 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md @@ -193,6 +193,7 @@ Usage: `yarn resourcemanager [-format-state-store]` | COMMAND\_OPTIONS | Description | |:---- |:---- | | -format-state-store | Formats the RMStateStore. This will clear the RMStateStore and is useful if past applications are no longer needed. This should be run only when the ResourceManager is not running. | +| -remove-application-from-state-store | Remove the application from RMStateStore. This should be run only when the ResourceManager is not running. | Start the ResourceManager