Search in sources :

Example 26 with UnavailableException

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

the class ZkMasterInquireClient method getPrimaryRpcAddress.

@Override
public synchronized InetSocketAddress getPrimaryRpcAddress() throws UnavailableException {
    ensureStarted();
    long startTime = System.currentTimeMillis();
    int tried = 0;
    try {
        CuratorZookeeperClient curatorClient = mClient.getZookeeperClient();
        // connection status explicitly.
        for (int i = 0; i < 50; i++) {
            if (curatorClient.isConnected()) {
                break;
            }
            CommonUtils.sleepMs(20);
        }
        curatorClient.blockUntilConnectedOrTimedOut();
        String leaderPath = mConnectDetails.getLeaderPath();
        while (tried++ < mInquireRetryCount) {
            ZooKeeper zookeeper = curatorClient.getZooKeeper();
            if (zookeeper.exists(leaderPath, false) != null) {
                List<String> masters = zookeeper.getChildren(leaderPath, null);
                LOG.debug("Master addresses: {}", masters);
                if (masters.size() >= 1) {
                    if (masters.size() == 1) {
                        return NetworkAddressUtils.parseInetSocketAddress(masters.get(0));
                    }
                    long maxTime = 0;
                    String leader = "";
                    for (String master : masters) {
                        Stat stat = zookeeper.exists(PathUtils.concatPath(leaderPath, master), null);
                        if (stat != null && stat.getCtime() > maxTime) {
                            maxTime = stat.getCtime();
                            leader = master;
                        }
                    }
                    LOG.debug("The leader master: {}", leader);
                    return NetworkAddressUtils.parseInetSocketAddress(leader);
                }
            } else {
                LOG.info("{} does not exist ({})", leaderPath, tried);
            }
            CommonUtils.sleepMs(LOG, Constants.SECOND_MS);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        LOG.error("Error getting the leader master address from zookeeper. Zookeeper: {}", mConnectDetails, e);
    } finally {
        LOG.debug("Finished getPrimaryRpcAddress() in {}ms", System.currentTimeMillis() - startTime);
    }
    throw new UnavailableException("Failed to determine primary master rpc address");
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) CuratorZookeeperClient(org.apache.curator.CuratorZookeeperClient) UnavailableException(alluxio.exception.status.UnavailableException) UnavailableException(alluxio.exception.status.UnavailableException)

Example 27 with UnavailableException

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

the class DefaultAsyncPersistHandler method pollFilesToPersist.

/**
 * Polls the files to send to the given worker for persistence. It also removes files from the
 * worker entry in {@link #mWorkerToAsyncPersistFiles}.
 *
 * @param workerId the worker id
 * @return the list of files
 * @throws FileDoesNotExistException if the file does not exist
 * @throws InvalidPathException if the path is invalid
 * @throws AccessControlException if permission checking fails
 */
@Override
public synchronized List<PersistFile> pollFilesToPersist(long workerId) throws FileDoesNotExistException, InvalidPathException, AccessControlException {
    List<PersistFile> filesToPersist = new ArrayList<>();
    List<Long> fileIdsToPersist = new ArrayList<>();
    if (!mWorkerToAsyncPersistFiles.containsKey(workerId)) {
        return filesToPersist;
    }
    Set<Long> scheduledFiles = mWorkerToAsyncPersistFiles.get(workerId);
    try {
        for (long fileId : scheduledFiles) {
            try {
                FileInfo fileInfo = mFileSystemMasterView.getFileInfo(fileId);
                if (fileInfo.isCompleted()) {
                    fileIdsToPersist.add(fileId);
                    List<Long> blockIds = new ArrayList<>();
                    for (FileBlockInfo fileBlockInfo : mFileSystemMasterView.getFileBlockInfoList(mFileSystemMasterView.getPath(fileId))) {
                        blockIds.add(fileBlockInfo.getBlockInfo().getBlockId());
                    }
                    filesToPersist.add(new PersistFile(fileId, blockIds));
                }
            } catch (FileDoesNotExistException e) {
                LOG.warn("FileId {} does not exist, ignore persistence it", fileId);
            }
        }
    } catch (UnavailableException e) {
        return filesToPersist;
    }
    mWorkerToAsyncPersistFiles.get(workerId).removeAll(fileIdsToPersist);
    return filesToPersist;
}
Also used : PersistFile(alluxio.wire.PersistFile) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) ArrayList(java.util.ArrayList) UnavailableException(alluxio.exception.status.UnavailableException) FileBlockInfo(alluxio.wire.FileBlockInfo)

Example 28 with UnavailableException

use of alluxio.exception.status.UnavailableException 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;
    }
}
Also used : UnavailableException(alluxio.exception.status.UnavailableException) NotFoundException(alluxio.exception.status.NotFoundException) AlluxioURI(alluxio.AlluxioURI)

Example 29 with UnavailableException

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

the class LeaderCommand method run.

@Override
public int run(CommandLine cl) {
    System.out.println("This command will be deprecated as of v3.0, please use masterInfo command");
    try (CloseableResource<FileSystemMasterClient> client = mFsContext.acquireMasterClientResource()) {
        try {
            InetSocketAddress address = client.get().getAddress();
            System.out.println(address.getHostName());
            List<InetSocketAddress> addresses = Arrays.asList(address);
            MasterInquireClient inquireClient = new PollingMasterInquireClient(addresses, () -> new ExponentialBackoffRetry(50, 100, 2), mFsContext.getClusterConf());
            try {
                inquireClient.getPrimaryRpcAddress();
            } catch (UnavailableException e) {
                System.err.println("The leader is not currently serving requests.");
            }
        } catch (UnavailableException e) {
            System.err.println("Failed to get the leader master.");
        }
    }
    return 0;
}
Also used : PollingMasterInquireClient(alluxio.master.PollingMasterInquireClient) MasterInquireClient(alluxio.master.MasterInquireClient) FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) PollingMasterInquireClient(alluxio.master.PollingMasterInquireClient) InetSocketAddress(java.net.InetSocketAddress) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) UnavailableException(alluxio.exception.status.UnavailableException)

Example 30 with UnavailableException

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

the class AlluxioFileInStreamTest method readOneRetry.

@Test
public void readOneRetry() throws Exception {
    long offset = 37;
    // Setups a broken stream for the first block to throw an exception.
    TestBlockInStream workingStream = mInStreams.get(0);
    TestBlockInStream brokenStream = mock(TestBlockInStream.class);
    when(mBlockStore.getInStream(any(BlockInfo.class), any(InStreamOptions.class), any())).thenReturn(brokenStream).thenReturn(workingStream);
    when(brokenStream.read()).thenThrow(new UnavailableException("test exception"));
    when(brokenStream.getPos()).thenReturn(offset);
    mTestStream.seek(offset);
    int b = mTestStream.read();
    doReturn(0).when(brokenStream).read();
    verify(brokenStream, times(1)).read();
    assertEquals(offset, b);
}
Also used : UnavailableException(alluxio.exception.status.UnavailableException) TestBlockInStream(alluxio.client.block.stream.TestBlockInStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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