use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class AbstractUfsManager method getRoot.
@Override
public UfsClient getRoot() {
synchronized (this) {
if (mRootUfsClient == null) {
String rootUri = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
boolean rootReadOnly = ServerConfiguration.getBoolean(PropertyKey.MASTER_MOUNT_TABLE_ROOT_READONLY);
boolean rootShared = ServerConfiguration.getBoolean(PropertyKey.MASTER_MOUNT_TABLE_ROOT_SHARED);
Map<String, Object> rootConf = ServerConfiguration.getNestedProperties(PropertyKey.MASTER_MOUNT_TABLE_ROOT_OPTION);
addMount(IdUtils.ROOT_MOUNT_ID, new AlluxioURI(rootUri), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()).setReadOnly(rootReadOnly).setShared(rootShared).createMountSpecificConf(rootConf));
try {
mRootUfsClient = get(IdUtils.ROOT_MOUNT_ID);
} catch (NotFoundException | UnavailableException e) {
throw new RuntimeException("We should never reach here", e);
}
}
return mRootUfsClient;
}
}
use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class MoveDefinition method runTask.
/**
* {@inheritDoc}
*
* This task will move the given block.
*/
@Override
public SerializableVoid runTask(MoveConfig config, SerializableVoid args, RunTaskContext context) throws Exception {
long blockId = config.getBlockId();
String localHostName = NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC, ServerConfiguration.global());
List<BlockWorkerInfo> workerInfoList = context.getFsContext().getCachedWorkers();
WorkerNetAddress localNetAddress = null;
for (BlockWorkerInfo workerInfo : workerInfoList) {
if (workerInfo.getNetAddress().getHost().equals(localHostName)) {
localNetAddress = workerInfo.getNetAddress();
break;
}
}
if (localNetAddress == null) {
String message = String.format("Cannot find a local block worker to move block %d", blockId);
throw new NotFoundException(message);
}
MoveBlockRequest request = MoveBlockRequest.newBuilder().setBlockId(blockId).setMediumType(config.getMediumType()).build();
try (CloseableResource<BlockWorkerClient> blockWorker = context.getFsContext().acquireBlockWorkerClient(localNetAddress)) {
blockWorker.get().moveBlock(request);
}
return null;
}
use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class RemoteReadIntegrationTest method remoteReadLock.
/**
* Tests remote reads lock blocks correctly.
*/
@Test
public void remoteReadLock() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteAlluxio, k);
URIStatus status = mFileSystem.getStatus(uri);
InStreamOptions options = new InStreamOptions(status, ServerConfiguration.global());
long blockId = status.getBlockIds().get(0);
BlockInfo info = AlluxioBlockStore.create(FileSystemContext.create(ServerConfiguration.global())).getInfo(blockId);
WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress();
BlockInStream is = BlockInStream.create(mFsContext, options.getBlockInfo(blockId), workerAddr, BlockInStreamSource.REMOTE, options);
Assert.assertEquals(0, is.read());
mFileSystem.delete(uri);
// The file has been deleted.
Assert.assertFalse(mFileSystem.exists(uri));
// Look! We can still read the deleted file since we have a lock!
byte[] ret = new byte[k / 2];
Assert.assertTrue(is.read(ret, 0, k / 2) > 0);
is.close();
Assert.assertFalse(mFileSystem.exists(uri));
// Try to create an in stream again, and it should fail.
BlockInStream is2 = null;
try {
is2 = BlockInStream.create(mFsContext, options.getBlockInfo(blockId), workerAddr, BlockInStreamSource.REMOTE, options);
} catch (NotFoundException e) {
// Expected since the file has been deleted.
} finally {
if (is2 != null) {
is2.close();
}
}
}
}
use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class DefaultBlockMaster method commitBlock.
// TODO(binfan): check the logic is correct or not when commitBlock is a retry
@Override
public void commitBlock(long workerId, long usedBytesOnTier, String tierAlias, String mediumType, long blockId, long length) throws NotFoundException, UnavailableException {
LOG.debug("Commit block from workerId: {}, usedBytesOnTier: {}, blockId: {}, length: {}", workerId, usedBytesOnTier, blockId, length);
MasterWorkerInfo worker = mWorkers.getFirstByField(ID_INDEX, workerId);
// TODO(peis): Check lost workers as well.
if (worker == null) {
throw new NotFoundException(ExceptionMessage.NO_WORKER_FOUND.getMessage(workerId));
}
try (JournalContext journalContext = createJournalContext()) {
// The worker metadata must be locked before the blocks
try (LockResource lr = worker.lockWorkerMeta(EnumSet.of(WorkerMetaLockSection.USAGE, WorkerMetaLockSection.BLOCKS), false)) {
try (LockResource r = lockBlock(blockId)) {
Optional<BlockMeta> block = mBlockStore.getBlock(blockId);
if (!block.isPresent() || block.get().getLength() != length) {
if (block.isPresent() && block.get().getLength() != Constants.UNKNOWN_SIZE) {
LOG.warn("Rejecting attempt to change block length from {} to {}", block.get().getLength(), length);
} else {
mBlockStore.putBlock(blockId, BlockMeta.newBuilder().setLength(length).build());
BlockInfoEntry blockInfo = BlockInfoEntry.newBuilder().setBlockId(blockId).setLength(length).build();
journalContext.append(JournalEntry.newBuilder().setBlockInfo(blockInfo).build());
}
}
// Update the block metadata with the new worker location.
mBlockStore.addLocation(blockId, BlockLocation.newBuilder().setWorkerId(workerId).setTier(tierAlias).setMediumType(mediumType).build());
// This worker has this block, so it is no longer lost.
mLostBlocks.remove(blockId);
// Update the worker information for this new block.
// TODO(binfan): when retry commitBlock on master is expected, make sure metrics are not
// double counted.
worker.addBlock(blockId);
worker.updateUsedBytes(tierAlias, usedBytesOnTier);
}
}
worker.updateLastUpdatedTimeMs();
}
}
use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class WorkerUfsManager method get.
/**
* {@inheritDoc}.
*
* If this mount id is new to this worker, this method will query master to get the
* corresponding ufs info.
*/
@Override
public UfsClient get(long mountId) throws NotFoundException, UnavailableException {
try {
return super.get(mountId);
} catch (NotFoundException e) {
// Not cached locally, let's query master
}
UfsInfo info;
try {
info = mMasterClient.getUfsInfo(mountId);
} catch (IOException e) {
throw new UnavailableException(String.format("Failed to create UFS info for mount point with id %d", mountId), e);
}
Preconditions.checkState((info.hasUri() && info.hasProperties()), "unknown mountId");
super.addMount(mountId, new AlluxioURI(info.getUri()), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()).setReadOnly(info.getProperties().getReadOnly()).setShared(info.getProperties().getShared()).createMountSpecificConf(info.getProperties().getPropertiesMap()));
UfsClient ufsClient = super.get(mountId);
return ufsClient;
}
Aggregations