use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class LineageMaster method reinitializeFile.
/**
* Reinitializes the file when the file is lost or not completed.
*
* @param path the path to the file
* @param blockSizeBytes the block size
* @param ttl the TTL
* @param ttlAction action to perform on ttl expiry
* @return the id of the reinitialized file when the file is lost or not completed, -1 otherwise
* @throws InvalidPathException the file path is invalid
* @throws LineageDoesNotExistException when the file does not exist
* @throws AccessControlException if permission checking fails
* @throws FileDoesNotExistException if the path does not exist
*/
public synchronized long reinitializeFile(String path, long blockSizeBytes, long ttl, TtlAction ttlAction) throws InvalidPathException, LineageDoesNotExistException, AccessControlException, FileDoesNotExistException {
long fileId = mFileSystemMaster.getFileId(new AlluxioURI(path));
FileInfo fileInfo;
try {
fileInfo = mFileSystemMaster.getFileInfo(fileId);
if (!fileInfo.isCompleted() || mFileSystemMaster.getLostFiles().contains(fileId)) {
LOG.info("Recreate the file {} with block size of {} bytes", path, blockSizeBytes);
return mFileSystemMaster.reinitializeFile(new AlluxioURI(path), blockSizeBytes, ttl, ttlAction);
}
} catch (FileDoesNotExistException e) {
throw new LineageDoesNotExistException(ExceptionMessage.MISSING_REINITIALIZE_FILE.getMessage(path));
}
return -1;
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterTest method ttlFileDelete.
/**
* Tests that an exception is in the
* {@link FileSystemMaster#createFile(AlluxioURI, CreateFileOptions)} with a TTL set in the
* {@link CreateFileOptions} after the TTL check was done once.
*/
@Test
public void ttlFileDelete() throws Exception {
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true).setTtl(0);
long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, options);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
Assert.assertEquals(fileInfo.getFileId(), fileId);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(fileId);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class PermissionCheckTest method verifyRename.
private void verifyRename(TestUser user, String srcPath, String dstPath) throws Exception {
try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(user.getUser())) {
String fileOwner = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(srcPath))).getOwner();
mFileSystemMaster.rename(new AlluxioURI(srcPath), new AlluxioURI(dstPath), RenameOptions.defaults());
Assert.assertEquals(-1, mFileSystemMaster.getFileId(new AlluxioURI(srcPath)));
FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(dstPath)));
String[] pathComponents = dstPath.split("/");
Assert.assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName());
Assert.assertEquals(fileOwner, fileInfo.getOwner());
}
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class PermissionCheckTest method verifySetAcl.
private void verifySetAcl(TestUser runUser, String path, String owner, String group, short mode, boolean recursive) throws Exception {
try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(runUser.getUser())) {
SetAttributeOptions options = SetAttributeOptions.defaults().setOwner(owner).setGroup(group).setMode(mode).setRecursive(recursive);
mFileSystemMaster.setAttribute(new AlluxioURI(path), options);
}
try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_ADMIN.getUser())) {
FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(path)));
if (owner != null) {
Assert.assertEquals(owner, fileInfo.getOwner());
}
if (group != null) {
Assert.assertEquals(group, fileInfo.getGroup());
}
if (mode != -1) {
Assert.assertEquals(mode, fileInfo.getMode());
}
}
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class DefaultAsyncPersistHandlerTest method scheduleAsyncPersist.
@Test
public void scheduleAsyncPersist() throws Exception {
DefaultAsyncPersistHandler handler = new DefaultAsyncPersistHandler(new FileSystemMasterView(mFileSystemMaster));
AlluxioURI path = new AlluxioURI("/test");
long blockId = 0;
long workerId = 1;
long fileId = 2;
List<FileBlockInfo> blockInfoList = new ArrayList<>();
BlockLocation location = new BlockLocation().setWorkerId(workerId);
blockInfoList.add(new FileBlockInfo().setBlockInfo(new BlockInfo().setBlockId(blockId).setLocations(Lists.newArrayList(location))));
Mockito.when(mFileSystemMaster.getFileBlockInfoList(path)).thenReturn(blockInfoList);
Mockito.when(mFileSystemMaster.getFileId(path)).thenReturn(fileId);
Mockito.when(mFileSystemMaster.getPath(fileId)).thenReturn(path);
Mockito.when(mFileSystemMaster.getFileInfo(fileId)).thenReturn(new FileInfo().setLength(1).setCompleted(true));
handler.scheduleAsyncPersistence(path);
List<PersistFile> persistFiles = handler.pollFilesToPersist(workerId);
Assert.assertEquals(1, persistFiles.size());
Assert.assertEquals(Lists.newArrayList(blockId), persistFiles.get(0).getBlockIds());
}
Aggregations