Search in sources :

Example 1 with UfsJournal

use of alluxio.master.journal.ufs.UfsJournal in project alluxio by Alluxio.

the class UfsJournalIntegrationTest method deleteFsMasterJournalLogs.

private void deleteFsMasterJournalLogs() throws Exception {
    String journalFolder = mLocalAlluxioCluster.getLocalAlluxioMaster().getJournalFolder();
    UfsJournal journal = new UfsJournal(new URI(PathUtils.concatPath(journalFolder, Constants.FILE_SYSTEM_MASTER_NAME)), new NoopMaster(), 0, Collections::emptySet);
    if (UfsJournalSnapshot.getCurrentLog(journal) != null) {
        UnderFileSystem.Factory.create(journalFolder, ServerConfiguration.global()).deleteFile(UfsJournalSnapshot.getCurrentLog(journal).getLocation().toString());
    }
}
Also used : Collections(java.util.Collections) AlluxioURI(alluxio.AlluxioURI) URI(java.net.URI) UfsJournal(alluxio.master.journal.ufs.UfsJournal) NoopMaster(alluxio.master.NoopMaster)

Example 2 with UfsJournal

use of alluxio.master.journal.ufs.UfsJournal in project alluxio by Alluxio.

the class TriggeredCheckpointTest method ufsJournal.

@Test
public void ufsJournal() throws Exception {
    int numFiles = 100;
    MultiProcessCluster cluster = MultiProcessCluster.newBuilder(PortCoordination.TRIGGERED_UFS_CHECKPOINT).setClusterName("TriggeredUfsCheckpointTest").addProperty(PropertyKey.MASTER_JOURNAL_TYPE, JournalType.UFS.toString()).addProperty(PropertyKey.MASTER_JOURNAL_CHECKPOINT_PERIOD_ENTRIES, String.valueOf(numFiles)).setNumMasters(1).setNumWorkers(1).build();
    try {
        cluster.start();
        cluster.waitForAllNodesRegistered(20 * Constants.SECOND_MS);
        // Get enough journal entries
        createFiles(cluster, numFiles);
        // Trigger checkpoint
        Assert.assertEquals(cluster.getMasterAddresses().get(0).getHostname(), cluster.getMetaMasterClient().checkpoint());
        String journalLocation = cluster.getJournalDir();
        UfsJournal ufsJournal = new UfsJournal(URIUtils.appendPathOrDie(new URI(journalLocation), Constants.FILE_SYSTEM_MASTER_NAME), new NoopMaster(""), 0, Collections::emptySet);
        Assert.assertEquals(1, UfsJournalSnapshot.getSnapshot(ufsJournal).getCheckpoints().size());
        validateCheckpointInClusterRestart(cluster);
        cluster.notifySuccess();
    } finally {
        cluster.destroy();
    }
}
Also used : MultiProcessCluster(alluxio.multi.process.MultiProcessCluster) Collections(java.util.Collections) AlluxioURI(alluxio.AlluxioURI) URI(java.net.URI) UfsJournal(alluxio.master.journal.ufs.UfsJournal) NoopMaster(alluxio.master.NoopMaster) Test(org.junit.Test)

Example 3 with UfsJournal

use of alluxio.master.journal.ufs.UfsJournal in project alluxio by Alluxio.

the class UfsJournalDumper method dumpJournal.

