use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FreeAndDeleteIntegrationTest method freeAndDeleteIntegration.
@Test
public void freeAndDeleteIntegration() throws Exception {
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
FileOutStream os = mFileSystem.createFile(filePath, mWriteBoth);
os.write((byte) 0);
os.write((byte) 1);
os.close();
URIStatus status = mFileSystem.getStatus(filePath);
assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
final Long blockId = status.getBlockIds().get(0);
BlockMaster bm = mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(BlockMaster.class);
BlockInfo blockInfo = bm.getBlockInfo(blockId);
assertEquals(2, blockInfo.getLength());
assertFalse(blockInfo.getLocations().isEmpty());
final BlockWorker bw = mLocalAlluxioClusterResource.get().getWorkerProcess().getWorker(BlockWorker.class);
assertTrue(bw.hasBlockMeta(blockId));
assertEquals(0, bm.getLostBlocksCount());
mFileSystem.free(filePath);
CommonUtils.waitFor("file is freed", () -> {
try {
return 0 == mFileSystem.getStatus(filePath).getInAlluxioPercentage();
} catch (Exception e) {
return false;
}
}, WAIT_OPTIONS);
status = mFileSystem.getStatus(filePath);
// Verify block metadata in master is still present after block freed.
assertEquals(1, status.getBlockIds().size());
blockInfo = bm.getBlockInfo(status.getBlockIds().get(0));
assertEquals(2, blockInfo.getLength());
// Verify the block has been removed from all workers.
assertTrue(blockInfo.getLocations().isEmpty());
assertFalse(bw.hasBlockMeta(blockId));
// Verify the removed block is added to LostBlocks list.
assertTrue(bm.isBlockLost(blockInfo.getBlockId()));
mFileSystem.delete(filePath);
try {
// File is immediately gone after delete.
mFileSystem.getStatus(filePath);
Assert.fail(String.format("Expected file %s being deleted but it was not.", filePath));
} catch (FileDoesNotExistException e) {
// expected
}
// Verify the blocks are not in mLostBlocks.
CommonUtils.waitFor("block is removed from mLostBlocks", () -> {
try {
return 0 == bm.getLostBlocksCount();
} catch (Exception e) {
return false;
}
}, WAIT_OPTIONS);
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class S3ClientRestApiTest method deleteBucket.
@Test
public void deleteBucket() throws Exception {
final String bucket = "bucket-to-delete";
createBucketRestCall(bucket);
// Verify the directory is created for the new bucket.
AlluxioURI uri = new AlluxioURI(AlluxioURI.SEPARATOR + bucket);
Assert.assertTrue(mFileSystemMaster.listStatus(uri, ListStatusContext.defaults()).isEmpty());
HttpURLConnection connection = deleteBucketRestCall(bucket);
Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), connection.getResponseCode());
try {
mFileSystemMaster.getFileInfo(uri, GET_STATUS_CONTEXT);
} catch (FileDoesNotExistException e) {
// expected
return;
}
Assert.fail("bucket should have been removed");
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class WebInterfaceMemoryServlet method doGet.
/**
* Populates attributes before redirecting to a jsp.
*
* @param request the {@link HttpServletRequest} object
* @param response the {@link HttpServletResponse} object
* @throws ServletException if the target resource throws this exception
* @throws IOException if the target resource throws this exception
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (SecurityUtils.isSecurityEnabled() && AuthenticatedClientUser.get() == null) {
AuthenticatedClientUser.set(LoginUser.get().getName());
}
request.setAttribute("masterNodeAddress", mMaster.getRpcAddress().toString());
request.setAttribute("fatalError", "");
request.setAttribute("showPermissions", Configuration.getBoolean(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED));
List<AlluxioURI> inMemoryFiles = mMaster.getFileSystemMaster().getInMemoryFiles();
Collections.sort(inMemoryFiles);
List<UIFileInfo> fileInfos = new ArrayList<>(inMemoryFiles.size());
for (AlluxioURI file : inMemoryFiles) {
try {
long fileId = mMaster.getFileSystemMaster().getFileId(file);
FileInfo fileInfo = mMaster.getFileSystemMaster().getFileInfo(fileId);
if (fileInfo != null && fileInfo.getInMemoryPercentage() == 100) {
fileInfos.add(new UIFileInfo(fileInfo));
}
} catch (FileDoesNotExistException e) {
request.setAttribute("fatalError", "Error: File does not exist " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
} catch (AccessControlException e) {
request.setAttribute("permissionError", "Error: File " + file + " cannot be accessed " + e.getMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
}
}
request.setAttribute("inMemoryFileNum", fileInfos.size());
// and redirect to "./memory?offset=xxx&limit=xxx"
if (request.getParameter("offset") == null && request.getParameter("limit") == null) {
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
}
try {
int offset = Integer.parseInt(request.getParameter("offset"));
int limit = Integer.parseInt(request.getParameter("limit"));
List<UIFileInfo> sub = fileInfos.subList(offset, offset + limit);
request.setAttribute("fileInfos", sub);
} catch (NumberFormatException e) {
request.setAttribute("fatalError", "Error: offset or limit parse error, " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
} catch (IndexOutOfBoundsException e) {
request.setAttribute("fatalError", "Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
} catch (IllegalArgumentException e) {
request.setAttribute("fatalError", e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
}
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
}
use of alluxio.exception.FileDoesNotExistException 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.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class CheckpointLatestPlanner method generatePlan.
@Override
public CheckpointPlan generatePlan(LineageStoreView store, FileSystemMasterView fileSystemMasterView) {
Lineage toCheckpoint = null;
long latestCreated = 0;
for (Lineage lineage : store.getAllLineagesInTopologicalOrder()) {
try {
if (!LineageStateUtils.isCompleted(lineage, fileSystemMasterView) || LineageStateUtils.isPersisted(lineage, fileSystemMasterView) || LineageStateUtils.needRecompute(lineage, fileSystemMasterView) || LineageStateUtils.isInCheckpointing(lineage, fileSystemMasterView)) {
continue;
}
} catch (FileDoesNotExistException | AccessControlException e) {
LOG.error("The lineage file does not exist", e);
continue;
}
if (lineage.getCreationTime() > latestCreated) {
latestCreated = lineage.getCreationTime();
toCheckpoint = lineage;
}
}
return toCheckpoint == null ? new CheckpointPlan(new ArrayList<Long>()) : new CheckpointPlan(Lists.newArrayList(toCheckpoint.getId()));
}
Aggregations