Search in sources :

Example 1 with WorkerProcess

use of alluxio.worker.WorkerProcess in project alluxio by Alluxio.

the class AbstractLocalAlluxioCluster method startWorkers.

/**
 * Configures and starts the worker(s).
 */
public void startWorkers() throws Exception {
    mWorkers = new ArrayList<>();
    for (int i = 0; i < mNumWorkers; i++) {
        mWorkers.add(WorkerProcess.Factory.create());
    }
    for (final WorkerProcess worker : mWorkers) {
        Runnable runWorker = () -> {
            try {
                worker.start();
            } catch (InterruptedException e) {
            // this is expected
            } catch (Exception e) {
                // Log the exception as the RuntimeException will be caught and handled silently by
                // JUnit
                LOG.error("Start worker error", e);
                throw new RuntimeException(e + " \n Start Worker Error \n" + e.getMessage(), e);
            }
        };
        Thread thread = new Thread(runWorker);
        thread.setName("WorkerThread-" + System.identityHashCode(thread));
        mWorkerThreads.add(thread);
        thread.start();
    }
    for (WorkerProcess worker : mWorkers) {
        TestUtils.waitForReady(worker);
    }
}
Also used : WorkerProcess(alluxio.worker.WorkerProcess) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) UnavailableException(alluxio.exception.status.UnavailableException)

Example 2 with WorkerProcess

use of alluxio.worker.WorkerProcess in project alluxio by Alluxio.

the class AbstractLocalAlluxioCluster method stopWorkers.

/**
 * Stops the workers.
 */
public void stopWorkers() throws Exception {
    if (mWorkers == null) {
        return;
    }
    for (WorkerProcess worker : mWorkers) {
        worker.stop();
    }
    for (Thread thread : mWorkerThreads) {
        while (thread.isAlive()) {
            LOG.info("Stopping thread {}.", thread.getName());
            thread.interrupt();
            thread.join(1000);
        }
    }
    mWorkerThreads.clear();
    // forget all the workers in the master
    LocalAlluxioMaster master = getLocalAlluxioMaster();
    if (master != null) {
        DefaultBlockMaster bm = (DefaultBlockMaster) master.getMasterProcess().getMaster(BlockMaster.class);
        bm.forgetAllWorkers();
    }
}
Also used : BlockMaster(alluxio.master.block.BlockMaster) DefaultBlockMaster(alluxio.master.block.DefaultBlockMaster) WorkerProcess(alluxio.worker.WorkerProcess) DefaultBlockMaster(alluxio.master.block.DefaultBlockMaster)

Example 3 with WorkerProcess

use of alluxio.worker.WorkerProcess in project alluxio by Alluxio.

the class LocalFirstPolicyIntegrationTest method test.

@Test
public void test() throws Exception {
    AlluxioMasterProcess master = AlluxioMasterProcess.Factory.create();
    WorkerProcess worker1 = AlluxioWorkerProcess.Factory.create(TieredIdentityFactory.fromString("node=node1,rack=rack1", ServerConfiguration.global()));
    WorkerProcess worker2 = AlluxioWorkerProcess.Factory.create(TieredIdentityFactory.fromString("node=node2,rack=rack2", ServerConfiguration.global()));
    runProcess(mExecutor, master);
    runProcess(mExecutor, worker1);
    runProcess(mExecutor, worker2);
    TestUtils.waitForReady(master);
    TestUtils.waitForReady(worker1);
    TestUtils.waitForReady(worker2);
    FileSystem fs = FileSystem.Factory.create(ServerConfiguration.global());
    // Write to the worker in node1
    {
        Whitebox.setInternalState(TieredIdentityFactory.class, "sInstance", TieredIdentityFactory.fromString("node=node1,rack=rack1", ServerConfiguration.global()));
        try {
            FileSystemTestUtils.createByteFile(fs, "/file1", WritePType.MUST_CACHE, 100);
        } finally {
            Whitebox.setInternalState(TieredIdentityFactory.class, "sInstance", (Object) null);
        }
        BlockWorker blockWorker1 = worker1.getWorker(BlockWorker.class);
        BlockWorker blockWorker2 = worker2.getWorker(BlockWorker.class);
        assertEquals(100, blockWorker1.getStoreMeta().getUsedBytes());
        assertEquals(0, blockWorker2.getStoreMeta().getUsedBytes());
    }
    // Write to the worker in rack2
    {
        Whitebox.setInternalState(TieredIdentityFactory.class, "sInstance", TieredIdentityFactory.fromString("node=node3,rack=rack2", ServerConfiguration.global()));
        try {
            FileSystemTestUtils.createByteFile(fs, "/file2", WritePType.MUST_CACHE, 10);
        } finally {
            Whitebox.setInternalState(TieredIdentityFactory.class, "sInstance", (Object) null);
        }
        BlockWorker blockWorker1 = worker1.getWorker(BlockWorker.class);
        BlockWorker blockWorker2 = worker2.getWorker(BlockWorker.class);
        assertEquals(100, blockWorker1.getStoreMeta().getUsedBytes());
        assertEquals(10, blockWorker2.getStoreMeta().getUsedBytes());
    }
}
Also used : WorkerProcess(alluxio.worker.WorkerProcess) AlluxioWorkerProcess(alluxio.worker.AlluxioWorkerProcess) AlluxioMasterProcess(alluxio.master.AlluxioMasterProcess) TieredIdentityFactory(alluxio.network.TieredIdentityFactory) FileSystem(alluxio.client.file.FileSystem) BlockWorker(alluxio.worker.block.BlockWorker) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

WorkerProcess (alluxio.worker.WorkerProcess)3 FileSystem (alluxio.client.file.FileSystem)1 UnavailableException (alluxio.exception.status.UnavailableException)1 AlluxioMasterProcess (alluxio.master.AlluxioMasterProcess)1 BlockMaster (alluxio.master.block.BlockMaster)1 DefaultBlockMaster (alluxio.master.block.DefaultBlockMaster)1 TieredIdentityFactory (alluxio.network.TieredIdentityFactory)1 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)1 AlluxioWorkerProcess (alluxio.worker.AlluxioWorkerProcess)1 BlockWorker (alluxio.worker.block.BlockWorker)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1