Search in sources :

Example 6 with FilenameFilter

use of java.io.FilenameFilter in project hadoop by apache.

the class TestEditLog method testEditLogFailOverFromCorrupt.

/** 
   * Test edit log failover from a corrupt edit log
   */
@Test
public void testEditLogFailOverFromCorrupt() throws IOException {
    File f1 = new File(TEST_DIR + "/failover0");
    File f2 = new File(TEST_DIR + "/failover1");
    List<URI> editUris = ImmutableList.of(f1.toURI(), f2.toURI());
    NNStorage storage = setupEdits(editUris, 3);
    final long startErrorTxId = 1 * TXNS_PER_ROLL + 1;
    final long endErrorTxId = 2 * TXNS_PER_ROLL;
    File[] files = new File(f1, "current").listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            if (name.startsWith(NNStorage.getFinalizedEditsFileName(startErrorTxId, endErrorTxId))) {
                return true;
            }
            return false;
        }
    });
    assertEquals(1, files.length);
    long fileLen = files[0].length();
    LOG.debug("Corrupting Log File: " + files[0] + " len: " + fileLen);
    RandomAccessFile rwf = new RandomAccessFile(files[0], "rw");
    // seek to checksum bytes
    rwf.seek(fileLen - 4);
    int b = rwf.readInt();
    rwf.seek(fileLen - 4);
    rwf.writeInt(b + 1);
    rwf.close();
    FSEditLog editlog = getFSEditLog(storage);
    editlog.initJournalsForWrite();
    long startTxId = 1;
    Collection<EditLogInputStream> streams = null;
    try {
        streams = editlog.selectInputStreams(startTxId, 4 * TXNS_PER_ROLL);
        readAllEdits(streams, startTxId);
    } catch (IOException e) {
        LOG.error("edit log failover didn't work", e);
        fail("Edit log failover didn't work");
    } finally {
        IOUtils.cleanup(null, streams.toArray(new EditLogInputStream[0]));
    }
}
Also used : IOException(java.io.IOException) URI(java.net.URI) FilenameFilter(java.io.FilenameFilter) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 7 with FilenameFilter

use of java.io.FilenameFilter in project hadoop by apache.

the class TestFileJournalManager method testManyLogsWithCorruptInprogress.

/** 
   * Test that we can load an edits directory with a corrupt inprogress file.
   * The corrupt inprogress file should be moved to the side.
   */
@Test
public void testManyLogsWithCorruptInprogress() throws IOException {
    File f = new File(TestEditLog.TEST_DIR + "/manylogswithcorruptinprogress");
    NNStorage storage = setupEdits(Collections.<URI>singletonList(f.toURI()), 10, new AbortSpec(10, 0));
    StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
    File[] files = new File(f, "current").listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            if (name.startsWith("edits_inprogress")) {
                return true;
            }
            return false;
        }
    });
    assertEquals(files.length, 1);
    corruptAfterStartSegment(files[0]);
    FileJournalManager jm = new FileJournalManager(conf, sd, storage);
    assertEquals(10 * TXNS_PER_ROLL + 1, getNumberOfTransactions(jm, 1, true, false));
}
Also used : FilenameFilter(java.io.FilenameFilter) AbortSpec(org.apache.hadoop.hdfs.server.namenode.TestEditLog.AbortSpec) StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 8 with FilenameFilter

use of java.io.FilenameFilter in project hadoop by apache.

the class TestFileJournalManager method testManyLogsWithGaps.

/** 
   * Test that we receive the correct number of transactions when we count
   * the number of transactions around gaps.
   * Set up a single edits directory, with no failures. Delete the 4th logfile.
   * Test that getNumberOfTransactions returns the correct number of 
   * transactions before this gap and after this gap. Also verify that if you
   * try to count on the gap that an exception is thrown.
   */
@Test
public void testManyLogsWithGaps() throws IOException {
    File f = new File(TestEditLog.TEST_DIR + "/manylogswithgaps");
    NNStorage storage = setupEdits(Collections.<URI>singletonList(f.toURI()), 10);
    StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
    final long startGapTxId = 3 * TXNS_PER_ROLL + 1;
    final long endGapTxId = 4 * TXNS_PER_ROLL;
    File[] files = new File(f, "current").listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            if (name.startsWith(NNStorage.getFinalizedEditsFileName(startGapTxId, endGapTxId))) {
                return true;
            }
            return false;
        }
    });
    assertEquals(1, files.length);
    assertTrue(files[0].delete());
    FileJournalManager jm = new FileJournalManager(conf, sd, storage);
    assertEquals(startGapTxId - 1, getNumberOfTransactions(jm, 1, true, true));
    assertEquals(0, getNumberOfTransactions(jm, startGapTxId, true, true));
    // rolled 10 times so there should be 11 files.
    assertEquals(11 * TXNS_PER_ROLL - endGapTxId, getNumberOfTransactions(jm, endGapTxId + 1, true, true));
}
Also used : FilenameFilter(java.io.FilenameFilter) StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 9 with FilenameFilter

use of java.io.FilenameFilter in project storm by apache.

the class Localizer method readCurrentBlobs.

// Looks for files in the directory with .current suffix
protected File[] readCurrentBlobs(String location) {
    File dir = new File(location);
    File[] files = null;
    if (dir.exists()) {
        files = dir.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(Utils.DEFAULT_CURRENT_BLOB_SUFFIX);
            }
        });
    }
    return files;
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 10 with FilenameFilter

use of java.io.FilenameFilter in project hive by apache.

the class QTestUtil method ensureQvFileList.

private static void ensureQvFileList(String queryDir) {
    if (cachedQvFileList != null)
        return;
    // Not thread-safe.
    System.out.println("Getting versions from " + queryDir);
    cachedQvFileList = (new File(queryDir)).list(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".qv");
        }
    });
    // no files at all
    if (cachedQvFileList == null)
        return;
    Arrays.sort(cachedQvFileList, String.CASE_INSENSITIVE_ORDER);
    List<String> defaults = getVersionFilesInternal("default");
    cachedDefaultQvFileList = (defaults != null) ? ImmutableList.copyOf(defaults) : ImmutableList.<String>of();
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Aggregations

FilenameFilter (java.io.FilenameFilter)354 File (java.io.File)350 IOException (java.io.IOException)87 ArrayList (java.util.ArrayList)61 Test (org.junit.Test)49 URL (java.net.URL)19 RandomAccessFile (java.io.RandomAccessFile)18 List (java.util.List)17 HashSet (java.util.HashSet)15 FileOutputStream (java.io.FileOutputStream)14 MalformedURLException (java.net.MalformedURLException)12 FileFilter (java.io.FileFilter)11 FileNotFoundException (java.io.FileNotFoundException)11 TestClient (org.syncany.tests.util.TestClient)11 FileWriter (java.io.FileWriter)10 HashMap (java.util.HashMap)10 ZipFile (java.util.zip.ZipFile)10 BufferedWriter (java.io.BufferedWriter)9 FileInputStream (java.io.FileInputStream)9 FileReader (java.io.FileReader)9