Search in sources :

Example 1 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class ClientMasterSync method loadConf.

/**
 * Loads configuration.
 *
 * @return true if successfully loaded configuration
 */
private boolean loadConf() {
    try {
        InetSocketAddress masterAddr = mInquireClient.getPrimaryRpcAddress();
        mContext.loadConf(masterAddr, true, false);
    } catch (UnavailableException e) {
        SAMPLING_LOG.error("Failed to get master address during initialization", e);
        return false;
    } catch (AlluxioStatusException ae) {
        SAMPLING_LOG.error("Failed to load configuration from meta master during initialization", ae);
        return false;
    }
    return true;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException)

Example 2 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class RetryHandlingMetricsMasterClient method heartbeat.

@Override
public void heartbeat(final List<ClientMetrics> metrics) throws IOException {
    connect();
    try {
        MetricsHeartbeatPRequest.Builder request = MetricsHeartbeatPRequest.newBuilder();
        request.setOptions(MetricsHeartbeatPOptions.newBuilder().addAllClientMetrics(metrics).build());
        mClient.metricsHeartbeat(request.build());
    } catch (io.grpc.StatusRuntimeException e) {
        disconnect();
        throw new UnavailableException(e);
    }
}
Also used : MetricsHeartbeatPRequest(alluxio.grpc.MetricsHeartbeatPRequest) UnavailableException(alluxio.exception.status.UnavailableException)

Example 3 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method getInStreamInAlluxioWhenCreateStreamIsFailed.

@Test
public void getInStreamInAlluxioWhenCreateStreamIsFailed() throws Exception {
    int workerCount = 5;
    boolean persisted = false;
    int[] blockLocations = new int[] { 2, 3, 4 };
    Map<Integer, Long> failedWorkers = ImmutableMap.of(0, 3L, 1, 1L, 3, 2L);
    int expectedWorker = 2;
    WorkerNetAddress[] workers = new WorkerNetAddress[workerCount];
    for (int i = 0; i < workers.length - 1; i++) {
        workers[i] = new WorkerNetAddress().setHost(String.format("worker-%d", i));
    }
    workers[workers.length - 1] = new WorkerNetAddress().setHost(WORKER_HOSTNAME_LOCAL);
    when(mContext.acquireBlockWorkerClient(WORKER_NET_ADDRESS_LOCAL)).thenThrow(new UnavailableException("failed to connect to " + WORKER_NET_ADDRESS_LOCAL.getHost()));
    BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLocations(Arrays.stream(blockLocations).mapToObj(x -> new BlockLocation().setWorkerAddress(workers[x])).collect(Collectors.toList()));
    URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(persisted).setBlockIds(Collections.singletonList(BLOCK_ID)).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
    BlockLocationPolicy mockPolicy = mock(BlockLocationPolicy.class);
    when(mockPolicy.getWorker(any())).thenAnswer(arg -> arg.getArgument(0, GetWorkerOptions.class).getBlockWorkerInfos().iterator().next().getNetAddress());
    InStreamOptions options = new InStreamOptions(dummyStatus, FileSystemOptions.openFileDefaults(sConf), sConf);
    options.setUfsReadLocationPolicy(mockPolicy);
    when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(info);
    when(mContext.getCachedWorkers()).thenReturn(Arrays.stream(workers).map(x -> new BlockWorkerInfo(x, -1, -1)).collect((Collectors.toList())));
    Map<WorkerNetAddress, Long> failedWorkerAddresses = failedWorkers.entrySet().stream().map(x -> new AbstractMap.SimpleImmutableEntry<>(workers[x.getKey()], x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    BlockInStream inStream = null;
    int i = 2;
    while (i-- > 0) {
        try {
            inStream = mBlockStore.getInStream(BLOCK_ID, options, failedWorkerAddresses);
        } catch (Exception e) {
        // do nothing
        }
    }
    assertEquals(workers[expectedWorker], inStream.getAddress());
}
Also used : Arrays(java.util.Arrays) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) BlockInfo(alluxio.wire.BlockInfo) GrpcDataReader(alluxio.client.block.stream.GrpcDataReader) NoopClosableResource(alluxio.client.block.stream.NoopClosableResource) FileBlockInfo(alluxio.wire.FileBlockInfo) PropertyKey(alluxio.conf.PropertyKey) StreamObserver(io.grpc.stub.StreamObserver) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) PreconditionMessage(alluxio.exception.PreconditionMessage) ClientContext(alluxio.ClientContext) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) List(java.util.List) DummyCloseableResource(alluxio.resource.DummyCloseableResource) ConfigurationTestUtils(alluxio.ConfigurationTestUtils) Mockito.any(org.mockito.Mockito.any) WriteType(alluxio.client.WriteType) InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mockito.mock(org.mockito.Mockito.mock) UnavailableException(alluxio.exception.status.UnavailableException) BlockWorker(alluxio.worker.block.BlockWorker) Assert.assertThrows(org.junit.Assert.assertThrows) WorkerNetAddress(alluxio.wire.WorkerNetAddress) RunWith(org.junit.runner.RunWith) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) BlockOutStream(alluxio.client.block.stream.BlockOutStream) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Lists(com.google.common.collect.Lists) ConfigurationRule(alluxio.ConfigurationRule) OpenLocalBlockResponse(alluxio.grpc.OpenLocalBlockResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) CreateLocalBlockResponse(alluxio.grpc.CreateLocalBlockResponse) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) TieredIdentityFactory(alluxio.network.TieredIdentityFactory) PowerMockito(org.powermock.api.mockito.PowerMockito) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) BlockInStream(alluxio.client.block.stream.BlockInStream) InStreamOptions(alluxio.client.file.options.InStreamOptions) ExceptionMessage(alluxio.exception.ExceptionMessage) Assert.assertTrue(org.junit.Assert.assertTrue) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) File(java.io.File) OpenLocalBlockRequest(alluxio.grpc.OpenLocalBlockRequest) BlockLocation(alluxio.wire.BlockLocation) Mockito(org.mockito.Mockito) URIStatus(alluxio.client.file.URIStatus) AbstractMap(java.util.AbstractMap) FileSystemContext(alluxio.client.file.FileSystemContext) FileInfo(alluxio.wire.FileInfo) Closeable(java.io.Closeable) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemOptions(alluxio.util.FileSystemOptions) UnavailableException(alluxio.exception.status.UnavailableException) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockInStream(alluxio.client.block.stream.BlockInStream) FileInfo(alluxio.wire.FileInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractMap(java.util.AbstractMap) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class AbstractClient method retryRPCInternal.

private synchronized <V> V retryRPCInternal(RetryPolicy retryPolicy, RpcCallable<V> rpc, Supplier<Void> onRetry) throws AlluxioStatusException {
    Exception ex = null;
    while (retryPolicy.attempt()) {
        if (mClosed) {
            throw new FailedPreconditionException("Client is closed");
        }
        connect();
        try {
            return rpc.call();
        } catch (StatusRuntimeException e) {
            AlluxioStatusException se = AlluxioStatusException.fromStatusRuntimeException(e);
            if (se.getStatusCode() == Status.Code.UNAVAILABLE || se.getStatusCode() == Status.Code.CANCELLED || se.getStatusCode() == Status.Code.UNAUTHENTICATED || e.getCause() instanceof UnresolvedAddressException) {
                ex = se;
            } else {
                throw se;
            }
        }
        LOG.debug("Rpc failed ({}): ", retryPolicy.getAttemptCount(), ex);
        onRetry.get();
        disconnect();
    }
    throw new UnavailableException("Failed after " + retryPolicy.getAttemptCount() + " attempts: " + ex.toString(), ex);
}
Also used : FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) StatusRuntimeException(io.grpc.StatusRuntimeException) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) StatusRuntimeException(io.grpc.StatusRuntimeException) ServiceNotFoundException(alluxio.exception.ServiceNotFoundException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) UnavailableException(alluxio.exception.status.UnavailableException)

