Search in sources :

Example 46 with IgniteInternalFuture

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();
        }
    }
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable)

Example 47 with IgniteInternalFuture

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);
            }
        }
    }
}
Also used : CacheException(javax.cache.CacheException) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 48 with IgniteInternalFuture

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;
}
Also used : ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) StartNodeCallable(org.apache.ignite.internal.util.nodestart.StartNodeCallable)

Example 49 with IgniteInternalFuture

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) StateChangeRequest(org.apache.ignite.internal.processors.cache.StateChangeRequest) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID)

Example 50 with IgniteInternalFuture

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);
                        }
                    });
                }
            });
        }
    }
}
Also used : IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) UUID(java.util.UUID) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Aggregations

IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)245 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)114 Ignite (org.apache.ignite.Ignite)71 ArrayList (java.util.ArrayList)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)46 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)46 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)43 IgniteException (org.apache.ignite.IgniteException)33 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)29 UUID (java.util.UUID)28 IgniteCache (org.apache.ignite.IgniteCache)28 ClusterNode (org.apache.ignite.cluster.ClusterNode)28 Callable (java.util.concurrent.Callable)27 HashMap (java.util.HashMap)25 Map (java.util.Map)25 CountDownLatch (java.util.concurrent.CountDownLatch)24 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)19 CacheException (javax.cache.CacheException)16 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)16 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)16