private static boolean formatFolder(String name, String folder, TachyonConf tachyonConf) throws IOException { UnderFileSystem ufs = UnderFileSystem.get(folder, tachyonConf); LOG.info("Formatting {}:{}", name, folder); if (ufs.exists(folder)) { for (String file : ufs.list(folder)) { if (!ufs.delete(PathUtils.concatPath(folder, file), true)) { LOG.info("Failed to remove {}:{}", name, file); return false; } } } else if (!ufs.mkdirs(folder, true)) { LOG.info("Failed to create {}:{}", name, folder); return false; } return true; }
/** * Checks to see if the journal directory is formatted. * * @param journalDirectory The journal directory to check * @return true if the journal directory was formatted previously, false otherwise * @throws IOException */ private boolean isJournalFormatted(String journalDirectory) throws IOException { TachyonConf conf = MasterContext.getConf(); UnderFileSystem ufs = UnderFileSystem.get(journalDirectory, conf); if (!ufs.providesStorage()) { // TODO(gene): Should the journal really be allowed on a ufs without storage? // This ufs doesn't provide storage. Allow the master to use this ufs for the journal. LOG.info("Journal directory doesn't provide storage: " + journalDirectory); return true; } String[] files = ufs.list(journalDirectory); if (files == null) { return false; } // Search for the format file. String formatFilePrefix = conf.get(Constants.MASTER_FORMAT_FILE_PREFIX); for (String file : files) { if (file.startsWith(formatFilePrefix)) { return true; } } return false; }
/** * To clean up the test environment over underfs cluster system, so that we can re-use the running * system for the next test round instead of turning on/off it from time to time. This function is * expected to be called either before or after each test case which avoids certain overhead from * the bootstrap. * * @throws IOException when the operation fails */ public void cleanup() throws IOException { if (isStarted()) { String path = getUnderFilesystemAddress() + TachyonURI.SEPARATOR; UnderFileSystem ufs = UnderFileSystem.get(path, mTachyonConf); for (String p : ufs.list(path)) { ufs.delete(PathUtils.concatPath(path, p), true); } } }
String[] files = ufs.list(ufsPath.toString()); // ufs.list() returns relative path if (files != null) { for (String filePath : files) {