Search in sources :

Example 11 with Command

use of alluxio.thrift.Command in project alluxio by Alluxio.

the class FileSystemMasterTest method freeDirWithPinnedFileAndForced.

/**
   * Tests the {@link FileSystemMaster#free} method with a directory with a file pinned when
   * forced flag is true.
   */
@Test
public void freeDirWithPinnedFileAndForced() throws Exception {
    mNestedFileOptions.setPersisted(true);
    long blockId = createFileWithSingleBlock(NESTED_FILE_URI);
    mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeOptions.defaults().setPinned(true));
    // free the parent dir of a pinned file with "forced"
    mFileSystemMaster.free(NESTED_FILE_URI.getParent(), FreeOptions.defaults().setForced(true).setRecursive(true));
    // Update the heartbeat of removedBlockId received from worker 1
    Command heartbeat = mBlockMaster.workerHeartbeat(mWorkerId1, ImmutableMap.of("MEM", (long) Constants.KB), ImmutableList.of(blockId), ImmutableMap.<String, List<Long>>of());
    // Verify the muted Free command on worker1
    Assert.assertEquals(new Command(CommandType.Nothing, ImmutableList.<Long>of()), heartbeat);
    Assert.assertEquals(0, mBlockMaster.getBlockInfo(blockId).getLocations().size());
}
Also used : FileSystemCommand(alluxio.thrift.FileSystemCommand) Command(alluxio.thrift.Command) Test(org.junit.Test)

Example 12 with Command

use of alluxio.thrift.Command in project alluxio by Alluxio.

the class BlockMaster method workerHeartbeat.

/**
   * Updates metadata when a worker periodically heartbeats with the master.
   *
   * @param workerId the worker id
   * @param usedBytesOnTiers a mapping from tier alias to the used bytes
   * @param removedBlockIds a list of block ids removed from this worker
   * @param addedBlocksOnTiers a mapping from tier alias to the added blocks
   * @return an optional command for the worker to execute
   */
public Command workerHeartbeat(long workerId, Map<String, Long> usedBytesOnTiers, List<Long> removedBlockIds, Map<String, List<Long>> addedBlocksOnTiers) {
    MasterWorkerInfo worker = mWorkers.getFirstByField(ID_INDEX, workerId);
    if (worker == null) {
        LOG.warn("Could not find worker id: {} for heartbeat.", workerId);
        return new Command(CommandType.Register, new ArrayList<Long>());
    }
    synchronized (worker) {
        // Technically, 'worker' should be confirmed to still be in the data structure. Lost worker
        // detection can remove it. However, we are intentionally ignoring this race, since the worker
        // will just re-register regardless.
        processWorkerRemovedBlocks(worker, removedBlockIds);
        processWorkerAddedBlocks(worker, addedBlocksOnTiers);
        worker.updateUsedBytes(usedBytesOnTiers);
        worker.updateLastUpdatedTimeMs();
        List<Long> toRemoveBlocks = worker.getToRemoveBlocks();
        if (toRemoveBlocks.isEmpty()) {
            return new Command(CommandType.Nothing, new ArrayList<Long>());
        }
        return new Command(CommandType.Free, toRemoveBlocks);
    }
}
Also used : Command(alluxio.thrift.Command) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo)

Example 13 with Command

use of alluxio.thrift.Command in project alluxio by Alluxio.

the class BlockMasterSync method heartbeat.

/**
   * Heartbeats to the master node about the change in the worker's managed space.
   */
@Override
public void heartbeat() {
    // Prepare metadata for the next heartbeat
    BlockHeartbeatReport blockReport = mBlockWorker.getReport();
    BlockStoreMeta storeMeta = mBlockWorker.getStoreMeta();
    // Send the heartbeat and execute the response
    Command cmdFromMaster = null;
    try {
        cmdFromMaster = mMasterClient.heartbeat(mWorkerId.get(), storeMeta.getUsedBytesOnTiers(), blockReport.getRemovedBlocks(), blockReport.getAddedBlocks());
        handleMasterCommand(cmdFromMaster);
        mLastSuccessfulHeartbeatMs = System.currentTimeMillis();
    } catch (Exception e) {
        // An error occurred, log and ignore it or error if heartbeat timeout is reached
        if (cmdFromMaster == null) {
            LOG.error("Failed to receive master heartbeat command.", e);
        } else {
            LOG.error("Failed to receive or execute master heartbeat command: {}", cmdFromMaster.toString(), e);
        }
        mMasterClient.resetConnection();
        if (System.currentTimeMillis() - mLastSuccessfulHeartbeatMs >= mHeartbeatTimeoutMs) {
            throw new RuntimeException("Master heartbeat timeout exceeded: " + mHeartbeatTimeoutMs);
        }
    }
}
Also used : Command(alluxio.thrift.Command) AlluxioException(alluxio.exception.AlluxioException) ConnectionFailedException(alluxio.exception.ConnectionFailedException) IOException(java.io.IOException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException)

Aggregations

Command (alluxio.thrift.Command)13 Test (org.junit.Test)11 FileSystemCommand (alluxio.thrift.FileSystemCommand)9 SetAttributeOptions (alluxio.master.file.options.SetAttributeOptions)4 CreateDirectoryOptions (alluxio.master.file.options.CreateDirectoryOptions)2 AlluxioURI (alluxio.AlluxioURI)1 AlluxioException (alluxio.exception.AlluxioException)1 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)1 ConnectionFailedException (alluxio.exception.ConnectionFailedException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)1 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)1 IOException (java.io.IOException)1