Search in sources :

Example 1 with FileSystemCommand

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

the class FileWorkerMasterSyncExecutor method heartbeat.

@Override
public void heartbeat() {
    List<Long> persistedFiles = mFileDataManager.getPersistedFiles();
    if (!persistedFiles.isEmpty()) {
        LOG.info("files {} persisted", persistedFiles);
    }
    FileSystemCommand command;
    try {
        command = mMasterClient.heartbeat(mWorkerId.get(), persistedFiles);
    } catch (IOException | AlluxioException e) {
        LOG.error("Failed to heartbeat to master", e);
        return;
    }
    // removes the persisted files that are confirmed
    mFileDataManager.clearPersistedFiles(persistedFiles);
    if (command == null) {
        LOG.error("The command sent from master is null");
        return;
    } else if (command.getCommandType() != CommandType.Persist) {
        LOG.error("The command sent from master should be PERSIST type, but was {}", command.getCommandType());
        return;
    }
    for (PersistFile persistFile : command.getCommandOptions().getPersistOptions().getPersistFiles()) {
        // Enqueue the persist request.
        mPersistFileService.execute(new FilePersister(mFileDataManager, persistFile.getFileId(), persistFile.getBlockIds()));
    }
}
Also used : PersistFile(alluxio.thrift.PersistFile) IOException(java.io.IOException) FileSystemCommand(alluxio.thrift.FileSystemCommand) AlluxioException(alluxio.exception.AlluxioException)

Example 2 with FileSystemCommand

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

the class FileSystemMaster method workerHeartbeat.

/**
   * Instructs a worker to persist the files.
   * <p>
   * Needs {@link Mode.Bits#WRITE} permission on the list of files.
   *
   * @param workerId the id of the worker that heartbeats
   * @param persistedFiles the files that persisted on the worker
   * @return the command for persisting the blocks of a file
   * @throws FileDoesNotExistException if the file does not exist
   * @throws InvalidPathException if the file path corresponding to the file id is invalid
   * @throws AccessControlException if permission checking fails
   */
public FileSystemCommand workerHeartbeat(long workerId, List<Long> persistedFiles) throws FileDoesNotExistException, InvalidPathException, AccessControlException {
    for (long fileId : persistedFiles) {
        try {
            // Permission checking for each file is performed inside setAttribute
            setAttribute(getPath(fileId), SetAttributeOptions.defaults().setPersisted(true));
        } catch (FileDoesNotExistException | AccessControlException | InvalidPathException e) {
            LOG.error("Failed to set file {} as persisted, because {}", fileId, e);
        }
    }
    // get the files for the given worker to persist
    List<PersistFile> filesToPersist = mAsyncPersistHandler.pollFilesToPersist(workerId);
    if (!filesToPersist.isEmpty()) {
        LOG.debug("Sent files {} to worker {} to persist", filesToPersist, workerId);
    }
    FileSystemCommandOptions options = new FileSystemCommandOptions();
    options.setPersistOptions(new PersistCommandOptions(filesToPersist));
    return new FileSystemCommand(CommandType.Persist, options);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) PersistFile(alluxio.thrift.PersistFile) AccessControlException(alluxio.exception.AccessControlException) PersistCommandOptions(alluxio.thrift.PersistCommandOptions) FileSystemCommandOptions(alluxio.thrift.FileSystemCommandOptions) FileSystemCommand(alluxio.thrift.FileSystemCommand) InvalidPathException(alluxio.exception.InvalidPathException)

Example 3 with FileSystemCommand

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

the class FileWorkerMasterSyncExecutorTest method heartbeat.

/**
   * Verifies {@link FileDataManager#clearPersistedFiles(java.util.List)} is called when the
   * heartbeat is successful.
   */
@Test
public void heartbeat() throws Exception {
    List<Long> persistedFiles = Lists.newArrayList(1L);
    Mockito.when(mFileDataManager.getPersistedFiles()).thenReturn(persistedFiles);
    // first time fails, second time passes
    Mockito.when(mFileSystemMasterClient.heartbeat(Mockito.anyLong(), Mockito.eq(persistedFiles))).thenReturn(new FileSystemCommand());
    mFileWorkerMasterSyncExecutor.heartbeat();
    Mockito.verify(mFileDataManager).clearPersistedFiles(persistedFiles);
}
Also used : FileSystemCommand(alluxio.thrift.FileSystemCommand) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FileSystemCommand (alluxio.thrift.FileSystemCommand)3 PersistFile (alluxio.thrift.PersistFile)2 AccessControlException (alluxio.exception.AccessControlException)1 AlluxioException (alluxio.exception.AlluxioException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 FileSystemCommandOptions (alluxio.thrift.FileSystemCommandOptions)1 PersistCommandOptions (alluxio.thrift.PersistCommandOptions)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1