use of javax.cache.CacheException in project ignite by apache.
the class IgniteCacheProxy method query.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <R> QueryCursor<R> query(Query<R> qry) {
A.notNull(qry, "qry");
GridCacheGateway<K, V> gate = this.gate;
CacheOperationContext prev = onEnter(gate, opCtx);
try {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
validate(qry);
convertToBinary(qry);
CacheOperationContext opCtxCall = ctx.operationContextPerCall();
boolean keepBinary = opCtxCall != null && opCtxCall.isKeepBinary();
if (qry instanceof ContinuousQuery)
return (QueryCursor<R>) queryContinuous((ContinuousQuery<K, V>) qry, qry.isLocal(), keepBinary);
if (qry instanceof SqlQuery)
return (QueryCursor<R>) ctx.kernalContext().query().querySql(ctx, (SqlQuery) qry, keepBinary);
if (qry instanceof SqlFieldsQuery)
return (FieldsQueryCursor<R>) ctx.kernalContext().query().querySqlFields(ctx, (SqlFieldsQuery) qry, keepBinary);
if (qry instanceof ScanQuery)
return query((ScanQuery) qry, null, projection(qry.isLocal()));
return (QueryCursor<R>) query(qry, projection(qry.isLocal()));
} catch (Exception e) {
if (e instanceof CacheException)
throw (CacheException) e;
throw new CacheException(e);
} finally {
onLeave(gate, prev);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class GridCacheUtils method convertToCacheException.
/**
* @param e Ignite checked exception.
* @return CacheException runtime exception, never null.
*/
@NotNull
public static RuntimeException convertToCacheException(IgniteCheckedException e) {
IgniteClientDisconnectedCheckedException disconnectedErr = e.getCause(IgniteClientDisconnectedCheckedException.class);
if (disconnectedErr != null) {
assert disconnectedErr.reconnectFuture() != null : disconnectedErr;
e = disconnectedErr;
}
if (e.hasCause(CacheWriterException.class))
return new CacheWriterException(U.convertExceptionNoWrap(e));
if (e instanceof CachePartialUpdateCheckedException)
return new CachePartialUpdateException((CachePartialUpdateCheckedException) e);
else if (e instanceof CacheAtomicUpdateTimeoutCheckedException)
return new CacheAtomicUpdateTimeoutException(e.getMessage(), e);
else if (e instanceof ClusterTopologyServerNotFoundException)
return new CacheServerNotFoundException(e.getMessage(), e);
if (e.getCause() instanceof CacheException)
return (CacheException) e.getCause();
if (e.getCause() instanceof NullPointerException)
return (NullPointerException) e.getCause();
C1<IgniteCheckedException, IgniteException> converter = U.getExceptionConverter(e.getClass());
return converter != null ? new CacheException(converter.apply(e)) : new CacheException(e);
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteCacheProxy method query.
/** {@inheritDoc} */
@Override
public <T, R> QueryCursor<R> query(Query<T> qry, IgniteClosure<T, R> transformer) {
A.notNull(qry, "qry");
A.notNull(transformer, "transformer");
if (!(qry instanceof ScanQuery))
throw new UnsupportedOperationException("Transformers are supported only for SCAN queries.");
GridCacheGateway<K, V> gate = this.gate;
CacheOperationContext prev = onEnter(gate, opCtx);
try {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
validate(qry);
return query((ScanQuery<K, V>) qry, transformer, projection(qry.isLocal()));
} catch (Exception e) {
if (e instanceof CacheException)
throw (CacheException) e;
throw new CacheException(e);
} finally {
onLeave(gate, prev);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class CacheObjectBinaryProcessorImpl method metadata.
/** {@inheritDoc} */
@Override
public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds) throws BinaryObjectException {
try {
Collection<BinaryMetadataKey> keys = new ArrayList<>(typeIds.size());
for (Integer typeId : typeIds) keys.add(new BinaryMetadataKey(typeId));
Map<Integer, BinaryType> res = U.newHashMap(metadataLocCache.size());
for (Map.Entry<Integer, BinaryMetadataHolder> e : metadataLocCache.entrySet()) res.put(e.getKey(), e.getValue().metadata().wrap(binaryCtx));
return res;
} catch (CacheException e) {
throw new BinaryObjectException(e);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteClientReconnectMassiveShutdownTest method massiveServersShutdown.
/**
* @param stopType How tp stop node.
* @throws Exception If any error occurs.
*/
private void massiveServersShutdown(final StopType stopType) throws Exception {
clientMode = false;
startGridsMultiThreaded(GRID_CNT);
clientMode = true;
startGridsMultiThreaded(GRID_CNT, CLIENT_GRID_CNT);
final AtomicBoolean done = new AtomicBoolean();
// Starting a cache dynamically.
Ignite client = grid(GRID_CNT);
assertTrue(client.configuration().isClientMode());
final CacheConfiguration<String, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
cfg.setCacheMode(PARTITIONED);
cfg.setAtomicityMode(TRANSACTIONAL);
cfg.setBackups(2);
IgniteCache<String, Integer> cache = client.getOrCreateCache(cfg);
assertNotNull(cache);
HashMap<String, Integer> put = new HashMap<>();
// Load some data.
for (int i = 0; i < 10_000; i++) put.put(String.valueOf(i), i);
cache.putAll(put);
// Preparing client nodes and starting cache operations from them.
final BlockingQueue<Integer> clientIdx = new LinkedBlockingQueue<>();
for (int i = GRID_CNT; i < GRID_CNT + CLIENT_GRID_CNT; i++) clientIdx.add(i);
final CountDownLatch latch = new CountDownLatch(CLIENT_GRID_CNT);
IgniteInternalFuture<?> clientsFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
int idx = clientIdx.take();
Ignite ignite = grid(idx);
Thread.currentThread().setName("client-thread-" + ignite.name());
assertTrue(ignite.configuration().isClientMode());
IgniteCache<String, Integer> cache = ignite.getOrCreateCache(cfg);
assertNotNull(cache);
IgniteTransactions txs = ignite.transactions();
Random rand = new Random();
latch.countDown();
while (!done.get()) {
try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(String.valueOf(rand.nextInt(10_000)), rand.nextInt(50_000));
tx.commit();
} catch (ClusterTopologyException ex) {
ex.retryReadyFuture().get();
} catch (IgniteException | CacheException e) {
if (X.hasCause(e, IgniteClientDisconnectedException.class)) {
IgniteClientDisconnectedException cause = X.cause(e, IgniteClientDisconnectedException.class);
assert cause != null;
cause.reconnectFuture().get();
} else if (X.hasCause(e, ClusterTopologyException.class)) {
ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
assert cause != null;
cause.retryReadyFuture().get();
} else
throw e;
}
}
return null;
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
}, CLIENT_GRID_CNT, "client-thread");
try {
if (!latch.await(30, SECONDS)) {
log.warning("Failed to wait for for clients start.");
U.dumpThreads(log);
fail("Failed to wait for for clients start.");
}
// Killing a half of server nodes.
final int srvsToKill = GRID_CNT / 2;
final BlockingQueue<Integer> victims = new LinkedBlockingQueue<>();
for (int i = 0; i < srvsToKill; i++) victims.add(i);
final BlockingQueue<Integer> assassins = new LinkedBlockingQueue<>();
for (int i = srvsToKill; i < GRID_CNT; i++) assassins.add(i);
IgniteInternalFuture<?> srvsShutdownFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Thread.sleep(5_000);
Ignite assassin = grid(assassins.take());
assertFalse(assassin.configuration().isClientMode());
Ignite victim = grid(victims.take());
assertFalse(victim.configuration().isClientMode());
log.info("Kill node [node=" + victim.name() + ", from=" + assassin.name() + ']');
switch(stopType) {
case CLOSE:
victim.close();
break;
case FAIL_EVENT:
UUID nodeId = victim.cluster().localNode().id();
assassin.configuration().getDiscoverySpi().failNode(nodeId, null);
break;
case SIMULATE_FAIL:
((TcpDiscoverySpi) victim.configuration().getDiscoverySpi()).simulateNodeFailure();
break;
default:
fail();
}
return null;
}
}, assassins.size(), "kill-thread");
srvsShutdownFut.get();
Thread.sleep(15_000);
done.set(true);
clientsFut.get();
awaitPartitionMapExchange();
for (int k = 0; k < 10_000; k++) {
String key = String.valueOf(k);
Object val = cache.get(key);
for (int i = srvsToKill; i < GRID_CNT; i++) assertEquals(val, ignite(i).cache(DEFAULT_CACHE_NAME).get(key));
}
} finally {
done.set(true);
}
}
Aggregations