use of org.apache.ignite.transactions.TransactionTimeoutException in project ignite by apache.
the class PlatformCache method convertException.
/**
* {@inheritDoc}
*/
@Override
public Exception convertException(Exception e) {
if (e instanceof CachePartialUpdateException)
return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException) e.getCause(), platformCtx, keepBinary);
if (e instanceof CachePartialUpdateCheckedException)
return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException) e, platformCtx, keepBinary);
if (e.getCause() instanceof EntryProcessorException)
return (Exception) e.getCause();
TransactionDeadlockException deadlockException = X.cause(e, TransactionDeadlockException.class);
if (deadlockException != null)
return deadlockException;
TransactionTimeoutException timeoutException = X.cause(e, TransactionTimeoutException.class);
if (timeoutException != null)
return timeoutException;
return super.convertException(e);
}
use of org.apache.ignite.transactions.TransactionTimeoutException in project ignite by apache.
the class IgniteTxConfigCacheSelfTest method checkExplicitTxTimeout.
/**
* Success if explicit tx fails.
*
* @param cache Cache name.
* @param ignite Ignite instance.
* @throws Exception If failed.
*/
protected void checkExplicitTxTimeout(final IgniteCache<Object, Object> cache, final Ignite ignite) throws Exception {
try (final Transaction tx = ignite.transactions().txStart()) {
assert tx != null;
cache.put("key0", "val0");
sleepForTxFailure();
cache.put("key", "val");
fail("Timeout exception must be thrown");
} catch (CacheException e) {
assert e.getCause() instanceof TransactionTimeoutException;
}
assertNull(ignite.transactions().tx());
assert !cache.containsKey("key0");
assert !cache.containsKey("key");
// New transaction must succeed.
try (final Transaction tx = ignite.transactions().txStart()) {
cache.put("key", "val");
tx.commit();
}
assert cache.containsKey("key");
}
use of org.apache.ignite.transactions.TransactionTimeoutException in project ignite by apache.
the class GridNearOptimisticTxPrepareFuture method prepare0.
/**
* Initializes future.
*
* @param remap Remap flag.
* @param topLocked {@code True} if thread already acquired lock preventing topology change.
*/
@Override
protected void prepare0(boolean remap, boolean topLocked) {
try {
boolean txStateCheck = remap ? tx.state() == PREPARING : tx.state(PREPARING);
if (!txStateCheck) {
if (tx.isRollbackOnly() || tx.setRollbackOnly()) {
if (tx.remainingTime() == -1)
onDone(tx.timeoutException());
else
onDone(tx.rollbackException());
} else
onDone(new IgniteCheckedException("Invalid transaction state for " + "prepare [state=" + tx.state() + ", tx=" + this + ']'));
return;
}
IgniteTxEntry singleWrite = tx.singleWrite();
if (singleWrite != null)
prepareSingle(singleWrite, topLocked, remap);
else
prepare(tx.writeEntries(), topLocked, remap);
markInitialized();
} catch (TransactionTimeoutException e) {
onError(e, false);
}
}
use of org.apache.ignite.transactions.TransactionTimeoutException in project ignite by apache.
the class IgniteCacheQueryNodeRestartSelfTest2 method testRestarts.
/**
* @throws Exception If failed.
*/
@Ignore("https://issues.apache.org/jira/browse/IGNITE-10917")
@Test
public void testRestarts() throws Exception {
int duration = 90 * 1000;
int qryThreadNum = 4;
// 4 + 2 = 6 nodes
int restartThreadsNum = 2;
final int nodeLifeTime = 2 * 1000;
final int logFreq = 10;
startGridsMultiThreaded(GRID_CNT);
final AtomicIntegerArray locks = new AtomicIntegerArray(GRID_CNT);
fillCaches();
final List<List<?>> pRes = grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll();
Thread.sleep(3000);
assertEquals(pRes, grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll());
final List<List<?>> rRes = grid(0).cache("co").query(new SqlFieldsQuery(REPLICATED_QRY)).getAll();
assertFalse(pRes.isEmpty());
assertFalse(rRes.isEmpty());
final AtomicInteger qryCnt = new AtomicInteger();
final AtomicBoolean qrysDone = new AtomicBoolean();
IgniteInternalFuture<?> fut1 = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
final GridRandom rnd = new GridRandom();
while (!qrysDone.get()) {
int g;
do {
g = rnd.nextInt(locks.length());
} while (!locks.compareAndSet(g, 0, 1));
try {
final IgniteEx grid = grid(g);
if (rnd.nextBoolean()) {
// Partitioned query.
final IgniteCache<?, ?> cache = grid.cache("pu");
final SqlFieldsQuery qry = new SqlFieldsQuery(PARTITIONED_QRY);
boolean smallPageSize = rnd.nextBoolean();
if (smallPageSize)
qry.setPageSize(3);
final IgniteCache<Integer, Company> co = grid.cache("co");
try {
runQuery(grid, new Runnable() {
@Override
public void run() {
if (rnd.nextBoolean())
// Get lock run test with open transaction.
co.get(rnd.nextInt(COMPANY_CNT));
assertEquals(pRes, cache.query(qry).getAll());
}
});
} catch (CacheException e) {
// Interruptions are expected here.
if (e.getCause() instanceof IgniteInterruptedCheckedException || e.getCause() instanceof InterruptedException || e.getCause() instanceof ClusterTopologyException || e.getCause() instanceof TransactionTimeoutException || e.getCause() instanceof TransactionException)
continue;
if (e.getCause() instanceof QueryCancelledException)
fail("Retry is expected");
if (!smallPageSize)
U.error(grid.log(), "On large page size must retry.", e);
assertTrue("On large page size must retry.", smallPageSize);
boolean failedOnRemoteFetch = false;
boolean failedOnInterruption = false;
for (Throwable th = e; th != null; th = th.getCause()) {
if (th instanceof InterruptedException) {
failedOnInterruption = true;
break;
}
if (!(th instanceof CacheException))
continue;
if (th.getMessage() != null && th.getMessage().startsWith("Failed to fetch data from node:")) {
failedOnRemoteFetch = true;
break;
}
}
// Interruptions are expected here.
if (failedOnInterruption)
continue;
if (!failedOnRemoteFetch) {
U.error(grid.log(), "Must fail inside of GridResultPage.fetchNextPage or subclass.", e);
fail("Must fail inside of GridResultPage.fetchNextPage or subclass.");
}
}
} else {
// Replicated query.
IgniteCache<?, ?> cache = grid.cache("co");
assertEquals(rRes, cache.query(new SqlFieldsQuery(REPLICATED_QRY)).getAll());
}
} finally {
// Clearing lock in final handler to avoid endless loop if exception is thrown.
locks.set(g, 0);
int c = qryCnt.incrementAndGet();
if (c % logFreq == 0)
info("Executed queries: " + c);
}
}
}
}, qryThreadNum, "query-thread");
final AtomicInteger restartCnt = new AtomicInteger();
final AtomicBoolean restartsDone = new AtomicBoolean();
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Object>() {
@SuppressWarnings({ "BusyWait" })
@Override
public Object call() throws Exception {
GridRandom rnd = new GridRandom();
while (!restartsDone.get()) {
int g;
do {
g = rnd.nextInt(locks.length());
} while (!locks.compareAndSet(g, 0, -1));
try {
log.info("Stop node: " + g);
stopGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
log.info("Start node: " + g);
startGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
} finally {
locks.set(g, 0);
int c = restartCnt.incrementAndGet();
if (c % logFreq == 0)
info("Node restarts: " + c);
}
}
return true;
}
}, restartThreadsNum, "restart-thread");
Thread.sleep(duration);
info("Stopping..");
restartsDone.set(true);
try {
fut2.get(20_000);
} catch (IgniteFutureTimeoutCheckedException e) {
U.dumpThreads(log);
fail("Stopping restarts timeout.");
}
info("Restarts stopped.");
qrysDone.set(true);
// Query thread can stuck in next page waiting loop because all nodes are left.
try {
fut1.get(5_000);
} catch (IgniteFutureTimeoutCheckedException ignored) {
fut1.cancel();
}
info("Queries stopped.");
}
use of org.apache.ignite.transactions.TransactionTimeoutException in project ignite by apache.
the class TxRollbackOnTimeoutTest method testTimeoutOnPrimaryDhtNode0.
/**
* @param prim Primary node.
* @param conc Concurrency.
* @param isolation Isolation.
*
* @throws Exception If failed.
*/
private void testTimeoutOnPrimaryDhtNode0(final Ignite prim, final TransactionConcurrency conc, final TransactionIsolation isolation) throws Exception {
log.info("concurrency=" + conc + ", isolation=" + isolation);
// Force timeout on primary DHT node by blocking DHT prepare response.
toggleBlocking(GridDhtTxPrepareResponse.class, prim, true);
final int val = 0;
try {
multithreaded(new Runnable() {
@Override
public void run() {
try (Transaction txOpt = prim.transactions().txStart(conc, isolation, 300, 1)) {
prim.cache(CACHE_NAME).put(val, val);
txOpt.commit();
}
}
}, 1, "tx-async-thread");
fail();
} catch (TransactionTimeoutException e) {
// Expected.
}
toggleBlocking(GridDhtTxPrepareResponse.class, prim, false);
AffinityTopologyVersion topVer = new AffinityTopologyVersion(GRID_CNT + 1, 0);
for (Ignite ignite : G.allGrids()) ((IgniteEx) ignite).context().cache().context().partitionReleaseFuture(topVer).get(10_000);
}
Aggregations