Search in sources :

Example 26 with CreateFileContext

use of alluxio.master.file.contexts.CreateFileContext in project alluxio by Alluxio.

the class FileSystemMasterFaultToleranceIntegrationTest method partitionTolerantCreateFile.

@Test
public void partitionTolerantCreateFile() throws Exception {
    // Create paths for the test.
    AlluxioURI testPath1 = new AlluxioURI("/testPath1");
    // Create context1 with unique operation id.
    CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setOperationId(new OperationId(UUID.randomUUID()).toFsProto())));
    // Create context2 with unique operation id.
    CreateFileContext context2 = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setOperationId(new OperationId(UUID.randomUUID()).toFsProto())));
    // Run partition tolerance test on leading master.
    {
        // Acquire file-system-master of leading master.
        final FileSystemMaster leadingFsMaster = mMultiMasterLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class);
        // Create the path the first time.
        leadingFsMaster.createFile(testPath1, context);
        // Create the path the second time with the same context.
        // It should just return successfully.
        FileInfo fileInfo = leadingFsMaster.createFile(testPath1, context);
        Assert.assertEquals(fileInfo.getFileId(), leadingFsMaster.getFileId(testPath1));
        // Create the file again with a different context.
        // It should fail with `FileAlreadyExistException`.
        assertThrows(FileAlreadyExistsException.class, () -> leadingFsMaster.createFile(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.
        final FileSystemMaster leadingFsMaster = mMultiMasterLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class);
        // Creating on the new leader with the original operation-id should succeed.
        FileInfo fileInfo = leadingFsMaster.createFile(testPath1, context);
        Assert.assertEquals(fileInfo.getFileId(), leadingFsMaster.getFileId(testPath1));
        // Creating on the new leader with a different operation-id should fail.
        assertThrows(FileAlreadyExistsException.class, () -> leadingFsMaster.createFile(testPath1, context2));
    }
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) FileInfo(alluxio.wire.FileInfo) OperationId(alluxio.wire.OperationId) FileSystemMaster(alluxio.master.file.FileSystemMaster) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

CreateFileContext (alluxio.master.file.contexts.CreateFileContext)26 Test (org.junit.Test)22 AlluxioURI (alluxio.AlluxioURI)14 FileInfo (alluxio.wire.FileInfo)10 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)9 CreateDirectoryContext (alluxio.master.file.contexts.CreateDirectoryContext)5 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)4 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 AccessControlList (alluxio.security.authorization.AccessControlList)2 DefaultAccessControlList (alluxio.security.authorization.DefaultAccessControlList)2 AuthenticatedUserRule (alluxio.AuthenticatedUserRule)1 BlockInfoException (alluxio.exception.BlockInfoException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 FileSystemMaster (alluxio.master.file.FileSystemMaster)1 CompleteFileContext (alluxio.master.file.contexts.CompleteFileContext)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 MergeJournalContext (alluxio.master.journal.MergeJournalContext)1 UpdateInodeEntry (alluxio.proto.journal.File.UpdateInodeEntry)1 LockResource (alluxio.resource.LockResource)1 Mode (alluxio.security.authorization.Mode)1