Skip to content

Commit 3990ffa

Browse files
committed
YARN-9909. Offline format of YarnConfigurationStore. Contributed by Prabhu Joseph.
1 parent a5034c7 commit 3990ffa

File tree

5 files changed

+102
-25
lines changed

5 files changed

+102
-25
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,15 @@
105105
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics;
106106
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
107107
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNode;
108+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.YarnConfigurationStore;
109+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.YarnConfigurationStoreFactory;
108110
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.constraint.AllocationTagsManager;
109111
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.constraint.MemoryPlacementConstraintManager;
110112
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.constraint.PlacementConstraintManagerService;
111113
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent;
112114
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType;
113115
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.MultiNodeSortingManager;
116+
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.MutableConfScheduler;
114117
import org.apache.hadoop.yarn.server.resourcemanager.security.DelegationTokenRenewer;
115118
import org.apache.hadoop.yarn.server.resourcemanager.security.ProxyCAManager;
116119
import org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager;
@@ -1563,6 +1566,8 @@ public static void main(String argv[]) {
15631566
if (argv.length >= 1) {
15641567
if (argv[0].equals("-format-state-store")) {
15651568
deleteRMStateStore(conf);
1569+
} else if (argv[0].equals("-format-conf-store")) {
1570+
deleteRMConfStore(conf);
15661571
} else if (argv[0].equals("-remove-application-from-state-store")
15671572
&& argv.length == 2) {
15681573
removeApplication(conf, argv[1]);
@@ -1671,6 +1676,45 @@ static void deleteRMStateStore(Configuration conf) throws Exception {
16711676
}
16721677
}
16731678

1679+
/**
1680+
* Deletes the YarnConfigurationStore
1681+
*
1682+
* @param conf
1683+
* @throws Exception
1684+
*/
1685+
@VisibleForTesting
1686+
static void deleteRMConfStore(Configuration conf) throws Exception {
1687+
ResourceManager rm = new ResourceManager();
1688+
rm.conf = conf;
1689+
ResourceScheduler scheduler = rm.createScheduler();
1690+
RMContextImpl rmContext = new RMContextImpl();
1691+
rmContext.setResourceManager(rm);
1692+
1693+
boolean isConfigurationMutable = false;
1694+
String confProviderStr = conf.get(
1695+
YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
1696+
YarnConfiguration.DEFAULT_CONFIGURATION_STORE);
1697+
switch (confProviderStr) {
1698+
case YarnConfiguration.MEMORY_CONFIGURATION_STORE:
1699+
case YarnConfiguration.LEVELDB_CONFIGURATION_STORE:
1700+
case YarnConfiguration.ZK_CONFIGURATION_STORE:
1701+
case YarnConfiguration.FS_CONFIGURATION_STORE:
1702+
isConfigurationMutable = true;
1703+
break;
1704+
default:
1705+
}
1706+
1707+
if (scheduler instanceof MutableConfScheduler && isConfigurationMutable) {
1708+
YarnConfigurationStore confStore = YarnConfigurationStoreFactory
1709+
.getStore(conf);
1710+
confStore.initialize(conf, conf, rmContext);
1711+
confStore.format();
1712+
} else {
1713+
System.out.println("Scheduler Configuration format only " +
1714+
"supported by MutableConfScheduler.");
1715+
}
1716+
}
1717+
16741718
@VisibleForTesting
16751719
static void removeApplication(Configuration conf, String applicationId)
16761720
throws Exception {
@@ -1691,7 +1735,9 @@ static void removeApplication(Configuration conf, String applicationId)
16911735
private static void printUsage(PrintStream out) {
16921736
out.println("Usage: yarn resourcemanager [-format-state-store]");
16931737
out.println(" "
1694-
+ "[-remove-application-from-state-store <appId>]" + "\n");
1738+
+ "[-remove-application-from-state-store <appId>]");
1739+
out.println(" "
1740+
+ "[-format-conf-store]" + "\n");
16951741

16961742
out.println("[-convert-fs-configuration ");
16971743
out.println(FSConfigToCSConfigConverter.WARNING_TEXT);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/MutableCSConfigurationProvider.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,7 @@ public MutableCSConfigurationProvider(RMContext rmContext) {
6868

6969
@Override
7070
public void init(Configuration config) throws IOException {
71-
String store = config.get(
72-
YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
73-
YarnConfiguration.MEMORY_CONFIGURATION_STORE);
74-
switch (store) {
75-
case YarnConfiguration.MEMORY_CONFIGURATION_STORE:
76-
this.confStore = new InMemoryConfigurationStore();
77-
break;
78-
case YarnConfiguration.LEVELDB_CONFIGURATION_STORE:
79-
this.confStore = new LeveldbConfigurationStore();
80-
break;
81-
case YarnConfiguration.ZK_CONFIGURATION_STORE:
82-
this.confStore = new ZKConfigurationStore();
83-
break;
84-
case YarnConfiguration.FS_CONFIGURATION_STORE:
85-
this.confStore = new FSSchedulerConfigurationStore();
86-
break;
87-
default:
88-
this.confStore = YarnConfigurationStoreFactory.getStore(config);
89-
break;
90-
}
71+
this.confStore = YarnConfigurationStoreFactory.getStore(config);
9172
Configuration initialSchedConf = new Configuration(false);
9273
initialSchedConf.addResource(YarnConfiguration.CS_CONFIGURATION_FILE);
9374
this.schedConf = new Configuration(false);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/YarnConfigurationStoreFactory.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,24 @@ private YarnConfigurationStoreFactory() {
3737
}
3838

3939
public static YarnConfigurationStore getStore(Configuration conf) {
40-
Class<? extends YarnConfigurationStore> storeClass =
41-
conf.getClass(YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
40+
String store = conf.get(
41+
YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
42+
YarnConfiguration.MEMORY_CONFIGURATION_STORE);
43+
switch (store) {
44+
case YarnConfiguration.MEMORY_CONFIGURATION_STORE:
45+
return new InMemoryConfigurationStore();
46+
case YarnConfiguration.LEVELDB_CONFIGURATION_STORE:
47+
return new LeveldbConfigurationStore();
48+
case YarnConfiguration.ZK_CONFIGURATION_STORE:
49+
return new ZKConfigurationStore();
50+
case YarnConfiguration.FS_CONFIGURATION_STORE:
51+
return new FSSchedulerConfigurationStore();
52+
default:
53+
Class<? extends YarnConfigurationStore> storeClass =
54+
conf.getClass(YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
4255
InMemoryConfigurationStore.class, YarnConfigurationStore.class);
43-
LOG.info("Using YarnConfigurationStore implementation - " + storeClass);
44-
return ReflectionUtils.newInstance(storeClass, conf);
56+
LOG.info("Using YarnConfigurationStore implementation - " + storeClass);
57+
return ReflectionUtils.newInstance(storeClass, conf);
58+
}
4559
}
4660
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMStoreCommands.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package org.apache.hadoop.yarn.server.resourcemanager;
2020

2121
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertNotNull;
23+
import static org.junit.Assert.assertNull;
2224
import static org.junit.Assert.assertTrue;
2325
import static org.junit.Assert.fail;
2426

@@ -66,6 +68,39 @@ public void testFormatStateStoreCmdForZK() throws Exception {
6668
}
6769
}
6870

71+
@Test
72+
public void testFormatConfStoreCmdForZK() throws Exception {
73+
try (TestingServer curatorTestingServer =
74+
TestZKRMStateStore.setupCuratorServer();
75+
CuratorFramework curatorFramework = TestZKRMStateStore.
76+
setupCuratorFramework(curatorTestingServer)) {
77+
Configuration conf = TestZKRMStateStore.createHARMConf("rm1,rm2", "rm1",
78+
1234, false, curatorTestingServer);
79+
conf.set(YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
80+
YarnConfiguration.ZK_CONFIGURATION_STORE);
81+
82+
ResourceManager rm = new MockRM(conf);
83+
rm.start();
84+
85+
String confStorePath = conf.get(
86+
YarnConfiguration.RM_SCHEDCONF_STORE_ZK_PARENT_PATH,
87+
YarnConfiguration.DEFAULT_RM_SCHEDCONF_STORE_ZK_PARENT_PATH)
88+
+ "/CONF_STORE";
89+
assertNotNull("Failed to initialize ZKConfigurationStore",
90+
curatorFramework.checkExists().forPath(confStorePath));
91+
92+
rm.close();
93+
try {
94+
ResourceManager.deleteRMConfStore(conf);
95+
} catch (Exception e) {
96+
fail("Exception should not be thrown during format rm conf store" +
97+
" operation.");
98+
}
99+
assertNull("Failed to format ZKConfigurationStore",
100+
curatorFramework.checkExists().forPath(confStorePath));
101+
}
102+
}
103+
69104
@Test
70105
public void testRemoveApplicationFromStateStoreCmdForZK() throws Exception {
71106
StateChangeRequestInfo req = new StateChangeRequestInfo(

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ Usage: `yarn resourcemanager [-format-state-store]`
193193
|:---- |:---- |
194194
| -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. |
195195
| -remove-application-from-state-store \<appId\> | Remove the application from RMStateStore. This should be run only when the ResourceManager is not running. |
196+
| -format-conf-store | Formats the YarnConfigurationStore. This will clear the persisted scheduler configuration under YarnConfigurationStore. This should be run only when the ResourceManager is not running. |
196197
| -convert-fs-configuration [-y&#124;yarnsiteconfig] [-f&#124;fsconfig] [-r&#124;rulesconfig] [-o&#124;output-directory] [-p&#124;print] [-c&#124;cluster-resource] | WARNING: This feature is experimental and not intended for production use! Development is still in progress so the converter should not be considered complete! <br/> Converts the specified Fair Scheduler configuration to Capacity Scheduler configuration. Requires two mandatory input files. First, the yarn-site.xml with the following format: [-y&#124;yarnsiteconfig [\<Path to the yarn-site.xml file\>]. Secondly, the fair-scheduler.xml with the following format: [-f&#124;fsconfig [\<Path to the fair-scheduler.xml file\>]. This config is not mandatory if there is a reference in yarn-site.xml to the fair-scheduler.xml with the property 'yarn.scheduler.fair.allocation.file'. If both are defined, the -f option has precedence. The output directory of the config files should be specified as well, with: \[-o&#124;output-directory\ \<directory\>]. An optional rules config file could be also specified with the following format: [-r&#124;rulesconfig \<Path to the conversion rules file\>]. The rule config file's format is a property file. There's an additional \[-p&#124;print\] parameter, which is optional. If defined, the configuration will be emitted to the console instead. In its normal operation, the output files (yarn-site.xml and capacity-scheduler.xml) of this command is generated to the specified output directory. The cluster resource parameter (\[-c&#124;cluster-resource\] \<resource\>\]) needs to be specified if any queue has a maxResources setting with value as percentage. The format of the resource string is the same as in fair-scheduler.xml.) ] |
197198

198199
Start the ResourceManager

0 commit comments

Comments
 (0)