Search in sources :

Example 31 with JournalEntry

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

the class DefaultBlockMaster method removeBlocks.

@Override
public void removeBlocks(Collection<Long> blockIds, boolean delete) throws UnavailableException {
    try (JournalContext journalContext = createJournalContext()) {
        for (long blockId : blockIds) {
            Set<Long> workerIds;
            try (LockResource r = lockBlock(blockId)) {
                Optional<BlockMeta> block = mBlockStore.getBlock(blockId);
                if (!block.isPresent()) {
                    continue;
                }
                List<BlockLocation> locations = mBlockStore.getLocations(blockId);
                workerIds = new HashSet<>(locations.size());
                for (BlockLocation loc : locations) {
                    workerIds.add(loc.getWorkerId());
                }
                // processWorkerRemovedBlocks
                if (delete) {
                    // Make sure blockId is removed from mLostBlocks when the block metadata is deleted.
                    // Otherwise blockId in mLostBlock can be dangling index if the metadata is gone.
                    mLostBlocks.remove(blockId);
                    mBlockStore.removeBlock(blockId);
                    JournalEntry entry = JournalEntry.newBuilder().setDeleteBlock(DeleteBlockEntry.newBuilder().setBlockId(blockId)).build();
                    journalContext.append(entry);
                }
            }
            // workerRegister should be changed to address this race condition.
            for (long workerId : workerIds) {
                MasterWorkerInfo worker = mWorkers.getFirstByField(ID_INDEX, workerId);
                if (worker != null) {
                    try (LockResource r = worker.lockWorkerMeta(EnumSet.of(WorkerMetaLockSection.BLOCKS), false)) {
                        worker.updateToRemovedBlock(true, blockId);
                    }
                }
            }
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) JournalContext(alluxio.master.journal.JournalContext) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) BlockLocation(alluxio.proto.meta.Block.BlockLocation) BlockMeta(alluxio.proto.meta.Block.BlockMeta) JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Example 32 with JournalEntry

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

the class AsyncJournalWriterTest method failedWriteInternal.

/**
 * Simulates that exception occurs when writing {@link JournalEntry}.
 *
 * @param batchingEnabled whether to use a batch flush or not
 */
public void failedWriteInternal(boolean batchingEnabled) throws Exception {
    setupAsyncJournalWriter(batchingEnabled);
    // Start failing journal writes.
    // PS: Need to stop the writer before mocking because mMockJournalWriter could be
    // acceessed concurrently by the internal flush thread.
    mAsyncJournalWriter.stop();
    doThrow(new IOException("entry write failed")).when(mMockJournalWriter).write(any(JournalEntry.class));
    mAsyncJournalWriter.start();
    int entries = 5;
    for (int i = 0; i < entries; i++) {
        long flushCounter = mAsyncJournalWriter.appendEntry(JournalEntry.getDefaultInstance());
        // Assuming the flush counter starts from 0
        assertEquals(i + 1, flushCounter);
    }
    // Flushes should fail.
    for (int i = 1; i <= entries; i++) {
        try {
            mAsyncJournalWriter.flush(1);
            fail("journal flush should not succeed if journal write fails.");
        } catch (IOException e) {
        // This is expected.
        }
    }
    // Allow journal writes to succeed.
    // PS: Need to stop the writer before mocking because mMockJournalWriter could be
    // acceessed concurrently by the internal flush thread.
    mAsyncJournalWriter.stop();
    doNothing().when(mMockJournalWriter).write(any(JournalEntry.class));
    mAsyncJournalWriter.start();
    // Flushes should succeed.
    for (int i = 1; i <= entries; i++) {
        mAsyncJournalWriter.flush(i);
    }
    verify(mMockJournalWriter, atLeastOnce()).flush();
}
Also used : IOException(java.io.IOException) JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Example 33 with JournalEntry

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

the class AlluxioEntryFetcher method canReadFromLastSeqNum.

public static boolean canReadFromLastSeqNum(Long lastSn) {
    try {
        if (AlluxioJournalUtil.getCurrentSeqNum(conf) == lastSn) {
            return true;
        }
        JournalReader reader = AlluxioJournalUtil.getJournalReaderFromSn(conf, lastSn);
        JournalEntry entry = reader.read();
        return entry != null;
    } catch (Exception e) {
        return false;
    }
}
Also used : JournalEntry(alluxio.proto.journal.Journal.JournalEntry) InvalidJournalEntryException(alluxio.exception.InvalidJournalEntryException) IOException(java.io.IOException) MetaStoreException(org.smartdata.metastore.MetaStoreException) JournalReader(alluxio.master.journal.JournalReader)

Example 34 with JournalEntry

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

the class TestAlluxioEntryApplier method testSetAttributeApplier.

@Test
public void testSetAttributeApplier() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    AlluxioEntryApplier entryApplier = new AlluxioEntryApplier(metaStore, fs);
    FileInfo fooFile = FileInfo.newBuilder().setFileId(33554431).setIsdir(false).setPath("/foo/foobar").build();
    metaStore.insertFile(fooFile);
    BackUpInfo backUpInfo = new BackUpInfo(1L, "/foo/foobar", "remote/dest/", 10);
    metaStore.insertBackUpInfo(backUpInfo);
    alluxio.wire.FileInfo info1 = new alluxio.wire.FileInfo().setFileId(33554431).setPath("/foo/foobar").setLength(100L).setFolder(false).setBlockSizeBytes(210000).setLastModificationTimeMs(1515665470681L).setCreationTimeMs(1515665470681L).setMode(493).setOwner("user1").setGroup("group1");
    URIStatus status1 = new URIStatus(info1);
    Mockito.when(fs.getStatus(new AlluxioURI("/foo/foobar"))).thenReturn(status1);
    SetAttributeEntry setAttributeEntry = SetAttributeEntry.newBuilder().setId(33554431).setOpTimeMs(1515667208590658L).setPermission(511).build();
    JournalEntry setAttributeJEntry = JournalEntry.newBuilder().setSetAttribute(setAttributeEntry).build();
    entryApplier.apply(setAttributeJEntry);
    List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/foo/foobar");
    Assert.assertTrue(fileDiffs.size() > 0);
    for (FileDiff fileDiff : fileDiffs) {
        if (fileDiff.getDiffType().equals(FileDiffType.METADATA)) {
            Assert.assertEquals("511", fileDiff.getParameters().get("-permission"));
        }
    }
}
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)

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