From 79091cf76f6e966f64ac1d65e43e95782695e678 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Fri, 27 Jul 2018 15:23:57 -0700 Subject: [PATCH] YARN-8596. Allow SQLFederationStateStore to submit the same app in the same subcluster. Contributed by Giovanni Matteo Fumarola. --- .../store/impl/SQLFederationStateStore.java | 14 +++++++------- .../impl/FederationStateStoreBaseTest.java | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/impl/SQLFederationStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/impl/SQLFederationStateStore.java index e62dcaf2a7f..273118aebaa 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/impl/SQLFederationStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/impl/SQLFederationStateStore.java @@ -564,13 +564,13 @@ public class SQLFederationStateStore implements FederationStateStore { // Check the ROWCOUNT value, if it is equal to 0 it means the call // did not add a new application into FederationStateStore if (cstmt.getInt(4) == 0) { - String errMsg = "The application " + appId - + " was not insert into the StateStore"; - FederationStateStoreUtils.logAndThrowStoreException(LOG, errMsg); - } - // Check the ROWCOUNT value, if it is different from 1 it means the call - // had a wrong behavior. Maybe the database is not set correctly. - if (cstmt.getInt(4) != 1) { + LOG.info( + "The application {} was not inserted in the StateStore because it" + + " was already present in SubCluster {}", + appId, subClusterHome); + } else if (cstmt.getInt(4) != 1) { + // Check the ROWCOUNT value, if it is different from 1 it means the + // call had a wrong behavior. Maybe the database is not set correctly. String errMsg = "Wrong behavior during the insertion of SubCluster " + subClusterId; FederationStateStoreUtils.logAndThrowStoreException(LOG, errMsg); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/impl/FederationStateStoreBaseTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/impl/FederationStateStoreBaseTest.java index 15cc0f0a009..b17f8702a94 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/impl/FederationStateStoreBaseTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/impl/FederationStateStoreBaseTest.java @@ -281,6 +281,25 @@ public abstract class FederationStateStoreBaseTest { } + @Test + public void testAddApplicationHomeSubClusterAppAlreadyExistsInTheSameSC() + throws Exception { + ApplicationId appId = ApplicationId.newInstance(1, 1); + SubClusterId subClusterId1 = SubClusterId.newInstance("SC1"); + addApplicationHomeSC(appId, subClusterId1); + + ApplicationHomeSubCluster ahsc2 = + ApplicationHomeSubCluster.newInstance(appId, subClusterId1); + + AddApplicationHomeSubClusterResponse response = + stateStore.addApplicationHomeSubCluster( + AddApplicationHomeSubClusterRequest.newInstance(ahsc2)); + + Assert.assertEquals(subClusterId1, response.getHomeSubCluster()); + Assert.assertEquals(subClusterId1, queryApplicationHomeSC(appId)); + + } + @Test public void testDeleteApplicationHomeSubCluster() throws Exception { ApplicationId appId = ApplicationId.newInstance(1, 1);