use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class UfsFallbackBlockWriteHandler method transferToUfsBlock.
/**
* Transfers data from block store to UFS.
*
* @param context context of this request
* @param pos number of bytes in block store to write in the UFS block
*/
private void transferToUfsBlock(BlockWriteRequestContext context, long pos) throws Exception {
OutputStream ufsOutputStream = context.getOutputStream();
long sessionId = context.getRequest().getSessionId();
long blockId = context.getRequest().getId();
TempBlockMeta block = mWorker.getTempBlockMeta(sessionId, blockId);
if (block == null) {
throw new NotFoundException("block " + blockId + " not found");
}
Preconditions.checkState(Files.copy(Paths.get(block.getPath()), ufsOutputStream) == pos);
}
use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class JobUfsManager method get.
@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);
try (CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
ufs.connectFromWorker(NetworkAddressUtils.getConnectHost(NetworkAddressUtils.ServiceType.WORKER_RPC, ServerConfiguration.global()));
} catch (IOException e) {
removeMount(mountId);
throw new UnavailableException(String.format("Failed to connect to UFS %s with id %d", info.getUri(), mountId), e);
}
return ufsClient;
}
use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class JobUtils method loadBlock.
/**
* Loads a block into the local worker. If the block doesn't exist in Alluxio, it will be read
* from the UFS.
* @param status the uriStatus
* @param context filesystem context
* @param blockId the id of the block to load
* @param address specify a worker to load into
* @param directCache Use passive-cache or direct cache request
*/
public static void loadBlock(URIStatus status, FileSystemContext context, long blockId, WorkerNetAddress address, boolean directCache) throws AlluxioException, IOException {
AlluxioConfiguration conf = ServerConfiguration.global();
// Explicitly specified a worker to load
WorkerNetAddress localNetAddress = address;
String localHostName = NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC, conf);
List<WorkerNetAddress> netAddress = context.getCachedWorkers().stream().map(BlockWorkerInfo::getNetAddress).filter(x -> Objects.equals(x.getHost(), localHostName)).collect(Collectors.toList());
if (localNetAddress == null && !netAddress.isEmpty()) {
localNetAddress = netAddress.get(0);
}
if (localNetAddress == null) {
throw new NotFoundException(ExceptionMessage.NO_LOCAL_BLOCK_WORKER_LOAD_TASK.getMessage(blockId));
}
Set<String> pinnedLocation = status.getPinnedMediumTypes();
if (pinnedLocation.size() > 1) {
throw new AlluxioException(ExceptionMessage.PINNED_TO_MULTIPLE_MEDIUMTYPES.getMessage(status.getPath()));
}
// Only use this read local first method to load if nearest worker is clear
if (netAddress.size() <= 1 && pinnedLocation.isEmpty() && status.isPersisted()) {
if (directCache) {
loadThroughCacheRequest(status, context, blockId, conf, localNetAddress);
} else {
loadThroughRead(status, context, blockId, conf);
}
return;
}
// TODO(bin): remove the following case when we consolidate tier and medium
// since there is only one element in the set, we take the first element in the set
String medium = pinnedLocation.isEmpty() ? "" : pinnedLocation.iterator().next();
OpenFilePOptions openOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build();
InStreamOptions inOptions = new InStreamOptions(status, openOptions, conf);
// Set read location policy always to local first for loading blocks for job tasks
inOptions.setUfsReadLocationPolicy(BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf));
OutStreamOptions outOptions = OutStreamOptions.defaults(context.getClientContext());
outOptions.setMediumType(medium);
// Set write location policy always to local first for loading blocks for job tasks
outOptions.setLocationPolicy(BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf));
BlockInfo blockInfo = status.getBlockInfo(blockId);
Preconditions.checkNotNull(blockInfo, "Can not find block %s in status %s", blockId, status);
long blockSize = blockInfo.getLength();
AlluxioBlockStore blockStore = AlluxioBlockStore.create(context);
try (OutputStream outputStream = blockStore.getOutStream(blockId, blockSize, localNetAddress, outOptions)) {
try (InputStream inputStream = blockStore.getInStream(blockId, inOptions)) {
ByteStreams.copy(inputStream, outputStream);
} catch (Throwable t) {
try {
((Cancelable) outputStream).cancel();
} catch (Throwable t2) {
t.addSuppressed(t2);
}
throw t;
}
}
}
use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class EvictDefinition method runTask.
/**
* {@inheritDoc}
*
* This task will evict the given block.
*/
@Override
public SerializableVoid runTask(EvictConfig 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 evict block %d", blockId);
throw new NotFoundException(message);
}
RemoveBlockRequest request = RemoveBlockRequest.newBuilder().setBlockId(blockId).build();
try (CloseableResource<BlockWorkerClient> blockWorker = context.getFsContext().acquireBlockWorkerClient(localNetAddress)) {
blockWorker.get().removeBlock(request);
} catch (NotFoundException e) {
// Instead of throwing this exception, we continue here because the block to evict does not
// exist on this worker anyway.
LOG.warn("Failed to delete block {} on {}: block does not exist", blockId, localNetAddress);
}
return null;
}
use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.
the class AbstractClient method connect.
/**
* Connects with the remote.
*/
@Override
public synchronized void connect() throws AlluxioStatusException {
if (mConnected) {
return;
}
disconnect();
Preconditions.checkState(!mClosed, "Client is closed, will not try to connect.");
IOException lastConnectFailure = null;
RetryPolicy retryPolicy = mRetryPolicySupplier.get();
while (retryPolicy.attempt()) {
if (mClosed) {
throw new FailedPreconditionException("Failed to connect: client has been closed");
}
// failover).
try {
mAddress = getAddress();
} catch (UnavailableException e) {
LOG.debug("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString());
continue;
}
try {
beforeConnect();
LOG.debug("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress);
mChannel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(mAddress), mContext.getClusterConf()).setSubject(mContext.getSubject()).setClientType(getServiceName()).build();
// Create stub for version service on host
mVersionService = ServiceVersionClientServiceGrpc.newBlockingStub(mChannel);
mConnected = true;
afterConnect();
checkVersion(getServiceVersion());
LOG.debug("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress);
return;
} catch (IOException e) {
LOG.debug("Failed to connect ({}) with {} @ {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e);
lastConnectFailure = e;
if (e instanceof UnauthenticatedException) {
// If there has been a failure in opening GrpcChannel, it's possible because
// the authentication credential has expired. Relogin.
mContext.getUserState().relogin();
}
if (e instanceof NotFoundException) {
// service is not found in the server, skip retry
break;
}
}
}
if (mChannel != null) {
mChannel.shutdown();
}
if (mAddress == null) {
throw new UnavailableException(String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount()));
}
/*
* Throw as-is if {@link UnauthenticatedException} occurred.
*/
if (lastConnectFailure instanceof UnauthenticatedException) {
throw (AlluxioStatusException) lastConnectFailure;
}
if (lastConnectFailure instanceof NotFoundException) {
throw new NotFoundException(lastConnectFailure.getMessage(), new ServiceNotFoundException(lastConnectFailure.getMessage(), lastConnectFailure));
}
throw new UnavailableException(String.format("Failed to connect to master (%s) after %s attempts." + "Please check if Alluxio master is currently running on \"%s\". Service=\"%s\"", mAddress, retryPolicy.getAttemptCount(), mAddress, getServiceName()), lastConnectFailure);
}
Aggregations