/** * Performs an operation with transaction with retries. * * @param cache Cache to do the transaction on. * @param clo Closure. * @return Result of closure execution. * @throws IgniteCheckedException If failed. */ public static <T> T doInTransactionWithRetries(IgniteInternalCache cache, IgniteOutClosureX<T> clo) throws IgniteCheckedException { assert cache != null; int attempts = 0; while (attempts < MAX_CACHE_TX_RETRIES) { try (Transaction tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) { T res = clo.applyx(); tx.commit(); return res; } catch (IgniteException | IgniteCheckedException e) { ClusterTopologyException cte = X.cause(e, ClusterTopologyException.class); if (cte != null) ((IgniteFutureImpl)cte.retryReadyFuture()).internalFuture().getUninterruptibly(); else throw U.cast(e); } attempts++; } throw new IgniteCheckedException("Failed to perform operation since max number of attempts " + "exceeded. [maxAttempts=" + MAX_CACHE_TX_RETRIES + ']'); }
((IgniteFutureImpl)cte.retryReadyFuture()).internalFuture().getUninterruptibly(); else throw U.cast(e);