use of javax.cache.CacheException in project ignite by apache.
the class GridReduceQueryExecutor method replicatedUnstableDataNodes.
/**
* Calculates data nodes for replicated caches on unstable topology.
*
* @param cacheIds Cache IDs.
* @return Collection of all data nodes owning all the caches or {@code null} for retry.
*/
private Collection<ClusterNode> replicatedUnstableDataNodes(List<Integer> cacheIds) {
int i = 0;
GridCacheContext<?, ?> cctx = cacheContext(cacheIds.get(i++));
// The main cache is allowed to be partitioned.
if (!cctx.isReplicated()) {
assert cacheIds.size() > 1 : "no extra replicated caches with partitioned main cache";
// Just replace the main cache with the first one extra.
cctx = cacheContext(cacheIds.get(i++));
assert cctx.isReplicated() : "all the extra caches must be replicated here";
}
Set<ClusterNode> nodes = replicatedUnstableDataNodes(cctx);
if (F.isEmpty(nodes))
// Retry.
return null;
for (; i < cacheIds.size(); i++) {
GridCacheContext<?, ?> extraCctx = cacheContext(cacheIds.get(i));
if (extraCctx.isLocal())
continue;
if (!extraCctx.isReplicated())
throw new CacheException("Queries running on replicated cache should not contain JOINs " + "with tables in partitioned caches [replicatedCache=" + cctx.name() + ", " + "partitionedCache=" + extraCctx.name() + "]");
Set<ClusterNode> extraOwners = replicatedUnstableDataNodes(extraCctx);
if (F.isEmpty(extraOwners))
// Retry.
return null;
nodes.retainAll(extraOwners);
if (nodes.isEmpty())
// Retry.
return null;
}
return nodes;
}
use of javax.cache.CacheException in project ignite by apache.
the class GridSqlUnion method getSQL.
/** {@inheritDoc} */
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN \n" : "");
buff.append('(').append(left.getSQL()).append(')');
switch(unionType()) {
case SelectUnion.UNION_ALL:
buff.append("\nUNION ALL\n");
break;
case SelectUnion.UNION:
buff.append("\nUNION\n");
break;
case SelectUnion.INTERSECT:
buff.append("\nINTERSECT\n");
break;
case SelectUnion.EXCEPT:
buff.append("\nEXCEPT\n");
break;
default:
throw new CacheException("type=" + unionType);
}
buff.append('(').append(right.getSQL()).append(')');
getSortLimitSQL(buff);
return buff.toString();
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteCacheCreateRestartSelfTest method testStopOriginatingNode.
/**
* @throws Exception If failed.
*/
public void testStopOriginatingNode() throws Exception {
startGrids(NODES);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 50; i++) {
int node = rnd.nextInt(0, NODES);
final Ignite ignite = ignite(node);
info("Running iteration on the node [idx=" + node + ", nodeId=" + ignite.cluster().localNode().id() + ']');
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.currentThread().setName("create-thread");
try {
ignite.createCache(new CacheConfiguration<>(CACHE_NAME));
} catch (CacheException | IllegalStateException e) {
log.info("Expected error: " + e);
}
return null;
}
});
ignite.close();
fut.get();
Ignite ignite0 = startGrid(node);
ignite0.destroyCache(CACHE_NAME);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteCacheClientNodeChangingTopologyTest method multinode.
/**
* @param atomicityMode Atomicity mode cache.
* @param testType Test type.
* @throws Exception If failed.
*/
private void multinode(CacheAtomicityMode atomicityMode, final TestType testType) throws Exception {
ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(PARTITIONED);
ccfg.setBackups(1);
ccfg.setAtomicityMode(atomicityMode);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setRebalanceMode(SYNC);
final int SRV_CNT = 4;
for (int i = 0; i < SRV_CNT; i++) startGrid(i);
final int CLIENT_CNT = 4;
final List<Ignite> clients = new ArrayList<>();
client = true;
for (int i = 0; i < CLIENT_CNT; i++) {
Ignite ignite = startGrid(SRV_CNT + i);
assertTrue(ignite.configuration().isClientMode());
clients.add(ignite);
}
final AtomicBoolean stop = new AtomicBoolean();
final AtomicInteger threadIdx = new AtomicInteger(0);
final int THREADS = CLIENT_CNT * 3;
final ConcurrentHashSet<Integer> putKeys = new ConcurrentHashSet<>();
IgniteInternalFuture<?> fut;
try {
fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int clientIdx = threadIdx.getAndIncrement() % CLIENT_CNT;
Ignite ignite = clients.get(clientIdx);
assertTrue(ignite.configuration().isClientMode());
Thread.currentThread().setName("update-thread-" + ignite.name());
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
boolean useTx = testType == TestType.OPTIMISTIC_TX || testType == TestType.OPTIMISTIC_SERIALIZABLE_TX || testType == TestType.PESSIMISTIC_TX;
if (useTx || testType == TestType.LOCK) {
assertEquals(TRANSACTIONAL, cache.getConfiguration(CacheConfiguration.class).getAtomicityMode());
}
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int cntr = 0;
while (!stop.get()) {
TreeMap<Integer, Integer> map = new TreeMap<>();
for (int i = 0; i < 100; i++) {
Integer key = rnd.nextInt(0, 1000);
map.put(key, rnd.nextInt());
}
try {
if (testType == TestType.LOCK) {
Lock lock = cache.lockAll(map.keySet());
lock.lock();
lock.unlock();
} else {
if (useTx) {
IgniteTransactions txs = ignite.transactions();
TransactionConcurrency concurrency = testType == TestType.PESSIMISTIC_TX ? PESSIMISTIC : OPTIMISTIC;
TransactionIsolation isolation = testType == TestType.OPTIMISTIC_SERIALIZABLE_TX ? SERIALIZABLE : REPEATABLE_READ;
try (Transaction tx = txs.txStart(concurrency, isolation)) {
cache.putAll(map);
tx.commit();
}
} else
cache.putAll(map);
putKeys.addAll(map.keySet());
}
} catch (CacheException | IgniteException e) {
log.info("Operation failed, ignore: " + e);
}
if (++cntr % 100 == 0)
log.info("Iteration: " + cntr);
if (updateBarrier != null)
updateBarrier.await();
}
return null;
}
}, THREADS, "update-thread");
long stopTime = System.currentTimeMillis() + 60_000;
while (System.currentTimeMillis() < stopTime) {
boolean restartClient = ThreadLocalRandom.current().nextBoolean();
Integer idx = null;
if (restartClient) {
log.info("Start client node.");
client = true;
IgniteEx ignite = startGrid(SRV_CNT + CLIENT_CNT);
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
} else {
idx = ThreadLocalRandom.current().nextInt(0, SRV_CNT);
log.info("Stop server node: " + idx);
stopGrid(idx);
}
updateBarrier = new CyclicBarrier(THREADS + 1, new Runnable() {
@Override
public void run() {
updateBarrier = null;
}
});
try {
updateBarrier.await(30_000, TimeUnit.MILLISECONDS);
} catch (TimeoutException ignored) {
log.error("Failed to wait for update.");
for (Ignite ignite : G.allGrids()) ((IgniteKernal) ignite).dumpDebugInfo();
U.dumpThreads(log);
CyclicBarrier barrier0 = updateBarrier;
if (barrier0 != null)
barrier0.reset();
fail("Failed to wait for update.");
}
U.sleep(500);
if (restartClient) {
log.info("Stop client node.");
stopGrid(SRV_CNT + CLIENT_CNT);
} else {
log.info("Start server node: " + idx);
client = false;
startGrid(idx);
}
updateBarrier = new CyclicBarrier(THREADS + 1, new Runnable() {
@Override
public void run() {
updateBarrier = null;
}
});
try {
updateBarrier.await(30_000, TimeUnit.MILLISECONDS);
} catch (TimeoutException ignored) {
log.error("Failed to wait for update.");
for (Ignite ignite : G.allGrids()) ((IgniteKernal) ignite).dumpDebugInfo();
U.dumpThreads(log);
CyclicBarrier barrier0 = updateBarrier;
if (barrier0 != null)
barrier0.reset();
fail("Failed to wait for update.");
}
U.sleep(500);
}
} finally {
stop.set(true);
}
fut.get(30_000);
if (testType != TestType.LOCK)
checkData(null, putKeys, grid(SRV_CNT).cache(DEFAULT_CACHE_NAME), SRV_CNT + CLIENT_CNT);
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteCacheNearRestartRollbackSelfTest method updateCache.
/**
* Updates the cache or rollback the update.
*
* @param ignite Ignite instance to use.
* @param newVal the new value to put to the entries
* @param invoke whether to use invokeAll() or putAll()
* @param rollback whether to rollback the changes or commit
* @param keys Collection of keys to update.
*/
private void updateCache(Ignite ignite, int newVal, boolean invoke, boolean rollback, Set<Integer> keys) {
final IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
if (rollback) {
while (true) {
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
updateEntries(cache, newVal, invoke, keys);
tx.rollback();
break;
} catch (CacheException e) {
if (e.getCause() instanceof ClusterTopologyException) {
ClusterTopologyException topEx = (ClusterTopologyException) e.getCause();
topEx.retryReadyFuture().get();
} else
throw e;
} catch (ClusterTopologyException e) {
IgniteFuture<?> fut = e.retryReadyFuture();
fut.get();
} catch (TransactionRollbackException ignore) {
// Safe to retry right away.
}
}
} else
updateEntries(cache, newVal, invoke, keys);
}
Aggregations