Search in sources :

Example 1 with MasterProcess

use of alluxio.master.MasterProcess in project alluxio by Alluxio.

the class BackupCommandStateLockingIntegrationTest method timeoutWhenStateLockAcquired.

@Test
public void timeoutWhenStateLockAcquired() throws Exception {
    // Grab the master state-lock-manager via reflection.
    MasterProcess masterProcess = Whitebox.getInternalState(mLocalAlluxioCluster.getLocalAlluxioMaster(), "mMasterProcess");
    MasterContext masterCtx = Whitebox.getInternalState(masterProcess, "mContext");
    StateLockManager stateLockManager = masterCtx.getStateLockManager();
    // Lock the state-change lock on the master before initiating the backup.
    try (LockResource lr = stateLockManager.lockExclusive(StateLockOptions.defaults())) {
        // Prepare for a backup.
        Path dir = Paths.get(ServerConfiguration.getString(PropertyKey.MASTER_BACKUP_DIRECTORY));
        Files.createDirectories(dir);
        assertEquals(0, Files.list(dir).count());
        // Initiate backup. It should fail.
        int errCode = mFsAdminShell.run("backup");
        assertTrue(mOutput.toString().contains(ExceptionMessage.STATE_LOCK_TIMED_OUT.getMessage(3000)));
        assertNotEquals(0, errCode);
    }
}
Also used : Path(java.nio.file.Path) LockResource(alluxio.resource.LockResource) StateLockManager(alluxio.master.StateLockManager) MasterProcess(alluxio.master.MasterProcess) MasterContext(alluxio.master.MasterContext) Test(org.junit.Test)

Example 2 with MasterProcess

use of alluxio.master.MasterProcess in project alluxio by Alluxio.

the class FileInStreamRehydrationIntegrationTest method testRehydration.

@Test
public void testRehydration() throws Exception {
    FileSystem fs = FileSystem.Factory.create(ServerConfiguration.global());
    // Create a file with 10 blocks.
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build();
    byte[] content = generateContent(BLOCK_BYTES * 10);
    try (FileOutStream os = fs.createFile(filePath, op)) {
        os.write(content);
    }
    // Validate file size and content.
    validateAndCloseFileStream(mFileSystem.openFile(filePath), content);
    // Grab the block master for emulating lost blocks.
    MasterProcess masterProcess = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster(), "mMasterProcess");
    BlockMaster blockMaster = masterProcess.getMaster(BlockMaster.class);
    // Remove blocks externally from block-master.
    URIStatus status = fs.getStatus(filePath);
    blockMaster.removeBlocks(status.getBlockIds(), true);
    // Validate file size and content.
    validateAndCloseFileStream(mFileSystem.openFile(filePath), content);
}
Also used : BlockMaster(alluxio.master.block.BlockMaster) FileSystem(alluxio.client.file.FileSystem) FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) MasterProcess(alluxio.master.MasterProcess) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AbstractFileOutStreamIntegrationTest(alluxio.client.fs.io.AbstractFileOutStreamIntegrationTest)

Example 3 with MasterProcess

use of alluxio.master.MasterProcess in project alluxio by Alluxio.

the class BackupCommandStateLockingIntegrationTest method takeBackupDuringExclusiveOnlyPhase.

@Test
public void takeBackupDuringExclusiveOnlyPhase() throws Exception {
    // Grab the master state-lock-manager via reflection.
    MasterProcess masterProcess = Whitebox.getInternalState(mLocalAlluxioCluster.getLocalAlluxioMaster(), "mMasterProcess");
    MasterContext masterCtx = Whitebox.getInternalState(masterProcess, "mContext");
    StateLockManager stateLockManager = masterCtx.getStateLockManager();
    // Activate exclusive-only phase via reflection.
    // Cannot make via cluster property due to lack of support from test utilities.
    long exclusiveOnlyDurationMs = 30000;
    Whitebox.setInternalState(stateLockManager, "mExclusiveOnlyDeadlineMs", System.currentTimeMillis() + exclusiveOnlyDurationMs);
    try {
        // getStatus() should fail during exclusive-only phase.
        mException.expect(AlluxioException.class);
        mLocalAlluxioCluster.getClient().getStatus(new AlluxioURI("/"));
        // Prepare for a backup.
        Path dir = Paths.get(ServerConfiguration.getString(PropertyKey.MASTER_BACKUP_DIRECTORY));
        Files.createDirectories(dir);
        assertEquals(0, Files.list(dir).count());
        // Take the backup. It should be allowed.
        int errCode = mFsAdminShell.run("backup");
        assertEquals("", mErrOutput.toString());
        assertEquals(0, errCode);
        assertEquals(1, Files.list(dir).count());
    } finally {
        // Reset exclusive-only phase.
        Whitebox.setInternalState(stateLockManager, "mExclusiveOnlyDeadlineMs", -1);
    }
}
Also used : Path(java.nio.file.Path) StateLockManager(alluxio.master.StateLockManager) MasterProcess(alluxio.master.MasterProcess) MasterContext(alluxio.master.MasterContext) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

MasterProcess (alluxio.master.MasterProcess)3 Test (org.junit.Test)3 AlluxioURI (alluxio.AlluxioURI)2 MasterContext (alluxio.master.MasterContext)2 StateLockManager (alluxio.master.StateLockManager)2 Path (java.nio.file.Path)2 FileOutStream (alluxio.client.file.FileOutStream)1 FileSystem (alluxio.client.file.FileSystem)1 URIStatus (alluxio.client.file.URIStatus)1 AbstractFileOutStreamIntegrationTest (alluxio.client.fs.io.AbstractFileOutStreamIntegrationTest)1 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)1 BlockMaster (alluxio.master.block.BlockMaster)1 LockResource (alluxio.resource.LockResource)1