use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class ThriftClientPool method createNewResource.
/**
* Creates a thrift client instance.
*
* @return the thrift client created
* @throws IOException if it fails to create a thrift client
*/
@Override
protected T createNewResource() throws IOException {
TTransport transport = mTransportProvider.getClientTransport(mParentSubject, mAddress);
TProtocol binaryProtocol = new TBinaryProtocol(transport);
T client = createThriftClient(new TMultiplexedProtocol(binaryProtocol, mServiceName));
TException exception;
RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
do {
LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, mServiceName, mAddress);
try {
if (!transport.isOpen()) {
transport.open();
}
if (transport.isOpen()) {
checkVersion(client);
}
LOG.info("Client registered with {} @ {}", mServiceName, mAddress);
return client;
} catch (TTransportException e) {
if (e.getCause() instanceof java.net.SocketTimeoutException) {
// Do not retry if socket timeout.
String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode.";
throw new IOException(message, e);
}
LOG.warn("Failed to connect ({}) to {} @ {}: {}", retryPolicy.getRetryCount(), mServiceName, mAddress, e.getMessage());
exception = e;
}
} while (retryPolicy.attemptRetry());
LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
Preconditions.checkNotNull(exception);
throw new IOException(exception);
}
use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class AbstractMaster method waitForJournalFlush.
/**
* Waits for the flush counter to be flushed to the journal. If the counter is
* {@link #INVALID_FLUSH_COUNTER}, this is a noop.
*
* @param journalContext the journal context
*/
private void waitForJournalFlush(JournalContext journalContext) {
if (journalContext.getFlushCounter() == INVALID_FLUSH_COUNTER) {
// Check this before the precondition.
return;
}
Preconditions.checkNotNull(mAsyncJournalWriter, PreconditionMessage.ASYNC_JOURNAL_WRITER_NULL);
RetryPolicy retry = new TimeoutRetry(JOURNAL_FLUSH_RETRY_TIMEOUT_MS, Constants.SECOND_MS);
int attempts = 0;
while (retry.attemptRetry()) {
try {
attempts++;
mAsyncJournalWriter.flush(journalContext.getFlushCounter());
return;
} catch (IOException e) {
LOG.warn("Journal flush failed. retrying...", e);
}
}
LOG.error("Journal flush failed after {} attempts. Terminating process to prevent inconsistency.", attempts);
if (Configuration.getBoolean(PropertyKey.TEST_MODE)) {
throw new RuntimeException("Journal flush failed after " + attempts + " attempts. Terminating process to prevent inconsistency.");
}
System.exit(-1);
}
use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class HdfsUnderFileSystem method rename.
/**
* Rename a file or folder to a file or folder.
*
* @param src path of source file or directory
* @param dst path of destination file or directory
* @return true if rename succeeds
* @throws IOException
*/
private boolean rename(String src, String dst) throws IOException {
IOException te = null;
RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
while (retryPolicy.attemptRetry()) {
try {
return mFileSystem.rename(new Path(src), new Path(dst));
} catch (IOException e) {
LOG.error("{} try to rename {} to {} : {}", retryPolicy.getRetryCount(), src, dst, e.getMessage(), e);
te = e;
}
}
throw te;
}
use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class HdfsUnderFileSystem method open.
@Override
public InputStream open(String path, OpenOptions options) throws IOException {
IOException te = null;
RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
while (retryPolicy.attemptRetry()) {
try {
FSDataInputStream inputStream = mFileSystem.open(new Path(path));
try {
inputStream.seek(options.getOffset());
} catch (IOException e) {
inputStream.close();
throw e;
}
return new HdfsUnderFileInputStream(inputStream);
} catch (IOException e) {
LOG.error("{} try to open {} : {}", retryPolicy.getRetryCount(), path, e.getMessage(), e);
te = e;
}
}
throw te;
}
use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class HdfsUnderFileSystem method createDirect.
@Override
public OutputStream createDirect(String path, CreateOptions options) throws IOException {
IOException te = null;
RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
while (retryPolicy.attemptRetry()) {
try {
LOG.debug("Creating HDFS file at {} with owner {}, group {}, mode {}", path, options.getOwner(), options.getGroup(), options.getMode());
// TODO(chaomin): support creating HDFS files with specified block size and replication.
return FileSystem.create(mFileSystem, new Path(path), new FsPermission(options.getMode().toShort()));
} catch (IOException e) {
LOG.error("Retry count {} : {} ", retryPolicy.getRetryCount(), e.getMessage(), e);
te = e;
}
}
throw te;
}
Aggregations