use of javax.cache.CacheException in project ignite by apache.
the class GridQueryProcessor method querySqlFieldsNoCache.
/**
* Query SQL fields without strict dependency on concrete cache.
*
* @param qry Query.
* @param keepBinary Keep binary flag.
* @return Cursor.
*/
public FieldsQueryCursor<List<?>> querySqlFieldsNoCache(final SqlFieldsQuery qry, final boolean keepBinary) {
checkxEnabled();
validateSqlFieldsQuery(qry);
if (qry.isLocal())
throw new IgniteException("Local query is not supported without specific cache.");
if (qry.getSchema() == null)
qry.setSchema(QueryUtils.DFLT_SCHEMA);
if (!busyLock.enterBusy())
throw new IllegalStateException("Failed to execute query (grid is stopping).");
try {
IgniteOutClosureX<FieldsQueryCursor<List<?>>> clo = new IgniteOutClosureX<FieldsQueryCursor<List<?>>>() {
@Override
public FieldsQueryCursor<List<?>> applyx() throws IgniteCheckedException {
GridQueryCancel cancel = new GridQueryCancel();
return idx.queryDistributedSqlFields(qry.getSchema(), qry, keepBinary, cancel, null);
}
};
return executeQuery(GridCacheQueryType.SQL_FIELDS, qry.getSql(), null, clo, true);
} catch (IgniteCheckedException e) {
throw new CacheException(e);
} finally {
busyLock.leaveBusy();
}
}
use of javax.cache.CacheException in project ignite by apache.
the class PlatformUtils method unwrapQueryException.
/**
* Unwrap query exception.
*
* @param err Initial error.
* @return Unwrapped error.
*/
public static IgniteCheckedException unwrapQueryException(Throwable err) {
assert err != null;
Throwable parent = err;
Throwable child = parent.getCause();
while (true) {
if (child == null || child == parent)
break;
if (child instanceof IgniteException || child instanceof IgniteCheckedException || child instanceof CacheException) {
// Continue unwrapping.
parent = child;
child = parent.getCause();
continue;
}
break;
}
// Specific exception found, but detailed message doesn't exist. Just pass exception name then.
if (parent.getMessage() == null)
return new IgniteCheckedException("Query execution failed due to exception: " + parent.getClass().getName(), err);
return new IgniteCheckedException(parent.getMessage(), err);
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteCachePutAllRestartTest method testStopNode.
/**
* @throws Exception If failed.
*/
public void testStopNode() throws Exception {
startGrids(NODES);
final AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Thread.currentThread().setName("put-thread");
IgniteCache<Integer, Integer> cache = ignite(0).cache(CACHE_NAME);
Random rnd = new Random();
int iter = 0;
while (!stop.get()) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < 10; i++) map.put(rnd.nextInt(1000), i);
try {
cache.putAll(map);
} catch (CacheException e) {
log.info("Update failed: " + e);
}
iter++;
if (iter % 1000 == 0)
log.info("Iteration: " + iter);
}
return null;
}
});
try {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
long endTime = System.currentTimeMillis() + 2 * 60_000;
while (System.currentTimeMillis() < endTime) {
int node = rnd.nextInt(1, NODES);
stopGrid(node);
startGrid(node);
}
} finally {
stop.set(true);
}
fut.get();
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteCachePutAllRestartTest method testStopOriginatingNode.
/**
* @throws Exception If failed.
*/
public void testStopOriginatingNode() throws Exception {
startGrids(NODES);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
long endTime = System.currentTimeMillis() + 2 * 60_000;
while (System.currentTimeMillis() < endTime) {
int node = rnd.nextInt(0, NODES);
final Ignite ignite = ignite(node);
info("Running iteration on the node [idx=" + node + ", nodeId=" + ignite.cluster().localNode().id() + ']');
final IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.currentThread().setName("put-thread");
Random rnd = new Random();
long endTime = System.currentTimeMillis() + 60_000;
try {
int iter = 0;
while (System.currentTimeMillis() < endTime) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < 10; i++) map.put(rnd.nextInt(1000), i);
cache.putAll(map);
iter++;
log.info("Iteration: " + iter);
}
fail("Should fail.");
} catch (CacheException | IllegalStateException e) {
log.info("Expected error: " + e);
}
return null;
}
});
ignite.close();
fut.get();
startGrid(node);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class CacheContinuousQueryFailoverAbstractSelfTest method checkBackupQueue.
/**
* @param backups Number of backups.
* @param updateFromClient If {@code true} executes cache update from client node.
* @throws Exception If failed.
*/
private void checkBackupQueue(int backups, boolean updateFromClient) throws Exception {
this.backups = atomicityMode() == CacheAtomicityMode.ATOMIC ? backups : backups < 2 ? 2 : backups;
final int SRV_NODES = 4;
startGridsMultiThreaded(SRV_NODES);
client = true;
Ignite qryClient = startGrid(SRV_NODES);
client = false;
IgniteCache<Object, Object> qryClientCache = qryClient.cache(DEFAULT_CACHE_NAME);
Affinity<Object> aff = qryClient.affinity(DEFAULT_CACHE_NAME);
CacheEventListener1 lsnr = asyncCallback() ? new CacheEventAsyncListener1(false) : new CacheEventListener1(false);
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(lsnr);
QueryCursor<?> cur = qryClientCache.query(qry);
int PARTS = 10;
Map<Object, T2<Object, Object>> updates = new HashMap<>();
List<T3<Object, Object, Object>> expEvts = new ArrayList<>();
for (int i = 0; i < (atomicityMode() == CacheAtomicityMode.ATOMIC ? SRV_NODES - 1 : SRV_NODES - 2); i++) {
log.info("Stop iteration: " + i);
TestCommunicationSpi spi = (TestCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
Ignite ignite = ignite(i);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
List<Integer> keys = testKeys(cache, PARTS);
CountDownLatch latch = new CountDownLatch(keys.size());
lsnr.latch = latch;
boolean first = true;
for (Integer key : keys) {
log.info("Put [node=" + ignite.name() + ", key=" + key + ", part=" + aff.partition(key) + ']');
T2<Object, Object> t = updates.get(key);
if (updateFromClient) {
if (atomicityMode() == CacheAtomicityMode.TRANSACTIONAL) {
try (Transaction tx = qryClient.transactions().txStart()) {
qryClientCache.put(key, key);
tx.commit();
} catch (CacheException | ClusterTopologyException ignored) {
log.warning("Failed put. [Key=" + key + ", val=" + key + "]");
continue;
}
} else
qryClientCache.put(key, key);
} else {
if (atomicityMode() == CacheAtomicityMode.TRANSACTIONAL) {
try (Transaction tx = ignite.transactions().txStart()) {
cache.put(key, key);
tx.commit();
} catch (CacheException | ClusterTopologyException ignored) {
log.warning("Failed put. [Key=" + key + ", val=" + key + "]");
continue;
}
} else
cache.put(key, key);
}
if (t == null) {
updates.put(key, new T2<>((Object) key, null));
expEvts.add(new T3<>((Object) key, (Object) key, null));
} else {
updates.put(key, new T2<>((Object) key, (Object) key));
expEvts.add(new T3<>((Object) key, (Object) key, (Object) key));
}
if (first) {
spi.skipMsg = true;
first = false;
}
}
stopGrid(i);
if (!latch.await(5, SECONDS)) {
Set<Integer> keys0 = new HashSet<>(keys);
keys0.removeAll(lsnr.keys);
log.info("Missed events for keys: " + keys0);
fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + lsnr.latch.getCount() + ']');
}
checkEvents(expEvts, lsnr);
}
for (int i = 0; i < (atomicityMode() == CacheAtomicityMode.ATOMIC ? SRV_NODES - 1 : SRV_NODES - 2); i++) {
log.info("Start iteration: " + i);
Ignite ignite = startGrid(i);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
List<Integer> keys = testKeys(cache, PARTS);
CountDownLatch latch = new CountDownLatch(keys.size());
lsnr.latch = latch;
for (Integer key : keys) {
log.info("Put [node=" + ignite.name() + ", key=" + key + ", part=" + aff.partition(key) + ']');
T2<Object, Object> t = updates.get(key);
if (t == null) {
updates.put(key, new T2<>((Object) key, null));
expEvts.add(new T3<>((Object) key, (Object) key, null));
} else {
updates.put(key, new T2<>((Object) key, (Object) key));
expEvts.add(new T3<>((Object) key, (Object) key, (Object) key));
}
if (updateFromClient)
qryClientCache.put(key, key);
else
cache.put(key, key);
}
if (!latch.await(10, SECONDS)) {
Set<Integer> keys0 = new HashSet<>(keys);
keys0.removeAll(lsnr.keys);
log.info("Missed events for keys: " + keys0);
fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + lsnr.latch.getCount() + ']');
}
checkEvents(expEvts, lsnr);
}
cur.close();
assertFalse("Unexpected error during test, see log for details.", err);
}
Aggregations