Search in sources :

Example 6 with UnderFileStatus

use of alluxio.underfs.UnderFileStatus in project alluxio by Alluxio.

the class Format method formatFolder.

private static boolean formatFolder(String name, String folder) throws IOException {
    UnderFileSystem ufs = UnderFileSystem.Factory.get(folder);
    LOG.info("Formatting {}:{}", name, folder);
    if (ufs.isDirectory(folder)) {
        for (UnderFileStatus p : ufs.listStatus(folder)) {
            String childPath = PathUtils.concatPath(folder, p.getName());
            boolean failedToDelete;
            if (p.isDirectory()) {
                failedToDelete = !ufs.deleteDirectory(childPath, DeleteOptions.defaults().setRecursive(true));
            } else {
                failedToDelete = !ufs.deleteFile(childPath);
            }
            if (failedToDelete) {
                LOG.info("Failed to delete {}", childPath);
                return false;
            }
        }
    } else if (!ufs.mkdirs(folder)) {
        LOG.info("Failed to create {}:{}", name, folder);
        return false;
    }
    return true;
}
Also used : UnderFileStatus(alluxio.underfs.UnderFileStatus) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 7 with UnderFileStatus

use of alluxio.underfs.UnderFileStatus in project alluxio by Alluxio.

the class JournalIntegrationTest method multipleFlush.

/**
   * Tests flushing the journal multiple times, without writing any data.
   */
@Test
public void multipleFlush() throws Exception {
    // Set the max log size to 0 to force a flush to write a new file.
    String existingMax = Configuration.get(PropertyKey.MASTER_JOURNAL_LOG_SIZE_BYTES_MAX);
    Configuration.set(PropertyKey.MASTER_JOURNAL_LOG_SIZE_BYTES_MAX, "0");
    try {
        String journalFolder = mLocalAlluxioCluster.getMaster().getJournalFolder();
        ReadWriteJournal journal = new ReadWriteJournal(PathUtils.concatPath(journalFolder, Constants.FILE_SYSTEM_MASTER_NAME));
        JournalWriter writer = journal.getNewWriter();
        writer.getCheckpointOutputStream(0).close();
        // Flush multiple times, without writing to the log.
        writer.flushEntryStream();
        writer.flushEntryStream();
        writer.flushEntryStream();
        UnderFileStatus[] paths = UnderFileSystem.Factory.get(journalFolder).listStatus(journal.getCompletedDirectory());
        // Make sure no new empty files were created.
        Assert.assertTrue(paths == null || paths.length == 0);
    } finally {
        // Reset the max log size.
        Configuration.set(PropertyKey.MASTER_JOURNAL_LOG_SIZE_BYTES_MAX, existingMax);
    }
}
Also used : ReadWriteJournal(alluxio.master.journal.ReadWriteJournal) JournalWriter(alluxio.master.journal.JournalWriter) UnderFileStatus(alluxio.underfs.UnderFileStatus) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

UnderFileStatus (alluxio.underfs.UnderFileStatus)7 UnderFileSystem (alluxio.underfs.UnderFileSystem)3 Test (org.junit.Test)2 AlluxioURI (alluxio.AlluxioURI)1 InodeDirectory (alluxio.master.file.meta.InodeDirectory)1 MountTable (alluxio.master.file.meta.MountTable)1 TempInodePathForChild (alluxio.master.file.meta.TempInodePathForChild)1 LoadMetadataOptions (alluxio.master.file.options.LoadMetadataOptions)1 JournalWriter (alluxio.master.journal.JournalWriter)1 ReadWriteJournal (alluxio.master.journal.ReadWriteJournal)1 File (java.io.File)1 IOException (java.io.IOException)1 Random (java.util.Random)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 Matchers.anyString (org.mockito.Matchers.anyString)1