use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.
the class IgniteCacheDistributedPartitionQueryNodeRestartsSelfTest method testJoinQueryUnstableTopology.
/**
* Tests join query within region on unstable topology.
*/
public void testJoinQueryUnstableTopology() throws Exception {
final AtomicBoolean stop = new AtomicBoolean();
final AtomicIntegerArray states = new AtomicIntegerArray(GRIDS_COUNT);
final Ignite client = grid("client");
final AtomicInteger cnt = new AtomicInteger();
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
while (!stop.get()) {
doTestJoinQuery(client, rnd.nextInt(PARTS_PER_REGION.length) + 1);
int cur = cnt.incrementAndGet();
if (cur % 100 == 0)
log().info("Queries count: " + cur);
}
}
}, QUERY_THREADS_CNT);
final AtomicIntegerArray restartStats = new AtomicIntegerArray(GRIDS_COUNT);
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!stop.get()) {
int grid = rnd.nextInt(GRIDS_COUNT);
String name = getTestIgniteInstanceName(grid);
Integer regionId = regionForGrid(name);
// Restart nodes only from region with enough number of nodes.
if (regionId != 3 && regionId != 4)
continue;
if (states.compareAndSet(grid, 0, 1)) {
restartStats.incrementAndGet(grid);
try {
stopGrid(grid);
Thread.sleep(rnd.nextInt(NODE_RESTART_TIME));
startGrid(grid);
Thread.sleep(rnd.nextInt(NODE_RESTART_TIME));
} finally {
states.set(grid, 0);
}
}
}
return null;
}
}, RESTART_THREADS_CNT);
try {
fut2.get(60, TimeUnit.SECONDS);
} catch (IgniteFutureTimeoutCheckedException ignored) {
stop.set(true);
}
try {
fut.get();
} finally {
log().info("Queries count: " + cnt.get());
for (int i = 0; i < GRIDS_COUNT; i++) log().info("Grid [name = " + getTestIgniteInstanceName(i) + ", idx=" + i + " ] restarts count: " + restartStats.get(i));
}
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.
the class GridExecutorService method invokeAny.
/**
* {@inheritDoc}
* <p>
* Note, for compilation with JDK 1.6 necessary to change method signature
* (note the {@code <? extends T>} clause).
* <pre name="code" class="java">
* ...
* public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
* throws InterruptedException, ExecutionException, TimeoutException {
* }
* ...
* </pre>
*/
@SuppressWarnings({ "MethodWithTooExceptionsDeclared" })
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
A.notNull(tasks, "tasks != null");
A.ensure(!tasks.isEmpty(), "!tasks.isEmpty()");
A.ensure(timeout >= 0, "timeout >= 0");
A.notNull(unit, "unit != null");
long now = System.currentTimeMillis();
timeout = TimeUnit.MILLISECONDS.convert(timeout, unit);
long end = timeout == 0 ? Long.MAX_VALUE : timeout + now;
// Prevent overflow.
if (end < 0)
end = Long.MAX_VALUE;
checkShutdown();
Collection<IgniteInternalFuture<T>> taskFuts = new ArrayList<>();
for (Callable<T> cmd : tasks) {
// Execute task with predefined timeout.
IgniteInternalFuture<T> fut;
ctx.gateway().readLock();
try {
fut = ctx.closure().callAsync(BALANCE, cmd, prj.nodes());
} finally {
ctx.gateway().readUnlock();
}
taskFuts.add(fut);
}
T res = null;
boolean isInterrupted = false;
boolean isResRcvd = false;
int errCnt = 0;
for (IgniteInternalFuture<T> fut : taskFuts) {
now = U.currentTimeMillis();
boolean cancel = false;
if (!isInterrupted && !isResRcvd && now < end) {
try {
res = fut.get(end - now);
isResRcvd = true;
// Cancel next tasks (avoid current task cancellation below in loop).
continue;
} catch (IgniteFutureTimeoutCheckedException ignored) {
if (log.isDebugEnabled())
log.debug("Timeout occurred during getting task result: " + fut);
cancel = true;
} catch (IgniteCheckedException e) {
// Note: that execution may be interrupted on remote node. Possible bug.
if (e.getCause() instanceof InterruptedException)
isInterrupted = true;
else
errCnt++;
}
}
// Cancel active task if any task interrupted, timeout elapsed or received task result before.
if ((isInterrupted || isResRcvd || cancel) && !fut.isDone())
cancelFuture(fut);
}
// Throw exception if any task wait was interrupted.
if (isInterrupted)
throw new InterruptedException("Got interrupted while waiting for tasks invocation.");
// per executor service contract.
if (!isResRcvd && taskFuts.size() == errCnt)
throw new ExecutionException("Failed to get any task completion.", null);
// throw timeout exception per executor service contract.
if (!isResRcvd)
throw new TimeoutException("Timeout occurred during tasks invocation.");
return res;
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.
the class GridCachePartitionExchangeManager method onKernalStart0.
/** {@inheritDoc} */
@Override
protected void onKernalStart0(boolean reconnect) throws IgniteCheckedException {
super.onKernalStart0(reconnect);
ClusterNode loc = cctx.localNode();
long startTime = loc.metrics().getStartTime();
assert startTime > 0;
// Generate dummy discovery event for local node joining.
T2<DiscoveryEvent, DiscoCache> locJoin = cctx.discovery().localJoin();
DiscoveryEvent discoEvt = locJoin.get1();
DiscoCache discoCache = locJoin.get2();
GridDhtPartitionExchangeId exchId = initialExchangeId();
GridDhtPartitionsExchangeFuture fut = exchangeFuture(exchId, discoEvt, discoCache, null, null);
if (reconnect)
reconnectExchangeFut = new GridFutureAdapter<>();
exchWorker.addFirstExchangeFuture(fut);
if (!cctx.kernalContext().clientNode()) {
for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) {
final int idx = cnt;
cctx.io().addOrderedHandler(rebalanceTopic(cnt), new CI2<UUID, GridCacheMessage>() {
@Override
public void apply(final UUID id, final GridCacheMessage m) {
if (!enterBusy())
return;
try {
GridCacheContext cacheCtx = cctx.cacheContext(m.cacheId);
if (cacheCtx != null) {
if (m instanceof GridDhtPartitionSupplyMessage)
cacheCtx.preloader().handleSupplyMessage(idx, id, (GridDhtPartitionSupplyMessage) m);
else if (m instanceof GridDhtPartitionDemandMessage)
cacheCtx.preloader().handleDemandMessage(idx, id, (GridDhtPartitionDemandMessage) m);
else
U.error(log, "Unsupported message type: " + m.getClass().getName());
}
} finally {
leaveBusy();
}
}
});
}
}
new IgniteThread(cctx.igniteInstanceName(), "exchange-worker", exchWorker).start();
if (reconnect) {
fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
try {
fut.get();
for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(null);
reconnectExchangeFut.onDone();
} catch (IgniteCheckedException e) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(e);
reconnectExchangeFut.onDone(e);
}
}
});
} else {
if (log.isDebugEnabled())
log.debug("Beginning to wait on local exchange future: " + fut);
boolean first = true;
while (true) {
try {
fut.get(cctx.preloadExchangeTimeout());
break;
} catch (IgniteFutureTimeoutCheckedException ignored) {
if (first) {
U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + " ^-- Transactions in deadlock." + U.nl() + " ^-- Long running transactions (ignore if this is the case)." + U.nl() + " ^-- Unreleased explicit locks.");
first = false;
} else
U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
} catch (IgniteNeedReconnectException e) {
throw e;
} catch (Exception e) {
if (fut.reconnectOnError(e))
throw new IgniteNeedReconnectException(cctx.localNode(), e);
throw e;
}
}
AffinityTopologyVersion nodeStartVer = new AffinityTopologyVersion(discoEvt.topologyVersion(), 0);
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (nodeStartVer.equals(cacheCtx.startTopologyVersion()))
cacheCtx.preloader().onInitialExchangeComplete(null);
}
if (log.isDebugEnabled())
log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
}
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.
the class GridFutureAdapterSelfTest method checkChaining.
/**
* @param exec Executor for chain callback.
* @throws Exception If failed.
*/
@SuppressWarnings("ErrorNotRethrown")
private void checkChaining(ExecutorService exec) throws Exception {
final CX1<IgniteInternalFuture<Object>, Object> passThrough = new CX1<IgniteInternalFuture<Object>, Object>() {
@Override
public Object applyx(IgniteInternalFuture<Object> f) throws IgniteCheckedException {
return f.get();
}
};
GridFutureAdapter<Object> fut = new GridFutureAdapter<>();
IgniteInternalFuture<Object> chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
assertFalse(fut.isDone());
assertFalse(chain.isDone());
try {
chain.get(20);
fail("Expects timeout exception.");
} catch (IgniteFutureTimeoutCheckedException e) {
info("Expected timeout exception: " + e.getMessage());
}
fut.onDone("result");
assertEquals("result", chain.get(1));
// Test exception re-thrown.
fut = new GridFutureAdapter<>();
chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
fut.onDone(new ClusterGroupEmptyCheckedException("test exception"));
try {
chain.get();
fail("Expects failed with exception.");
} catch (ClusterGroupEmptyCheckedException e) {
info("Expected exception: " + e.getMessage());
}
// Test error re-thrown.
fut = new GridFutureAdapter<>();
chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
try {
fut.onDone(new StackOverflowError("test error"));
if (exec == null)
fail("Expects failed with error.");
} catch (StackOverflowError e) {
info("Expected error: " + e.getMessage());
}
try {
chain.get();
fail("Expects failed with error.");
} catch (StackOverflowError e) {
info("Expected error: " + e.getMessage());
}
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.
the class IgniteCacheCrossCacheTxFailoverTest method crossCacheTxFailover.
/**
* @param cacheMode Cache mode.
* @param sameAff If {@code false} uses different number of partitions for caches.
* @param concurrency Transaction concurrency.
* @param isolation Transaction isolation.
* @throws Exception If failed.
*/
private void crossCacheTxFailover(CacheMode cacheMode, boolean sameAff, final TransactionConcurrency concurrency, final TransactionIsolation isolation) throws Exception {
IgniteKernal ignite0 = (IgniteKernal) ignite(0);
final AtomicBoolean stop = new AtomicBoolean();
try {
ignite0.createCache(cacheConfiguration(CACHE1, cacheMode, 256));
ignite0.createCache(cacheConfiguration(CACHE2, cacheMode, sameAff ? 256 : 128));
final AtomicInteger threadIdx = new AtomicInteger();
IgniteInternalFuture<?> fut = runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = threadIdx.getAndIncrement();
Ignite ignite = ignite(idx % GRID_CNT);
log.info("Started update thread [node=" + ignite.name() + ", client=" + ignite.configuration().isClientMode() + ']');
IgniteCache<TestKey, TestValue> cache1 = ignite.cache(CACHE1);
IgniteCache<TestKey, TestValue> cache2 = ignite.cache(CACHE2);
assertNotSame(cache1, cache2);
IgniteTransactions txs = ignite.transactions();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
long iter = 0;
while (!stop.get()) {
boolean sameKey = rnd.nextBoolean();
try {
try (Transaction tx = txs.txStart(concurrency, isolation)) {
if (sameKey) {
TestKey key = new TestKey(rnd.nextLong(KEY_RANGE));
cacheOperation(rnd, cache1, key);
cacheOperation(rnd, cache2, key);
} else {
TestKey key1 = new TestKey(rnd.nextLong(KEY_RANGE));
TestKey key2 = new TestKey(key1.key() + 1);
cacheOperation(rnd, cache1, key1);
cacheOperation(rnd, cache2, key2);
}
tx.commit();
}
} catch (CacheException | IgniteException e) {
log.info("Update error: " + e);
}
if (iter++ % 500 == 0)
log.info("Iteration: " + iter);
}
return null;
}
/**
* @param rnd Random.
* @param cache Cache.
* @param key Key.
*/
private void cacheOperation(ThreadLocalRandom rnd, IgniteCache<TestKey, TestValue> cache, TestKey key) {
switch(rnd.nextInt(4)) {
case 0:
cache.put(key, new TestValue(rnd.nextLong()));
break;
case 1:
cache.remove(key);
break;
case 2:
cache.invoke(key, new TestEntryProcessor(rnd.nextBoolean() ? 1L : null));
break;
case 3:
cache.get(key);
break;
default:
assert false;
}
}
}, 10, "tx-thread");
long stopTime = System.currentTimeMillis() + 3 * 60_000;
long topVer = ignite0.cluster().topologyVersion();
boolean failed = false;
while (System.currentTimeMillis() < stopTime) {
log.info("Start node.");
IgniteKernal ignite = (IgniteKernal) startGrid(GRID_CNT);
assertFalse(ignite.configuration().isClientMode());
topVer++;
IgniteInternalFuture<?> affFut = ignite.context().cache().context().exchange().affinityReadyFuture(new AffinityTopologyVersion(topVer));
try {
if (affFut != null)
affFut.get(30_000);
} catch (IgniteFutureTimeoutCheckedException ignored) {
log.error("Failed to wait for affinity future after start: " + topVer);
failed = true;
break;
}
Thread.sleep(500);
log.info("Stop node.");
stopGrid(GRID_CNT);
topVer++;
affFut = ignite0.context().cache().context().exchange().affinityReadyFuture(new AffinityTopologyVersion(topVer));
try {
if (affFut != null)
affFut.get(30_000);
} catch (IgniteFutureTimeoutCheckedException ignored) {
log.error("Failed to wait for affinity future after stop: " + topVer);
failed = true;
break;
}
}
stop.set(true);
fut.get();
assertFalse("Test failed, see log for details.", failed);
} finally {
stop.set(true);
ignite0.destroyCache(CACHE1);
ignite0.destroyCache(CACHE2);
AffinityTopologyVersion topVer = ignite0.context().cache().context().exchange().lastTopologyFuture().get();
for (Ignite ignite : G.allGrids()) ((IgniteKernal) ignite).context().cache().context().exchange().affinityReadyFuture(topVer).get();
awaitPartitionMapExchange();
}
}
Aggregations