Search in sources :

Example 16 with JournalEntry

use of alluxio.proto.journal.Journal.JournalEntry in project alluxio by Alluxio.

the class UfsJournalReader method readInternal.

/**
 * Reads the next journal entry.
 *
 * @return the journal entry, null if no journal entry is found
 */
private Journal.JournalEntry readInternal() throws IOException {
    if (mInputStream == null) {
        return null;
    }
    JournalEntry entry = mInputStream.mReader.readEntry();
    if (entry != null) {
        return entry;
    }
    if (mInputStream.mFile.isIncompleteLog()) {
        // Incomplete logs may end early.
        return null;
    } else {
        Preconditions.checkState(mInputStream.mFile.isCompletedLog(), "Expected log to be either checkpoint, incomplete, or complete");
        ProcessUtils.fatalError(LOG, "Journal entry %s was truncated", mNextSequenceNumber);
        return null;
    }
}
Also used : JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Example 17 with JournalEntry

use of alluxio.proto.journal.Journal.JournalEntry in project alluxio by Alluxio.

the class JournalTool method main.

/**
 * Reads a journal via
 * {@code java -cp \
 * assembly/server/target/alluxio-assembly-server-<ALLUXIO-VERSION>-jar-with-dependencies.jar \
 * alluxio.master.journal.JournalTool < journal/FileSystemMaster/log.out}.
 *
 * @param args arguments passed to the tool
 */
public static void main(String[] args) throws IOException {
    if (!parseInputArgs(args)) {
        usage();
        System.exit(EXIT_FAILED);
    }
    if (sHelp) {
        usage();
        System.exit(EXIT_SUCCEEDED);
    }
    if (!sNoTimeout && !stdinHasData()) {
        System.exit(EXIT_FAILED);
    }
    JournalFormatter formatter = new ProtoBufJournalFormatter();
    try (JournalInputStream journalStream = formatter.deserialize(System.in)) {
        JournalEntry entry;
        while ((entry = journalStream.read()) != null) {
            System.out.print(entry);
            System.out.println(ENTRY_SEPARATOR);
        }
    }
}
Also used : JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Example 18 with JournalEntry

use of alluxio.proto.journal.Journal.JournalEntry in project SSM by Intel-bigdata.

the class AlluxioEntryFetchAndApplyTask method run.

@Override
public void run() {
    LOG.trace("AlluxioEntryFetchAndApplyTask run at " + new Date());
    try {
        JournalEntry journalEntry = journalReader.read();
        while (journalEntry != null) {
            entryApplier.apply(journalEntry);
            lastSn.getAndSet(journalEntry.getSequenceNumber());
            metaStore.updateAndInsertIfNotExist(new SystemInfo(SmartConstants.SMART_ALLUXIO_LAST_ENTRY_SN, String.valueOf(lastSn.get())));
            journalEntry = journalReader.read();
        }
    } catch (Throwable t) {
        LOG.error("Alluxio Entry Apply Events error", t);
    }
}
Also used : SystemInfo(org.smartdata.model.SystemInfo) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) Date(java.util.Date)

Example 19 with JournalEntry

use of alluxio.proto.journal.Journal.JournalEntry in project SSM by Intel-bigdata.

the class TestAlluxioEntryApplier method testRenameApplier.

@Test
public void testRenameApplier() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    AlluxioEntryApplier entryApplier = new AlluxioEntryApplier(metaStore, fs);
    FileInfo fooFile = FileInfo.newBuilder().setFileId(50331647).setIsdir(false).setPath("/bar/foobar1").build();
    metaStore.insertFile(fooFile);
    BackUpInfo backUpInfo = new BackUpInfo(1L, "/bar/foobar1", "remote/dest/", 10);
    metaStore.insertBackUpInfo(backUpInfo);
    alluxio.wire.FileInfo info1 = new alluxio.wire.FileInfo().setFileId(50331647).setPath("/bar/foobar1").setLength(300L).setFolder(false).setBlockSizeBytes(310000).setLastModificationTimeMs(1515665270681L).setCreationTimeMs(1515665270681L).setMode(493).setOwner("user1").setGroup("group1");
    URIStatus status1 = new URIStatus(info1);
    Mockito.when(fs.getStatus(new AlluxioURI("/bar/foobar1"))).thenReturn(status1);
    RenameEntry renameEntry = RenameEntry.newBuilder().setId(50331647).setOpTimeMs(1515666148444L).setDstPath("/bar/foobar1_new").build();
    JournalEntry renameJEntry = JournalEntry.newBuilder().setRename(renameEntry).build();
    entryApplier.apply(renameJEntry);
    List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/bar/foobar1");
    Assert.assertTrue(fileDiffs.size() > 0);
    for (FileDiff fileDiff : fileDiffs) {
        if (fileDiff.getDiffType().equals(FileDiffType.RENAME)) {
            Assert.assertEquals("/bar/foobar1", fileDiff.getSrc());
            Assert.assertEquals("/bar/foobar1_new", fileDiff.getParameters().get("-dest"));
        }
    }
}
Also used : AlluxioEntryApplier(org.smartdata.alluxio.metric.fetcher.AlluxioEntryApplier) URIStatus(alluxio.client.file.URIStatus) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) FileInfo(org.smartdata.model.FileInfo) BackUpInfo(org.smartdata.model.BackUpInfo) FileSystem(alluxio.client.file.FileSystem) FileDiff(org.smartdata.model.FileDiff) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 20 with JournalEntry

