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");
}
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;
}
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;
}
}
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;
}
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);
}
Aggregations