Search in sources :

Example 1 with OperationId

use of alluxio.wire.OperationId in project alluxio by Alluxio.

the class InodeTreePersistentState method applyAndJournal.

/**
 * Deletes an inode (may be either a file or directory).
 *
 * @param context journal context supplier
 * @param entry delete file entry
 */
public void applyAndJournal(Supplier<JournalContext> context, DeleteFileEntry entry) {
    // operation holds that lock until after it has appended to the journal.
    try {
        JournalEntry.Builder builder = JournalEntry.newBuilder().setDeleteFile(entry);
        OperationId opId = getOpId(context);
        if (opId != null) {
            builder.setOperationId(opId.toJournalProto());
        }
        context.get().append(builder.build());
        applyDelete(entry);
    } catch (Throwable t) {
        // Delete entries should always apply cleanly, but if it somehow fails, we are in a state
        // where we've journaled the delete, but failed to make the in-memory update. We don't yet
        // have a way to recover from this, so we give a fatal error.
        ProcessUtils.fatalError(LOG, t, "Failed to apply entry %s", entry);
    }
}
Also used : OperationId(alluxio.wire.OperationId) JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Example 2 with OperationId

use of alluxio.wire.OperationId in project alluxio by Alluxio.

the class InodeTreePersistentState method applyAndJournal.

/**
 * Renames an inode.
 *
 * @param context journal context supplier
 * @param entry rename entry
 */
public void applyAndJournal(Supplier<JournalContext> context, RenameEntry entry) {
    try {
        applyRename(entry);
        JournalEntry.Builder builder = JournalEntry.newBuilder().setRename(entry);
        OperationId opId = getOpId(context);
        if (opId != null) {
            builder.setOperationId(opId.toJournalProto());
        }
        context.get().append(builder.build());
    } catch (Throwable t) {
        ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry);
        // fatalError will usually system.exit
        throw t;
    }
}
Also used : OperationId(alluxio.wire.OperationId) JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Example 3 with OperationId

use of alluxio.wire.OperationId in project alluxio by Alluxio.

the class FileSystemMasterFaultToleranceIntegrationTest method partitionTolerantDeleteFile.

@Test
public void partitionTolerantDeleteFile() throws Exception {
    // Create paths for the test.
    AlluxioURI testPath1 = new AlluxioURI("/testPath1");
    // Create context1 with unique operation id.
    DeleteContext context = DeleteContext.mergeFrom(DeletePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setOperationId(new OperationId(UUID.randomUUID()).toFsProto())));
    // Create context2 with unique operation id.
    DeleteContext context2 = DeleteContext.mergeFrom(DeletePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setOperationId(new OperationId(UUID.randomUUID()).toFsProto())));
    {
        // Acquire file-system-master of leading master.
        FileSystemMaster leadingFsMaster = mMultiMasterLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class);
        // Create the path to delete.
        leadingFsMaster.createFile(testPath1, CreateFileContext.defaults());
        leadingFsMaster.completeFile(testPath1, CompleteFileContext.defaults());
        // Delete the path the first time.
        leadingFsMaster.delete(testPath1, context);
        // Delete the path the second time with the same context.
        // It should just return successfully.
        leadingFsMaster.delete(testPath1, context);
        // Delete the path again with a different context.
        // It should fail with `FileDoesNotExistException`.
        assertThrows(FileDoesNotExistException.class, () -> leadingFsMaster.delete(testPath1, context2));
    }
    // Promote standby to be a leader and reset test state.
    mMultiMasterLocalAlluxioCluster.stopLeader();
    mMultiMasterLocalAlluxioCluster.waitForNewMaster(CLUSTER_WAIT_TIMEOUT_MS);
    mAuthenticatedUser.resetUser();
    // Run partition tolerance test on the *new* leading master.
    {
        // Acquire file-system-master of leading master.
        FileSystemMaster leadingFsMaster = mMultiMasterLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class);
        // Deleting the file on the new leader with the original operation-id should succeed.
        leadingFsMaster.delete(testPath1, context);
        // Deleting on the new leader with a different operation-id.
        // It should fail with `FileDoesNotExistException`.
        assertThrows(FileDoesNotExistException.class, () -> leadingFsMaster.delete(testPath1, context2));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeleteContext(alluxio.master.file.contexts.DeleteContext) OperationId(alluxio.wire.OperationId) FileSystemMaster(alluxio.master.file.FileSystemMaster) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 4 with OperationId

