use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class PartitionsExchangeOnDiscoveryHistoryOverflowTest method testDynamicCacheCreation.
/**
* @throws Exception In case of error.
*/
public void testDynamicCacheCreation() throws Exception {
for (int iter = 0; iter < 5; iter++) {
log.info("Iteration: " + iter);
IgniteInternalFuture[] futs = new IgniteInternalFuture[CACHES_COUNT];
for (int i = 0; i < CACHES_COUNT; i++) {
final int cacheIdx = i;
final int gridIdx = cacheIdx % gridCount();
futs[i] = GridTestUtils.runAsync(new Callable<IgniteCache>() {
@Override
public IgniteCache call() throws Exception {
return grid(gridIdx).createCache(cacheConfiguration(gridIdx, cacheIdx));
}
});
}
for (IgniteInternalFuture fut : futs) {
assertNotNull(fut);
fut.get();
}
for (int i = 0; i < CACHES_COUNT; i++) {
final int cacheIdx = i;
final int gridIdx = cacheIdx % gridCount();
futs[i] = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
grid(gridIdx).destroyCache(cacheConfiguration(gridIdx, cacheIdx).getName());
return null;
}
});
}
for (IgniteInternalFuture fut : futs) {
assertNotNull(fut);
fut.get();
}
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridCacheStopSelfTest method testStop.
/**
* @param startTx If {@code true} starts transactions.
* @throws Exception If failed.
*/
private void testStop(final boolean startTx) throws Exception {
for (int i = 0; i < 10; i++) {
startGrid(0);
final int PUT_THREADS = 50;
final CountDownLatch stopLatch = new CountDownLatch(1);
final CountDownLatch readyLatch = new CountDownLatch(PUT_THREADS);
final IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);
assertEquals(atomic ? ATOMIC : TRANSACTIONAL, ccfg.getAtomicityMode());
assertEquals(replicated ? REPLICATED : PARTITIONED, ccfg.getCacheMode());
Collection<IgniteInternalFuture<?>> putFuts = new ArrayList<>();
for (int j = 0; j < PUT_THREADS; j++) {
final int key = j;
putFuts.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
if (startTx) {
TransactionConcurrency concurrency = key % 2 == 0 ? OPTIMISTIC : PESSIMISTIC;
try (Transaction tx = grid(0).transactions().txStart(concurrency, REPEATABLE_READ)) {
cache.put(key, key);
readyLatch.countDown();
stopLatch.await();
tx.commit();
}
} else {
readyLatch.countDown();
stopLatch.await();
cache.put(key, key);
}
} catch (CacheException | IgniteException | IllegalStateException e) {
log.info("Ignore error: " + e);
}
return null;
}
}, "cache-thread"));
}
readyLatch.await();
stopLatch.countDown();
stopGrid(0);
for (IgniteInternalFuture<?> fut : putFuts) fut.get();
try {
cache.put(1, 1);
} catch (IllegalStateException e) {
if (!X.hasCause(e, CacheStoppedException.class)) {
e.printStackTrace();
fail("Unexpected exception: " + e);
}
}
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class IgniteClusterImpl method runNextNodeCallable.
/**
* Runs next callable from host node start queue.
*
* @param queue Queue of tasks to poll from.
* @param comp Compound future that comprise all started node tasks.
* @param cnt Atomic counter to check if all futures are added to compound future.
* @return {@code True} if task was started, {@code false} if queue was empty.
*/
private boolean runNextNodeCallable(final ConcurrentLinkedQueue<StartNodeCallable> queue, final GridCompoundFuture<ClusterStartNodeResult, Collection<ClusterStartNodeResult>> comp, final AtomicInteger cnt) {
StartNodeCallable call = queue.poll();
if (call == null)
return false;
IgniteInternalFuture<ClusterStartNodeResult> fut = ctx.closure().callLocalSafe(call, true);
comp.add(fut);
if (cnt.decrementAndGet() == 0)
comp.markInitialized();
fut.listen(new CI1<IgniteInternalFuture<ClusterStartNodeResult>>() {
@Override
public void apply(IgniteInternalFuture<ClusterStartNodeResult> f) {
runNextNodeCallable(queue, comp, cnt);
}
});
return true;
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridClusterStateProcessor method onStateChangeMessage.
/**
* {@inheritDoc}
*/
@Override
public boolean onStateChangeMessage(AffinityTopologyVersion topVer, ChangeGlobalStateMessage msg, DiscoCache discoCache) {
DiscoveryDataClusterState state = globalState;
if (log.isInfoEnabled())
U.log(log, "Received " + prettyStr(msg.activate()) + " request with BaselineTopology" + (msg.baselineTopology() == null ? ": null" : "[id=" + msg.baselineTopology().id() + "]"));
if (msg.baselineTopology() != null)
compatibilityMode = false;
if (state.transition()) {
if (isApplicable(msg, state)) {
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.onDone(concurrentStateChangeError(msg.activate()));
} else {
final GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
GridFutureAdapter<Void> transitionFut = transitionFuts.get(state.transitionRequestId());
if (stateFut != null && transitionFut != null) {
transitionFut.listen(new IgniteInClosure<IgniteInternalFuture<Void>>() {
@Override
public void apply(IgniteInternalFuture<Void> fut) {
try {
fut.get();
stateFut.onDone();
} catch (Exception ex) {
stateFut.onDone(ex);
}
}
});
}
}
} else {
if (isApplicable(msg, state)) {
ExchangeActions exchangeActions;
try {
exchangeActions = ctx.cache().onStateChangeRequest(msg, topVer, state);
} catch (IgniteCheckedException e) {
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.onDone(e);
return false;
}
Set<UUID> nodeIds = U.newHashSet(discoCache.allNodes().size());
for (ClusterNode node : discoCache.allNodes()) nodeIds.add(node.id());
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.setRemaining(nodeIds, topVer.nextMinorVersion());
if (log.isInfoEnabled())
log.info("Started state transition: " + msg.activate());
BaselineTopologyHistoryItem bltHistItem = BaselineTopologyHistoryItem.fromBaseline(globalState.baselineTopology());
transitionFuts.put(msg.requestId(), new GridFutureAdapter<Void>());
globalState = DiscoveryDataClusterState.createTransitionState(globalState, msg.activate(), msg.activate() ? msg.baselineTopology() : globalState.baselineTopology(), msg.requestId(), topVer, nodeIds);
if (msg.forceChangeBaselineTopology())
globalState.setTransitionResult(msg.requestId(), msg.activate());
AffinityTopologyVersion stateChangeTopVer = topVer.nextMinorVersion();
StateChangeRequest req = new StateChangeRequest(msg, bltHistItem, msg.activate() != state.active(), stateChangeTopVer);
exchangeActions.stateChangeRequest(req);
msg.exchangeActions(exchangeActions);
return true;
} else {
// State already changed.
GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
if (stateFut != null)
stateFut.onDone();
}
}
return false;
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridClusterStateProcessor method processChangeGlobalStateResponse.
/**
* @param nodeId Node ID.
* @param msg Message.
*/
private void processChangeGlobalStateResponse(final UUID nodeId, final GridChangeGlobalStateMessageResponse msg) {
assert nodeId != null;
assert msg != null;
if (log.isDebugEnabled()) {
log.debug("Received activation response [requestId=" + msg.getRequestId() + ", nodeId=" + nodeId + "]");
}
UUID requestId = msg.getRequestId();
final GridChangeGlobalStateFuture fut = stateChangeFut.get();
if (fut != null && requestId.equals(fut.requestId)) {
if (fut.initFut.isDone())
fut.onResponse(nodeId, msg);
else {
fut.initFut.listen(new CI1<IgniteInternalFuture<?>>() {
@Override
public void apply(IgniteInternalFuture<?> f) {
// initFut is completed from discovery thread, process response from other thread.
ctx.getSystemExecutorService().execute(new Runnable() {
@Override
public void run() {
fut.onResponse(nodeId, msg);
}
});
}
});
}
}
}
Aggregations