/** Format a new filesystem. Destroys any filesystem that may already * exist at this location. **/ public static void format(Configuration conf) throws IOException { format(conf, true, true); }
/** Format a new filesystem. Destroys any filesystem that may already * exist at this location. **/ public static void format(Configuration conf) throws IOException { format(conf, false); }
/** Format a new filesystem. Destroys any filesystem that may already * exist at this location. **/ public static void format(Configuration conf) throws IOException { format(conf, false); }
/** Format a new filesystem. Destroys any filesystem that may already * exist at this location. **/ public static void format(Configuration conf) throws IOException { format(conf, true, true); }
/** Format a new filesystem. Destroys any filesystem that may already * exist at this location. **/ public static void format(Configuration conf) throws IOException { format(conf, true, true); }
switch (startOpt) { case FORMAT: aborted = format(conf, startOpt.getForceFormat(), startOpt.getInteractiveFormat()); terminate(aborted ? 1 : 0);
@Override protected void doExecute(Configuration conf) throws Exception { Collection<File> dirsToFormat = FSNamesystem.getNamespaceDirs(conf); for (Iterator<File> it = dirsToFormat.iterator(); it.hasNext(); ) { File curDir = it.next(); if (!curDir.exists()) { continue; } if (!force) { System.err.print("Re-format filesystem in " + curDir + " ? (Y or N) "); System.err.flush(); if (!(System.in.read() == 'Y')) { System.err.println("Format aborted in " + curDir); return; } while (System.in.read() != '\n') ; // discard the enter-key } } NameNode.format(conf); }
public void formatStorage() { log.info("Format Storage..."); try { NameNode.format(HadoopUtils.toConfiguration(startupProperties)); } catch (IOException e) { throw new TechnicalException(e); } log.info("Storage formatted"); }
@Override protected NameNode doCreate(Dictionary properties) throws Exception { Configuration conf = new Configuration(); for (Enumeration e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); Object val = properties.get(key); conf.set( key.toString(), val.toString() ); } boolean exists = false; for (File file : FSNamesystem.getNamespaceDirs(conf)) { exists |= file.exists(); } if (!exists) { NameNode.format(conf); } NameNode nameNode = NameNode.createNameNode(null, conf); return nameNode; }
/** * This test runs all benchmarks defined in {@link NNThroughputBenchmark}. */ @Test public void testNNThroughput() throws Exception { Configuration conf = new HdfsConfiguration(); FileSystem.setDefaultUri(conf, "hdfs://localhost:" + 0); conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "0.0.0.0:0"); NameNode.format(conf); String[] args = new String[] {"-op", "all"}; NNThroughputBenchmark.runBenchmark(conf, Arrays.asList(args)); } }
/** * Initiates and sets a spied on FSNamesystem so tests can hook its methods * @throws IOException if an error occurred */ @Before public void startUp() throws IOException { conf = new HdfsConfiguration(); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, NAME_DIR); conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, NAME_DIR); // avoid stubbing access control conf.setBoolean(DFSConfigKeys.DFS_PERMISSIONS_ENABLED_KEY, false); NameNode.initMetrics(conf, NamenodeRole.ACTIVE); FileSystem.setDefaultUri(conf, "hdfs://localhost:0"); conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "0.0.0.0:0"); NameNode.format(conf); fsn = spy(new FSNamesystem(conf)); }
public static NameNode createNameNode(String argv[], Configuration conf) throws IOException { if (conf == null) conf = new Configuration(); StartupOption startOpt = parseArguments(argv, conf); if (startOpt == null) { printUsage(); return null; } switch (startOpt) { case FORMAT: boolean aborted = format(conf, true); System.exit(aborted ? 1 : 0); case FINALIZE: aborted = finalize(conf, true); System.exit(aborted ? 1 : 0); default: } NameNode namenode = new NameNode(conf); return namenode; }
/** * Start the namenode. */ public NameNode startNameNode(boolean withService) throws IOException { String dataDir = getTestingDir(); hdfsDir = new File(dataDir, "dfs"); if ( hdfsDir.exists() && !FileUtil.fullyDelete(hdfsDir) ) { throw new IOException("Could not delete hdfs directory '" + hdfsDir + "'"); } config = new HdfsConfiguration(); config.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, fileAsURI(new File(hdfsDir, "name1")).toString()); FileSystem.setDefaultUri(config, "hdfs://" + THIS_HOST); if (withService) { NameNode.setServiceAddress(config, THIS_HOST); } config.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, THIS_HOST); NameNode.format(config); String[] args = new String[] {}; // NameNode will modify config with the ports it bound to return NameNode.createNameNode(args, config); }
/** * when formatting a namenode - we must provide clusterid. * @param conf * @throws IOException */ public static void formatNameNode(Configuration conf) throws IOException { String clusterId = StartupOption.FORMAT.getClusterId(); if(clusterId == null || clusterId.isEmpty()) StartupOption.FORMAT.setClusterId("testClusterID"); // Use a copy of conf as it can be altered by namenode during format. NameNode.format(new Configuration(conf)); }
@Test public void testLoadFsEditsShouldReturnTrueWhenEditsNewExists() throws Exception { nnConf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, OUT_DIR + "/BNN1"); NameNode.format(nnConf); miniDFSCluster = new MiniDFSCluster.Builder(nnConf).numDataNodes(1).build(); FSImage image = miniDFSCluster.getNameNode().getFSImage(); URI next = miniDFSCluster.getNameDirs().iterator().next(); File editsNew = new File(next.getRawPath(), "/current/edits.new"); createEditsNew(editsNew, image); int loadFSEdits = image.loadFSEdits(image.getStorageDir(0)); assertEquals("The numEdits should not be zero.", 1, loadFSEdits); }
public static NameNode createNameNode(String argv[], Configuration conf) throws IOException { if (conf == null) conf = new Configuration(); StartupOptionAndService startOpt = parseArguments(argv); if (startOpt == null) { printUsage(); return null; } if (!validateServiceName(conf, startOpt.serviceName)) { return null; } initializeGenericKeys(conf, startOpt.serviceName); setupDefaultURI(conf); setStartupOption(conf, startOpt.startupOption); switch (startOpt.startupOption) { case FORMAT: boolean aborted = format(conf, true); System.exit(aborted ? 1 : 0); case FINALIZE: aborted = finalize(conf, true); System.exit(aborted ? 1 : 0); default: } NameNode namenode = new NameNode(conf, startOpt.failOnTxIdMismatch); namenode.nameserviceId = startOpt.serviceName; return namenode; }
NameNode.format(conf);
@Test public void testFormatClusterIdOption() throws IOException { // 1. should format without cluster id //StartupOption.FORMAT.setClusterId(""); NameNode.format(config); // see if cluster id not empty. String cid = getClusterId(config); assertTrue("Didn't get new ClusterId", (cid != null && !cid.equals("")) ); // 2. successful format with given clusterid StartupOption.FORMAT.setClusterId("mycluster"); NameNode.format(config); // see if cluster id matches with given clusterid. cid = getClusterId(config); assertTrue("ClusterId didn't match", cid.equals("mycluster")); // 3. format without any clusterid again. It should generate new //clusterid. StartupOption.FORMAT.setClusterId(""); NameNode.format(config); String newCid = getClusterId(config); assertFalse("ClusterId should not be the same", newCid.equals(cid)); }
/** * Test NameNode format failure when reformat is disabled and metadata * directories exist. */ @Test public void testNNFormatFailure() throws Exception { NameNode.initMetrics(config, NamenodeRole.NAMENODE); DFSTestUtil.formatNameNode(config); config.setBoolean(DFSConfigKeys.DFS_REFORMAT_DISABLED, true); // Call to NameNode format will fail as name dir is not empty try { NameNode.format(config); fail("NN format should fail."); } catch (NameNodeFormatException e) { GenericTestUtils.assertExceptionContains("NameNode format aborted as " + "reformat is disabled for this cluster", e); } }
NameNode.format(onDiskOnly);