use of alluxio.wire.OperationId in project alluxio by Alluxio.

the class AlluxioFileOutStream method close.

@Override
public void close() throws IOException {
    if (mClosed) {
        return;
    }
    try {
        if (mCurrentBlockOutStream != null) {
            mPreviousBlockOutStreams.add(mCurrentBlockOutStream);
        }
        CompleteFilePOptions.Builder optionsBuilder = CompleteFilePOptions.newBuilder();
        optionsBuilder.setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setOperationId(new OperationId(UUID.randomUUID()).toFsProto()).buildPartial());
        if (mUnderStorageType.isSyncPersist()) {
            if (mCanceled) {
                mUnderStorageOutputStream.cancel();
            } else {
                mUnderStorageOutputStream.close();
                optionsBuilder.setUfsLength(mBytesWritten);
            }
        }
        if (mAlluxioStorageType.isStore()) {
            if (mCanceled) {
                for (BlockOutStream bos : mPreviousBlockOutStreams) {
                    bos.cancel();
                }
            } else {
                // write(blockN), and blockN evicts the committed blockN-1 and causing file lost.
                if (mCurrentBlockOutStream != null) {
                    mCurrentBlockOutStream.close();
                }
                for (BlockOutStream bos : mPreviousBlockOutStreams) {
                    bos.close();
                }
            }
        }
        // Whether to complete file with async persist request.
        if (!mCanceled && mUnderStorageType.isAsyncPersist() && mOptions.getPersistenceWaitTime() != Constants.NO_AUTO_PERSIST) {
            optionsBuilder.setAsyncPersistOptions(FileSystemOptions.scheduleAsyncPersistDefaults(mContext.getPathConf(mUri)).toBuilder().setCommonOptions(mOptions.getCommonOptions()).setPersistenceWaitTime(mOptions.getPersistenceWaitTime()));
        }
        // Complete the file if it's ready to be completed.
        if (!mCanceled && (mUnderStorageType.isSyncPersist() || mAlluxioStorageType.isStore())) {
            try (CloseableResource<FileSystemMasterClient> masterClient = mContext.acquireMasterClientResource()) {
                masterClient.get().completeFile(mUri, optionsBuilder.build());
            }
        }
    } catch (Throwable e) {
        // IOException will be thrown as-is.
        throw mCloser.rethrow(e);
    } finally {
        mClosed = true;
        mCloser.close();
    }
}
Also used : BlockOutStream(alluxio.client.block.stream.BlockOutStream) OperationId(alluxio.wire.OperationId) CompleteFilePOptions(alluxio.grpc.CompleteFilePOptions)

Example 5 with OperationId

use of alluxio.wire.OperationId in project alluxio by Alluxio.

the class InodeTreePersistentState method applyAndJournal.

/**
 * Adds an inode to the inode tree.
 *
 * @param context journal context supplier
 * @param inode an inode to add and create a journal entry for
 * @param path path of the new inode
 */
public void applyAndJournal(Supplier<JournalContext> context, MutableInode<?> inode, String path) {
    try {
        applyCreateInode(inode);
        JournalEntry.Builder builder = inode.toJournalEntry(Preconditions.checkNotNull(path)).toBuilder();
        OperationId opId = getOpId(context);
        if (opId != null) {
            builder.setOperationId(opId.toJournalProto());
        }
        context.get().append(builder.build());
    } catch (Throwable t) {
        ProcessUtils.fatalError(LOG, t, "Failed to apply %s", inode);
        // fatalError will usually system.exit
        throw t;
    }
}
Also used : OperationId(alluxio.wire.OperationId) JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Aggregations

OperationId (alluxio.wire.OperationId)10 AlluxioURI (alluxio.AlluxioURI)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)5 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)5 Test (org.junit.Test)5 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)4 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 DeleteContext (alluxio.master.file.contexts.DeleteContext)2 BlockOutStream (alluxio.client.block.stream.BlockOutStream)1 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 CompleteFilePOptions (alluxio.grpc.CompleteFilePOptions)1 CompleteFileContext (alluxio.master.file.contexts.CompleteFileContext)1 CreateFileContext (alluxio.master.file.contexts.CreateFileContext)1 RenameContext (alluxio.master.file.contexts.RenameContext)1 FileInfo (alluxio.wire.FileInfo)1