use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class DataStreamerImpl method waitAffinityAndRun.
/**
* @param c Closure to run.
* @param topVer Topology version to wait for.
* @param async Async flag.
*/
private void waitAffinityAndRun(final Runnable c, long topVer, boolean async) {
AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer, 0);
IgniteInternalFuture<?> fut = ctx.cache().context().exchange().affinityReadyFuture(topVer0);
if (fut != null && !fut.isDone()) {
fut.listen(new CI1<IgniteInternalFuture<?>>() {
@Override
public void apply(IgniteInternalFuture<?> fut) {
ctx.closure().runLocalSafe(c, true);
}
});
} else {
if (async)
ctx.closure().runLocalSafe(c, true);
else
c.run();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridNearOptimisticTxPrepareFuture method proceedPrepare.
/**
* Continues prepare after previous mapping successfully finished.
*
* @param m Mapping.
* @param mappings Queue of mappings.
*/
private void proceedPrepare(GridDistributedTxMapping m, @Nullable final Queue<GridDistributedTxMapping> mappings) {
if (isDone())
return;
boolean set = cctx.tm().setTxTopologyHint(tx.topologyVersionSnapshot());
try {
assert !m.empty();
final ClusterNode n = m.primary();
long timeout = tx.remainingTime();
if (timeout != -1) {
GridNearTxPrepareRequest req = new GridNearTxPrepareRequest(futId, tx.topologyVersion(), tx, timeout, null, m.writes(), m.hasNearCacheEntries(), txMapping.transactionNodes(), m.last(), tx.onePhaseCommit(), tx.needReturnValue() && tx.implicit(), tx.implicitSingle(), m.explicitLock(), tx.subjectId(), tx.taskNameHash(), m.clientFirst(), true, tx.activeCachesDeploymentEnabled());
for (IgniteTxEntry txEntry : m.entries()) {
if (txEntry.op() == TRANSFORM)
req.addDhtVersion(txEntry.txKey(), null);
}
// Must lock near entries separately.
if (m.hasNearCacheEntries()) {
try {
cctx.tm().prepareTx(tx, m.nearCacheEntries());
} catch (IgniteCheckedException e) {
onError(e, false);
return;
}
}
final MiniFuture fut = new MiniFuture(this, m, ++miniId, mappings);
req.miniId(fut.futureId());
// Append new future.
add(fut);
if (n.isLocal()) {
assert !(m.hasColocatedCacheEntries() && m.hasNearCacheEntries()) : m;
IgniteInternalFuture<GridNearTxPrepareResponse> prepFut = m.hasNearCacheEntries() ? cctx.tm().txHandler().prepareNearTxLocal(req) : cctx.tm().txHandler().prepareColocatedTx(tx, req);
prepFut.listen(new CI1<IgniteInternalFuture<GridNearTxPrepareResponse>>() {
@Override
public void apply(IgniteInternalFuture<GridNearTxPrepareResponse> prepFut) {
try {
fut.onResult(prepFut.get());
} catch (IgniteCheckedException e) {
fut.onResult(e);
}
}
});
} else {
try {
cctx.io().send(n, req, tx.ioPolicy());
if (msgLog.isDebugEnabled()) {
msgLog.debug("Near optimistic prepare fut, sent request [txId=" + tx.nearXidVersion() + ", node=" + n.id() + ']');
}
} catch (ClusterTopologyCheckedException e) {
e.retryReadyFuture(cctx.nextAffinityReadyFuture(tx.topologyVersion()));
fut.onNodeLeft(e, false);
} catch (IgniteCheckedException e) {
if (msgLog.isDebugEnabled()) {
msgLog.debug("Near optimistic prepare fut, failed to sent request [txId=" + tx.nearXidVersion() + ", node=" + n.id() + ", err=" + e + ']');
}
fut.onResult(e);
}
}
} else
onTimeout();
} finally {
if (set)
cctx.tm().setTxTopologyHint(null);
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheExchangeMergeTest method mergeServersAndClientsFail.
/**
* @param waitRebalance Wait for rebalance end before start tested topology change.
* @throws Exception If failed.
*/
private void mergeServersAndClientsFail(boolean waitRebalance) throws Exception {
clientC = new IgniteClosure<String, Boolean>() {
@Override
public Boolean apply(String nodeName) {
return nodeName.equals(getTestIgniteInstanceName(2)) || nodeName.equals(getTestIgniteInstanceName(3));
}
};
final Ignite srv0 = startGrids(6);
if (waitRebalance)
awaitPartitionMapExchange();
mergeExchangeWaitVersion(srv0, 10);
stopGrid(getTestIgniteInstanceName(1), true, false);
stopGrid(getTestIgniteInstanceName(2), true, false);
stopGrid(getTestIgniteInstanceName(3), true, false);
stopGrid(getTestIgniteInstanceName(4), true, false);
checkAffinity();
mergeExchangeWaitVersion(srv0, 12);
IgniteInternalFuture fut = startGridsAsync(srv0, 6, 2);
fut.get();
checkCaches();
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheGetFutureHangsSelfTest method doTestFailover.
/**
* Executes one test iteration.
*
* @throws Exception If failed.
*/
private void doTestFailover() throws Exception {
try {
done = false;
nodes = new AtomicReferenceArray<>(GRID_CNT);
startGridsMultiThreaded(GRID_CNT, false);
for (int i = 0; i < GRID_CNT; i++) assertTrue(nodes.compareAndSet(i, null, ignite(i)));
List<IgniteInternalFuture> futs = new ArrayList<>();
for (int i = 0; i < GRID_CNT + 1; i++) {
futs.add(multithreadedAsync(new Runnable() {
@Override
public void run() {
T2<Ignite, Integer> ignite;
Set<Integer> keys = F.asSet(1, 2, 3, 4, 5);
while ((ignite = randomNode()) != null) {
IgniteCache<Object, Object> cache = ignite.get1().cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) cache.containsKey(ThreadLocalRandom.current().nextInt(100_000));
cache.containsKeys(keys);
assertTrue(nodes.compareAndSet(ignite.get2(), null, ignite.get1()));
try {
Thread.sleep(ThreadLocalRandom.current().nextLong(50));
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}
}
}, 1, "containsKey-thread-" + i));
futs.add(multithreadedAsync(new Runnable() {
@Override
public void run() {
T2<Ignite, Integer> ignite;
while ((ignite = randomNode()) != null) {
IgniteCache<Object, Object> cache = ignite.get1().cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) cache.put(ThreadLocalRandom.current().nextInt(100_000), UUID.randomUUID());
assertTrue(nodes.compareAndSet(ignite.get2(), null, ignite.get1()));
try {
Thread.sleep(ThreadLocalRandom.current().nextLong(50));
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}
}
}, 1, "put-thread-" + i));
}
try {
int aliveGrids = GRID_CNT;
while (aliveGrids > 0) {
T2<Ignite, Integer> ignite = randomNode();
assert ignite != null;
Ignite ignite0 = ignite.get1();
log.info("Stop node: " + ignite0.name());
ignite0.close();
log.info("Node stop finished: " + ignite0.name());
aliveGrids--;
}
} finally {
done = true;
}
for (IgniteInternalFuture fut : futs) fut.get();
} finally {
done = true;
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridFutureListenPerformanceTest method main.
/**
* @param args Args.
* @throws InterruptedException If failed.
*/
public static void main(String[] args) throws InterruptedException {
final LongAdder cnt = new LongAdder();
final ConcurrentLinkedDeque<GridFutureAdapter<Object>> futs = new ConcurrentLinkedDeque<>();
ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
Thread statThread = new Thread() {
@SuppressWarnings("BusyWait")
@Override
public void run() {
while (!done) {
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
return;
}
System.out.println(new Date() + " Notifications per sec: " + (cnt.sumThenReset() / 5));
}
}
};
statThread.setDaemon(true);
statThread.start();
for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
pool.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
Random rnd = new Random();
while (!done) {
for (int j = 0; j < rnd.nextInt(10); j++) {
GridFutureAdapter<Object> fut = new GridFutureAdapter<>();
futs.add(fut);
for (int k = 1; k < rnd.nextInt(3); k++) {
fut.listen(new IgniteInClosure<IgniteInternalFuture<Object>>() {
@Override
public void apply(IgniteInternalFuture<Object> t) {
try {
t.get();
} catch (IgniteCheckedException e) {
e.printStackTrace();
}
cnt.increment();
}
});
}
}
GridFutureAdapter<Object> fut;
while ((fut = futs.poll()) != null) fut.onDone();
}
return null;
}
});
}
Thread.sleep(5 * 60 * 1000);
done = true;
pool.shutdownNow();
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
Aggregations