@Override
public void dumpJournal() throws Throwable {
    try (UfsJournal journal = new UfsJournalSystem(getJournalLocation(mInputDir), 0).createJournal(new NoopMaster(mMaster));
        PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(mJournalEntryFile)));
        JournalReader reader = new UfsJournalReader(journal, mStart, true)) {
        boolean done = false;
        while (!done && reader.getNextSequenceNumber() < mEnd) {
            JournalReader.State state = reader.advance();
            switch(state) {
                case CHECKPOINT:
                    try (CheckpointInputStream checkpoint = reader.getCheckpoint()) {
                        Path dir = Paths.get(mCheckpointsDir + "-" + reader.getNextSequenceNumber());
                        Files.createDirectories(dir);
                        readCheckpoint(checkpoint, dir);
                    }
                    break;
                case LOG:
                    Journal.JournalEntry entry = reader.getEntry();
                    out.println(ENTRY_SEPARATOR);
                    out.print(entry);
                    break;
                case DONE:
                    done = true;
                    break;
                default:
                    throw new RuntimeException("Unknown state: " + state);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) UfsJournal(alluxio.master.journal.ufs.UfsJournal) Journal(alluxio.proto.journal.Journal) CheckpointInputStream(alluxio.master.journal.checkpoint.CheckpointInputStream) FileOutputStream(java.io.FileOutputStream) UfsJournalReader(alluxio.master.journal.ufs.UfsJournalReader) UfsJournalSystem(alluxio.master.journal.ufs.UfsJournalSystem) BufferedOutputStream(java.io.BufferedOutputStream) UfsJournal(alluxio.master.journal.ufs.UfsJournal) NoopMaster(alluxio.master.NoopMaster) JournalReader(alluxio.master.journal.JournalReader) UfsJournalReader(alluxio.master.journal.ufs.UfsJournalReader)

Example 4 with UfsJournal

use of alluxio.master.journal.ufs.UfsJournal in project alluxio by Alluxio.

the class UfsJournalIntegrationTest method multipleFlush.

/**
 * Tests flushing the journal multiple times, without writing any data.
 */
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.MASTER_JOURNAL_LOG_SIZE_BYTES_MAX, "0" })
public void multipleFlush() throws Exception {
    String journalFolder = mLocalAlluxioCluster.getLocalAlluxioMaster().getJournalFolder();
    mLocalAlluxioCluster.stop();
    UfsJournal journal = new UfsJournal(new URI(PathUtils.concatPath(journalFolder, Constants.FILE_SYSTEM_MASTER_NAME)), new NoopMaster(), 0, Collections::emptySet);
    journal.start();
    journal.gainPrimacy();
    UfsStatus[] paths = UnderFileSystem.Factory.create(journalFolder, ServerConfiguration.global()).listStatus(journal.getLogDir().toString());
    int expectedSize = paths == null ? 0 : paths.length;
    journal.flush();
    journal.flush();
    journal.flush();
    journal.close();
    paths = UnderFileSystem.Factory.create(journalFolder, ServerConfiguration.global()).listStatus(journal.getLogDir().toString());
    int actualSize = paths == null ? 0 : paths.length;
    // No new files are created.
    Assert.assertEquals(expectedSize, actualSize);
}
Also used : UfsStatus(alluxio.underfs.UfsStatus) Collections(java.util.Collections) AlluxioURI(alluxio.AlluxioURI) URI(java.net.URI) UfsJournal(alluxio.master.journal.ufs.UfsJournal) NoopMaster(alluxio.master.NoopMaster) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 5 with UfsJournal

use of alluxio.master.journal.ufs.UfsJournal in project alluxio by Alluxio.

the class IntegrationTestUtils method waitForUfsJournalCheckpoint.

/**
 * Waits for a checkpoint to be written in the specified master's journal.
 *
 * @param masterName the name of the master
 * @param journalLocation the location of the journal
 */
public static void waitForUfsJournalCheckpoint(String masterName, URI journalLocation) throws TimeoutException, InterruptedException {
    UfsJournal journal = new UfsJournal(URIUtils.appendPathOrDie(journalLocation, masterName), new NoopMaster(""), 0, Collections::emptySet);
    CommonUtils.waitFor("checkpoint to be written", () -> {
        UfsJournalSnapshot snapshot;
        try {
            snapshot = UfsJournalSnapshot.getSnapshot(journal);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return !snapshot.getCheckpoints().isEmpty();
    });
}
Also used : IOException(java.io.IOException) Collections(java.util.Collections) UfsJournal(alluxio.master.journal.ufs.UfsJournal) NoopMaster(alluxio.master.NoopMaster) UfsJournalSnapshot(alluxio.master.journal.ufs.UfsJournalSnapshot)

Aggregations

NoopMaster (alluxio.master.NoopMaster)6 UfsJournal (alluxio.master.journal.ufs.UfsJournal)6 Collections (java.util.Collections)5 AlluxioURI (alluxio.AlluxioURI)4 URI (java.net.URI)4 Test (org.junit.Test)3 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)2 JournalReader (alluxio.master.journal.JournalReader)1 CheckpointInputStream (alluxio.master.journal.checkpoint.CheckpointInputStream)1 UfsJournalReader (alluxio.master.journal.ufs.UfsJournalReader)1 UfsJournalSnapshot (alluxio.master.journal.ufs.UfsJournalSnapshot)1 UfsJournalSystem (alluxio.master.journal.ufs.UfsJournalSystem)1 MultiProcessCluster (alluxio.multi.process.MultiProcessCluster)1 Journal (alluxio.proto.journal.Journal)1 UfsStatus (alluxio.underfs.UfsStatus)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Path (java.nio.file.Path)1