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()));
}
}
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);
}
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);
}
Aggregations