Example 5 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class ConfigHashSync method heartbeat.

@Override
public synchronized void heartbeat() {
    if (!mContext.getClientContext().getClusterConf().clusterDefaultsLoaded()) {
        // Wait until the initial cluster defaults are loaded.
        return;
    }
    ConfigHash hash;
    try {
        hash = mClient.getConfigHash();
    } catch (IOException e) {
        LOG.error("Failed to heartbeat to meta master to get configuration hash:", e);
        // Disconnect to reconnect in the next heartbeat.
        mClient.disconnect();
        return;
    }
    boolean isClusterConfUpdated = !hash.getClusterConfigHash().equals(mContext.getClientContext().getClusterConfHash());
    boolean isPathConfUpdated = !hash.getPathConfigHash().equals(mContext.getClientContext().getPathConfHash());
    if (isClusterConfUpdated || isPathConfUpdated) {
        try {
            mContext.reinit(isClusterConfUpdated, isPathConfUpdated);
            mException = null;
        } catch (UnavailableException e) {
            LOG.error("Failed to reinitialize FileSystemContext:", e);
        // Meta master might be temporarily unavailable, retry in next heartbeat.
        } catch (IOException e) {
            LOG.error("Failed to close FileSystemContext, interrupting the heartbeat thread", e);
            mException = e;
            // If the heartbeat keeps running, the context might be reinitialized successfully in the
            // next heartbeat, then the resources that are not closed in the old context are leaked.
            Thread.currentThread().interrupt();
        }
    }
}
Also used : UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException) ConfigHash(alluxio.wire.ConfigHash)

Aggregations

UnavailableException (alluxio.exception.status.UnavailableException)58 IOException (java.io.IOException)25 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)10 AlluxioURI (alluxio.AlluxioURI)9 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)9 NotFoundException (alluxio.exception.status.NotFoundException)9 InetSocketAddress (java.net.InetSocketAddress)9 BlockInfo (alluxio.wire.BlockInfo)8 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 WorkerNetAddress (alluxio.wire.WorkerNetAddress)7 WorkerInfo (alluxio.wire.WorkerInfo)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Set (java.util.Set)6 RetryPolicy (alluxio.retry.RetryPolicy)5 TimeoutException (java.util.concurrent.TimeoutException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 ExceptionMessage (alluxio.exception.ExceptionMessage)4 InodeFile (alluxio.master.file.meta.InodeFile)4