/** * Returns a ConnectionId object. * @param addr Remote address for the connection. * @param protocol Protocol for RPC. * @param ticket UGI * @param rpcTimeout timeout * @param conf Configuration object * @return A ConnectionId instance * @throws IOException */ static ConnectionId getConnectionId(InetSocketAddress addr, Class<?> protocol, UserGroupInformation ticket, int rpcTimeout, RetryPolicy connectionRetryPolicy, Configuration conf) throws IOException { if (connectionRetryPolicy == null) { final int max = conf.getInt( CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_DEFAULT); final int retryInterval = conf.getInt( CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_RETRY_INTERVAL_KEY, CommonConfigurationKeysPublic .IPC_CLIENT_CONNECT_RETRY_INTERVAL_DEFAULT); connectionRetryPolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( max, retryInterval, TimeUnit.MILLISECONDS); } return new ConnectionId(addr, protocol, ticket, rpcTimeout, connectionRetryPolicy, conf); }
/** * Writes to filesystem serialized form of segment descriptor if an existing file exists it will try to replace it. * * @param outputFS filesystem. * @param segment DataSegment object. * @param descriptorPath path. * * @throws IOException in case any IO issues occur. */ public static void writeSegmentDescriptor(final FileSystem outputFS, final DataSegment segment, final Path descriptorPath) throws IOException { final DataPusher descriptorPusher = (DataPusher) RetryProxy.create(DataPusher.class, () -> { if (outputFS.exists(descriptorPath)) { if (!outputFS.delete(descriptorPath, false)) { throw new IOException(String.format("Failed to delete descriptor at [%s]", descriptorPath)); } } try (final OutputStream descriptorOut = outputFS.create(descriptorPath, true, DEFAULT_FS_BUFFER_SIZE)) { JSON_MAPPER.writeValue(descriptorOut, segment); descriptorOut.flush(); } }, RetryPolicies.exponentialBackoffRetry(NUM_RETRIES, SECONDS_BETWEEN_RETRIES, TimeUnit.SECONDS)); descriptorPusher.push(); }
public static final RetryPolicy failoverOnNetworkException( RetryPolicy fallbackPolicy, int maxFailovers) { return failoverOnNetworkException(fallbackPolicy, maxFailovers, 0, 0); }
public AliyunOSSFileReaderTask(String key, AliyunOSSFileSystemStore store, ReadBuffer readBuffer) { this.key = key; this.store = store; this.readBuffer = readBuffer; RetryPolicy defaultPolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( MAX_RETRIES, 3, TimeUnit.SECONDS); Map<Class<? extends Exception>, RetryPolicy> policies = new HashMap<>(); policies.put(IOException.class, defaultPolicy); policies.put(IndexOutOfBoundsException.class, RetryPolicies.TRY_ONCE_THEN_FAIL); policies.put(NullPointerException.class, RetryPolicies.TRY_ONCE_THEN_FAIL); this.retryPolicy = RetryPolicies.retryByException(defaultPolicy, policies); }
private static HighTideProtocol createHighTidenode(HighTideProtocol rpcHighTidenode) throws IOException { RetryPolicy createPolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( 5, 5000, TimeUnit.MILLISECONDS); Map<Class<? extends Exception>,RetryPolicy> remoteExceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); exceptionToPolicyMap.put(RemoteException.class, RetryPolicies.retryByRemoteException( RetryPolicies.TRY_ONCE_THEN_FAIL, remoteExceptionToPolicyMap)); RetryPolicy methodPolicy = RetryPolicies.retryByException( RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap); Map<String,RetryPolicy> methodNameToPolicyMap = new HashMap<String,RetryPolicy>(); methodNameToPolicyMap.put("create", methodPolicy); return (HighTideProtocol) RetryProxy.create(HighTideProtocol.class, rpcHighTidenode, methodNameToPolicyMap); }
return RetryPolicies.failoverOnNetworkException( RetryPolicies.TRY_ONCE_THEN_FAIL, maxFailoverAttempts, failoverSleepBaseMs, failoverSleepMaxMs); } else { retryPolicy = RetryPolicies.retryUpToMaximumTimeWithFixedSleep(rmConnectWaitMS, rmConnectionRetryIntervalMS, TimeUnit.MILLISECONDS); return RetryPolicies.retryOtherThanRemoteException( RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);
return RetryPolicies.failoverOnNetworkException( RetryPolicies.TRY_ONCE_THEN_FAIL, maxFailoverAttempts, failoverSleepBaseMs, failoverSleepMaxMs); retryPolicy = RetryPolicies.retryForeverWithFixedSleep( rmConnectionRetryIntervalMS, TimeUnit.MILLISECONDS); } else { retryPolicy = RetryPolicies.retryUpToMaximumTimeWithFixedSleep(rmConnectWaitMS, rmConnectionRetryIntervalMS, TimeUnit.MILLISECONDS); return RetryPolicies.retryOtherThanRemoteException( RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);
private static NamenodeProtocol createNamenode(InetSocketAddress nameNodeAddr, Configuration conf) throws IOException { RetryPolicy timeoutPolicy = RetryPolicies.exponentialBackoffRetry( 5, 200, TimeUnit.MILLISECONDS); Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); RetryPolicy methodPolicy = RetryPolicies.retryByException( timeoutPolicy, exceptionToPolicyMap); Map<String,RetryPolicy> methodNameToPolicyMap = new HashMap<String, RetryPolicy>(); methodNameToPolicyMap.put("getBlocks", methodPolicy); UserGroupInformation ugi; try { ugi = UnixUserGroupInformation.login(conf); } catch (javax.security.auth.login.LoginException e) { throw new IOException(StringUtils.stringifyException(e)); } return (NamenodeProtocol) RetryProxy.create( NamenodeProtocol.class, RPC.getProxy(NamenodeProtocol.class, NamenodeProtocol.versionID, nameNodeAddr, ugi, conf, NetUtils.getDefaultSocketFactory(conf)), methodNameToPolicyMap); }
PurgeCallable(Configuration conf, LlapServiceInstance llapServiceInstance) { this.conf = conf; this.instance = llapServiceInstance; this.socketFactory = NetUtils.getDefaultSocketFactory(conf); //not making this configurable, best effort this.retryPolicy = RetryPolicies.retryUpToMaximumTimeWithFixedSleep( 10000, 2000L, TimeUnit.MILLISECONDS); }
if (maxWaitTime == -1) { retryPolicy = RetryPolicies.retryForeverWithFixedSleep(retryIntervalMS, TimeUnit.MILLISECONDS); } else { retryPolicy = RetryPolicies.retryUpToMaximumTimeWithFixedSleep(maxWaitTime, retryIntervalMS, TimeUnit.MILLISECONDS); return RetryPolicies.retryByException(RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);
} else { retryPolicy = RetryPolicies.retryUpToMaximumTimeWithFixedSleep(maxWaitTime, retryIntervalMS, TimeUnit.MILLISECONDS); exceptionToPolicyMap.put(NMNotYetReadyException.class, retryPolicy); return RetryPolicies.retryByException(RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);
public void testRetryByException() throws UnreliableException { Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap = Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL); UnreliableInterface unreliable = (UnreliableInterface) RetryProxy.create(UnreliableInterface.class, unreliableImpl, retryByException(RETRY_FOREVER, exceptionToPolicyMap)); unreliable.failsOnceThenSucceeds(); try { unreliable.alwaysFailsWithFatalException(); fail("Should fail"); } catch (FatalException e) { // expected } }
@Override public RetryAction shouldRetry(Exception e, int retries, int failovers, boolean isMethodIdempotent) throws Exception { if (e instanceof ServiceException) { //unwrap ServiceException final Throwable cause = e.getCause(); if (cause != null && cause instanceof Exception) { e = (Exception)cause; } } //see (1) and (2) in the javadoc of this method. final RetryPolicy p; if (e instanceof RetriableException || RetryPolicies.getWrappedRetriableException(e) != null) { // RetriableException or RetriableException wrapped p = multipleLinearRandomRetry; } else if (e instanceof RemoteException) { final RemoteException re = (RemoteException)e; p = re.getClassName().equals(remoteExceptionToRetry) ? multipleLinearRandomRetry : RetryPolicies.TRY_ONCE_THEN_FAIL; } else if (e instanceof IOException || e instanceof ServiceException) { p = multipleLinearRandomRetry; } else { //non-IOException p = RetryPolicies.TRY_ONCE_THEN_FAIL; } LOG.debug("RETRY {}) policy={}", retries, p.getClass().getSimpleName(), e); return p.shouldRetry(e, retries, failovers, isMethodIdempotent); }
private static long calculateExponentialTime(long time, int retries) { return calculateExponentialTime(time, retries, Long.MAX_VALUE); }
public void testRetryByRemoteException() throws UnreliableException { Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap = Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL); UnreliableInterface unreliable = (UnreliableInterface) RetryProxy.create(UnreliableInterface.class, unreliableImpl, retryByRemoteException(RETRY_FOREVER, exceptionToPolicyMap)); try { unreliable.alwaysFailsWithRemoteFatalException(); fail("Should fail"); } catch (RemoteException e) { // expected } }
@Test public void testRetryOtherThanRemoteException() throws Throwable { Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap = Collections.<Class<? extends Exception>, RetryPolicy>singletonMap( IOException.class, RETRY_FOREVER); UnreliableInterface unreliable = (UnreliableInterface) RetryProxy.create(UnreliableInterface.class, unreliableImpl, retryOtherThanRemoteException(TRY_ONCE_THEN_FAIL, exceptionToPolicyMap)); // should retry with local IOException. unreliable.failsOnceWithIOException(); try { // won't get retry on remote exception unreliable.failsOnceWithRemoteException(); fail("Should fail"); } catch (RemoteException e) { // expected } }
private static FileSystemStore createDefaultStore(Configuration conf) { FileSystemStore store = new Jets3tFileSystemStore(); RetryPolicy basePolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( conf.getInt("fs.s3.maxRetries", 4), conf.getLong("fs.s3.sleepTimeSeconds", 10), TimeUnit.SECONDS); Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); exceptionToPolicyMap.put(IOException.class, basePolicy); exceptionToPolicyMap.put(S3Exception.class, basePolicy); RetryPolicy methodPolicy = RetryPolicies.retryByException( RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap); Map<String,RetryPolicy> methodNameToPolicyMap = new HashMap<String,RetryPolicy>(); methodNameToPolicyMap.put("storeBlock", methodPolicy); methodNameToPolicyMap.put("retrieveBlock", methodPolicy); return (FileSystemStore) RetryProxy.create(FileSystemStore.class, store, methodNameToPolicyMap); }
private static ClientProtocol createNamenode(ClientProtocol rpcNamenode) throws IOException { RetryPolicy createPolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( 5, LEASE_SOFTLIMIT_PERIOD, TimeUnit.MILLISECONDS); Map<Class<? extends Exception>,RetryPolicy> remoteExceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); remoteExceptionToPolicyMap.put(AlreadyBeingCreatedException.class, createPolicy); Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); exceptionToPolicyMap.put(RemoteException.class, RetryPolicies.retryByRemoteException( RetryPolicies.TRY_ONCE_THEN_FAIL, remoteExceptionToPolicyMap)); RetryPolicy methodPolicy = RetryPolicies.retryByException( RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap); Map<String,RetryPolicy> methodNameToPolicyMap = new HashMap<String,RetryPolicy>(); methodNameToPolicyMap.put("create", methodPolicy); return (ClientProtocol) RetryProxy.create(ClientProtocol.class, rpcNamenode, methodNameToPolicyMap); }
return RetryPolicies.failoverOnNetworkException( RetryPolicies.TRY_ONCE_THEN_FAIL, maxFailoverAttempts, failoverSleepBaseMs, failoverSleepMaxMs); } else { retryPolicy = RetryPolicies.retryUpToMaximumTimeWithFixedSleep(rmConnectWaitMS, rmConnectionRetryIntervalMS, TimeUnit.MILLISECONDS); return RetryPolicies.retryOtherThanRemoteException( RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);
private static NamenodeProtocol createNamenode(Configuration conf) throws IOException { InetSocketAddress nameNodeAddr = DataNode.createSocketAddr(FileSystem.getDefaultUri(conf).getAuthority()); RetryPolicy timeoutPolicy = RetryPolicies.exponentialBackoffRetry( 5, 200, TimeUnit.MILLISECONDS); Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); RetryPolicy methodPolicy = RetryPolicies.retryByException( timeoutPolicy, exceptionToPolicyMap); Map<String,RetryPolicy> methodNameToPolicyMap = new HashMap<String, RetryPolicy>(); methodNameToPolicyMap.put("getBlocks", methodPolicy); UserGroupInformation ugi; try { ugi = UnixUserGroupInformation.login(conf); } catch (javax.security.auth.login.LoginException e) { throw new IOException(StringUtils.stringifyException(e)); } return (NamenodeProtocol) RetryProxy.create( NamenodeProtocol.class, RPC.getProxy(NamenodeProtocol.class, NamenodeProtocol.versionID, nameNodeAddr, ugi, conf, NetUtils.getDefaultSocketFactory(conf)), methodNameToPolicyMap); }