use of alluxio.proto.journal.Journal.JournalEntry in project SSM by Intel-bigdata.

the class TestAlluxioEntryApplier method testInodeDirectoryApplier.

@Test
public void testInodeDirectoryApplier() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    AlluxioEntryApplier entryApplier = new AlluxioEntryApplier(metaStore, fs);
    FileInfo rootDir = FileInfo.newBuilder().setFileId(0).setIsdir(true).setPath("/").build();
    metaStore.insertFile(rootDir);
    alluxio.wire.FileInfo info1 = new alluxio.wire.FileInfo().setFileId(1).setPath("/dir1").setLength(0L).setFolder(true).setBlockSizeBytes(1000000).setLastModificationTimeMs(1528876616216L).setCreationTimeMs(1528876616216L).setMode(493).setOwner("user1").setGroup("group1");
    URIStatus status1 = new URIStatus(info1);
    Mockito.when(fs.getStatus(new AlluxioURI("/dir1"))).thenReturn(status1);
    InodeDirectoryEntry inodeDirectoryEntry = InodeDirectoryEntry.newBuilder().setId(1).setParentId(0).setName("dir1").setPersistenceState("NOT_PERSISTED").setPinned(false).setCreationTimeMs(1528876616216L).setLastModificationTimeMs(1528876616216L).setOwner("user1").setGroup("group1").setMode(493).setMountPoint(false).setDirectChildrenLoaded(false).setTtl(-1L).setTtlAction(PTtlAction.DELETE).build();
    JournalEntry inodeDirectoryJEntry = JournalEntry.newBuilder().setInodeDirectory(inodeDirectoryEntry).build();
    entryApplier.apply(inodeDirectoryJEntry);
    Assert.assertTrue(metaStore.getFile().get(0).getPath().equals("/"));
    Assert.assertTrue(metaStore.getFile().get(1).getPath().equals("/dir1"));
    Assert.assertEquals("user1", metaStore.getFile("/dir1").getOwner());
    Assert.assertEquals(1528876616216L, metaStore.getFile("/dir1").getModificationTime());
}
Also used : FileInfo(org.smartdata.model.FileInfo) FileSystem(alluxio.client.file.FileSystem) AlluxioEntryApplier(org.smartdata.alluxio.metric.fetcher.AlluxioEntryApplier) URIStatus(alluxio.client.file.URIStatus) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

JournalEntry (alluxio.proto.journal.Journal.JournalEntry)34 IOException (java.io.IOException)11 AlluxioURI (alluxio.AlluxioURI)8 Test (org.junit.Test)8 FileSystem (alluxio.client.file.FileSystem)6 URIStatus (alluxio.client.file.URIStatus)6 AlluxioEntryApplier (org.smartdata.alluxio.metric.fetcher.AlluxioEntryApplier)6 FileInfo (org.smartdata.model.FileInfo)6 BackUpInfo (org.smartdata.model.BackUpInfo)5 FileDiff (org.smartdata.model.FileDiff)5 JournalClosedException (alluxio.exception.JournalClosedException)2 IOJournalClosedException (alluxio.exception.JournalClosedException.IOJournalClosedException)2 JournalContext (alluxio.master.journal.JournalContext)2 JournalEntryStreamReader (alluxio.master.journal.JournalEntryStreamReader)2 CloseableIterator (alluxio.resource.CloseableIterator)2 Timer (com.codahale.metrics.Timer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2