Search in sources :

Example 1 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class GridDhtAtomicCache method start.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "IfMayBeConditional", "SimplifiableIfStatement" })
@Override
public void start() throws IgniteCheckedException {
    super.start();
    CacheMetricsImpl m = new CacheMetricsImpl(ctx);
    if (ctx.dht().near() != null)
        m.delegate(ctx.dht().near().metrics0());
    metrics = m;
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetRequest.class, new CI2<UUID, GridNearGetRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearGetRequest req) {
            processNearGetRequest(nodeId, req);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetRequest.class, new CI2<UUID, GridNearSingleGetRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearSingleGetRequest req) {
            processNearSingleGetRequest(nodeId, req);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicAbstractUpdateRequest.class, new CI2<UUID, GridNearAtomicAbstractUpdateRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearAtomicAbstractUpdateRequest req) {
            processNearAtomicUpdateRequest(nodeId, req);
        }

        @Override
        public String toString() {
            return "GridNearAtomicAbstractUpdateRequest handler " + "[msgIdx=" + GridNearAtomicAbstractUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicUpdateResponse.class, new CI2<UUID, GridNearAtomicUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridNearAtomicUpdateResponse res) {
            processNearAtomicUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridNearAtomicUpdateResponse handler " + "[msgIdx=" + GridNearAtomicUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicAbstractUpdateRequest.class, new CI2<UUID, GridDhtAtomicAbstractUpdateRequest>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicAbstractUpdateRequest req) {
            processDhtAtomicUpdateRequest(nodeId, req);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicUpdateRequest handler " + "[msgIdx=" + GridDhtAtomicUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicUpdateResponse.class, new CI2<UUID, GridDhtAtomicUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicUpdateResponse res) {
            processDhtAtomicUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicUpdateResponse handler " + "[msgIdx=" + GridDhtAtomicUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicDeferredUpdateResponse.class, new CI2<UUID, GridDhtAtomicDeferredUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicDeferredUpdateResponse res) {
            processDhtAtomicDeferredUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicDeferredUpdateResponse handler " + "[msgIdx=" + GridDhtAtomicDeferredUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicNearResponse.class, new CI2<UUID, GridDhtAtomicNearResponse>() {

        @Override
        public void apply(UUID uuid, GridDhtAtomicNearResponse msg) {
            processDhtAtomicNearResponse(uuid, msg);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicNearResponse handler " + "[msgIdx=" + GridDhtAtomicNearResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicCheckUpdateRequest.class, new CI2<UUID, GridNearAtomicCheckUpdateRequest>() {

        @Override
        public void apply(UUID uuid, GridNearAtomicCheckUpdateRequest msg) {
            processCheckUpdateRequest(uuid, msg);
        }

        @Override
        public String toString() {
            return "GridNearAtomicCheckUpdateRequest handler " + "[msgIdx=" + GridNearAtomicCheckUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysRequest.class, new MessageHandler<GridDhtForceKeysRequest>() {

        @Override
        public void onMessage(ClusterNode node, GridDhtForceKeysRequest msg) {
            processForceKeysRequest(node, msg);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysResponse.class, new MessageHandler<GridDhtForceKeysResponse>() {

        @Override
        public void onMessage(ClusterNode node, GridDhtForceKeysResponse msg) {
            processForceKeyResponse(node, msg);
        }
    });
    if (near == null) {
        ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2<UUID, GridNearGetResponse>() {

            @Override
            public void apply(UUID nodeId, GridNearGetResponse res) {
                processNearGetResponse(nodeId, res);
            }
        });
        ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetResponse.class, new CI2<UUID, GridNearSingleGetResponse>() {

            @Override
            public void apply(UUID nodeId, GridNearSingleGetResponse res) {
                processNearSingleGetResponse(nodeId, res);
            }
        });
    }
}
Also used : GridDhtForceKeysResponse(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) GridDhtForceKeysRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest) UUID(java.util.UUID) GridNearGetResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetResponse) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridNearSingleGetResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse) GridNearSingleGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest)

Example 2 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class GridDhtPartitionDemander method addAssignments.

/**
 * Initiates new rebalance process from given {@code assignments}.
 * If previous rebalance is not finished method cancels it.
 * In case of delayed rebalance method schedules new with configured delay.
 *
 * @param assignments Assignments.
 * @param force {@code True} if dummy reassign.
 * @param rebalanceId Rebalance id.
 * @param next Runnable responsible for cache rebalancing start.
 * @param forcedRebFut External future for forced rebalance.
 * @return Rebalancing runnable.
 */
Runnable addAssignments(final GridDhtPreloaderAssignments assignments, boolean force, long rebalanceId, final Runnable next, @Nullable final GridCompoundFuture<Boolean, Boolean> forcedRebFut) {
    if (log.isDebugEnabled())
        log.debug("Adding partition assignments: " + assignments);
    assert force == (forcedRebFut != null);
    long delay = grp.config().getRebalanceDelay();
    if ((delay == 0 || force) && assignments != null) {
        final RebalanceFuture oldFut = rebalanceFut;
        final RebalanceFuture fut = new RebalanceFuture(grp, assignments, log, rebalanceId);
        if (!oldFut.isInitial())
            oldFut.cancel();
        else
            fut.listen(f -> oldFut.onDone(f.result()));
        if (forcedRebFut != null)
            forcedRebFut.add(fut);
        rebalanceFut = fut;
        for (final GridCacheContext cctx : grp.caches()) {
            if (cctx.statisticsEnabled()) {
                final CacheMetricsImpl metrics = cctx.cache().metrics0();
                metrics.clearRebalanceCounters();
                metrics.startRebalance(0);
                rebalanceFut.listen(f -> metrics.clearRebalanceCounters());
            }
        }
        fut.sendRebalanceStartedEvent();
        if (assignments.cancelled()) {
            // Pending exchange.
            if (log.isDebugEnabled())
                log.debug("Rebalancing skipped due to cancelled assignments.");
            fut.onDone(false);
            fut.sendRebalanceFinishedEvent();
            return null;
        }
        if (assignments.isEmpty()) {
            // Nothing to rebalance.
            if (log.isDebugEnabled())
                log.debug("Rebalancing skipped due to empty assignments.");
            fut.onDone(true);
            ((GridFutureAdapter) grp.preloader().syncFuture()).onDone();
            fut.sendRebalanceFinishedEvent();
            return null;
        }
        return () -> {
            if (next != null)
                fut.listen(f -> {
                    try {
                        if (// Not cancelled.
                        f.get())
                            // Starts next cache rebalancing (according to the order).
                            next.run();
                    } catch (IgniteCheckedException e) {
                        if (log.isDebugEnabled())
                            log.debug(e.getMessage());
                    }
                });
            requestPartitions(fut, assignments);
        };
    } else if (delay > 0) {
        for (GridCacheContext cctx : grp.caches()) {
            if (cctx.statisticsEnabled()) {
                final CacheMetricsImpl metrics = cctx.cache().metrics0();
                metrics.startRebalance(delay);
            }
        }
        GridTimeoutObject obj = lastTimeoutObj.get();
        if (obj != null)
            ctx.time().removeTimeoutObject(obj);
        final GridDhtPartitionsExchangeFuture exchFut = lastExchangeFut;
        assert exchFut != null : "Delaying rebalance process without topology event.";
        obj = new GridTimeoutObjectAdapter(delay) {

            @Override
            public void onTimeout() {
                exchFut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

                    @Override
                    public void apply(IgniteInternalFuture<AffinityTopologyVersion> f) {
                        ctx.exchange().forceRebalance(exchFut.exchangeId());
                    }
                });
            }
        };
        lastTimeoutObj.set(obj);
        ctx.time().addTimeoutObject(obj);
    }
    return null;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) EVT_CACHE_REBALANCE_STARTED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STARTED) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) EVT_CACHE_REBALANCE_STOPPED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STOPPED) EVT_CACHE_REBALANCE_PART_LOADED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_LOADED) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DR_PRELOAD(org.apache.ignite.internal.processors.dr.GridDrType.DR_PRELOAD) Set(java.util.Set) UUID(java.util.UUID) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) EVT_CACHE_REBALANCE_OBJECT_LOADED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_OBJECT_LOADED) GridCachePartitionExchangeManager(org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager) MOVING(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING) DR_NONE(org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) AtomicReference(java.util.concurrent.atomic.AtomicReference) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) LT(org.apache.ignite.internal.util.typedef.internal.LT) ArrayList(java.util.ArrayList) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) Iterator(java.util.Iterator) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridToStringInclude(org.apache.ignite.internal.util.tostring.GridToStringInclude) T2(org.apache.ignite.internal.util.typedef.T2) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Example 3 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class GridDhtPartitionDemander method awaitClearingAndStartRebalance.

/**
 * Awaits partitions clearing for full partitions and sends initial demand request
 * after all partitions are cleared and safe to consume data.
 *
 * @param fut Rebalance future.
 * @param demandMessage Initial demand message which contains set of full partitions to await.
 * @param initDemandRequestTask Task which sends initial demand request.
 */
private void awaitClearingAndStartRebalance(RebalanceFuture fut, GridDhtPartitionDemandMessage demandMessage, Runnable initDemandRequestTask) {
    Set<Integer> fullPartitions = demandMessage.partitions().fullSet();
    if (fullPartitions.isEmpty()) {
        ctx.kernalContext().closure().runLocalSafe(initDemandRequestTask, true);
        return;
    }
    for (GridCacheContext cctx : grp.caches()) {
        if (cctx.statisticsEnabled()) {
            final CacheMetricsImpl metrics = cctx.cache().metrics0();
            metrics.rebalanceClearingPartitions(fullPartitions.size());
        }
    }
    final AtomicInteger clearingPartitions = new AtomicInteger(fullPartitions.size());
    for (int partId : fullPartitions) {
        if (fut.isDone())
            return;
        GridDhtLocalPartition part = grp.topology().localPartition(partId);
        if (part != null && part.state() == MOVING) {
            part.onClearFinished(f -> {
                // Cancel rebalance if partition clearing was failed.
                if (f.error() != null) {
                    if (!fut.isDone()) {
                        for (GridCacheContext cctx : grp.caches()) {
                            if (cctx.statisticsEnabled()) {
                                final CacheMetricsImpl metrics = cctx.cache().metrics0();
                                metrics.rebalanceClearingPartitions(0);
                            }
                        }
                        log.error("Unable to await partition clearing " + part, f.error());
                        fut.cancel();
                    }
                } else {
                    if (!fut.isDone()) {
                        int existed = clearingPartitions.decrementAndGet();
                        for (GridCacheContext cctx : grp.caches()) {
                            if (cctx.statisticsEnabled()) {
                                final CacheMetricsImpl metrics = cctx.cache().metrics0();
                                metrics.rebalanceClearingPartitions(existed);
                            }
                        }
                        // If all partitions are cleared send initial demand message.
                        if (existed == 0)
                            ctx.kernalContext().closure().runLocalSafe(initDemandRequestTask, true);
                    }
                }
            });
        } else
            clearingPartitions.decrementAndGet();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)

Example 4 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class StopRebuildIndexTest method stopRebuildIndexes.

/**
 * Restart the rebuild of the indexes, checking that it completes gracefully.
 *
 * @param stopRebuildIndexes Stop index rebuild function.
 * @param expThrowEx Expect an exception on index rebuild futures.
 * @throws Exception If failed.
 */
private void stopRebuildIndexes(IgniteThrowableConsumer<IgniteEx> stopRebuildIndexes, boolean expThrowEx) throws Exception {
    prepareBeforeNodeStart();
    int keys = 100_000;
    IgniteEx n = startGrid(0);
    populate(n.cache(DEFAULT_CACHE_NAME), keys);
    GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
    addCacheRowConsumer(nodeName(n), cacheCtx.name(), row -> U.sleep(10));
    forceRebuildIndexes(n, cacheCtx);
    IgniteInternalFuture<?> fut0 = indexRebuildFuture(n, cacheCtx.cacheId());
    assertNotNull(fut0);
    SchemaIndexCacheFuture fut1 = internalIndexRebuildFuture(n, cacheCtx.cacheId());
    assertNotNull(fut1);
    CacheMetricsImpl metrics0 = cacheMetrics0(n, cacheCtx.name());
    assertTrue(metrics0.isIndexRebuildInProgress());
    assertFalse(fut0.isDone());
    assertFalse(fut1.isDone());
    assertNull(fut1.cancelToken().cancelException());
    assertTrue(waitForCondition(() -> metrics0.getIndexRebuildKeysProcessed() >= keys / 100, getTestTimeout()));
    assertTrue(metrics0.isIndexRebuildInProgress());
    assertFalse(fut0.isDone());
    assertFalse(fut1.isDone());
    assertNull(fut1.cancelToken().cancelException());
    stopRebuildIndexes.accept(n);
    assertFalse(metrics0.isIndexRebuildInProgress());
    assertTrue(metrics0.getIndexRebuildKeysProcessed() < keys);
    if (expThrowEx) {
        assertThrows(log, () -> fut0.get(getTestTimeout()), SchemaIndexOperationCancellationException.class, null);
        assertThrows(log, () -> fut1.get(getTestTimeout()), SchemaIndexOperationCancellationException.class, null);
        assertNotNull(fut1.cancelToken().cancelException());
    } else {
        fut0.get(getTestTimeout());
        fut1.get(getTestTimeout());
        assertNull(fut1.cancelToken().cancelException());
    }
    assertNull(internalIndexRebuildFuture(n, cacheCtx.cacheId()));
}
Also used : CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) SchemaIndexCacheFuture(org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFuture)

Example 5 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class GridDhtPartitionDemander method addAssignments.

/**
 * This method initiates new rebalance process from given {@code assignments} by creating new rebalance
 * future based on them. Cancels previous rebalance future and sends rebalance started event.
 * In case of delayed rebalance method schedules the new one with configured delay based on {@code lastExchangeFut}.
 *
 * @param assignments Assignments to process.
 * @param force {@code True} if preload request by {@link ForceRebalanceExchangeTask}.
 * @param rebalanceId Rebalance id generated from exchange thread.
 * @param next A next rebalance routine in chain.
 * @param forcedRebFut External future for forced rebalance.
 * @param compatibleRebFut Future for waiting for compatible rebalances.
 *
 * @return Rebalancing future or {@code null} to exclude an assignment from a chain.
 */
@Nullable
RebalanceFuture addAssignments(final GridDhtPreloaderAssignments assignments, boolean force, long rebalanceId, final RebalanceFuture next, @Nullable final GridCompoundFuture<Boolean, Boolean> forcedRebFut, GridCompoundFuture<Boolean, Boolean> compatibleRebFut) {
    if (log.isDebugEnabled())
        log.debug("Adding partition assignments: " + assignments);
    assert force == (forcedRebFut != null);
    long delay = grp.config().getRebalanceDelay();
    if (delay == 0 || force) {
        assert assignments != null;
        final RebalanceFuture oldFut = rebalanceFut;
        if (assignments.cancelled()) {
            // Pending exchange.
            if (log.isDebugEnabled())
                log.debug("Rebalancing skipped due to cancelled assignments.");
            return null;
        }
        if (assignments.isEmpty()) {
            // Nothing to rebalance.
            if (log.isDebugEnabled())
                log.debug("Rebalancing skipped due to empty assignments.");
            if (oldFut.isInitial())
                oldFut.onDone(true);
            else if (!oldFut.isDone())
                oldFut.tryCancel();
            ((GridFutureAdapter) grp.preloader().syncFuture()).onDone();
            return null;
        }
        // Check if ongoing rebalancing is compatible with a new assignment.
        if (!force && (!oldFut.isDone() || oldFut.result()) && oldFut.compatibleWith(assignments)) {
            if (!oldFut.isDone())
                compatibleRebFut.add(oldFut);
            return null;
        }
        // Cancel ongoing rebalancing.
        if (!oldFut.isDone() && !oldFut.isInitial())
            oldFut.tryCancel();
        // Partition states cannot be changed from now on by previous incompatible rebalancing.
        // Retain only moving partitions. Assignment can become empty as a result.
        // Delayed partition owning happens in the exchange worker as well, so no race with delayed owning here.
        assignments.retainMoving(grp.topology());
        // Skip rebalanced group.
        if (assignments.isEmpty())
            return null;
        final RebalanceFuture fut = new RebalanceFuture(grp, lastExchangeFut, assignments, log, rebalanceId, next, lastCancelledTime);
        if (oldFut.isInitial())
            fut.listen(f -> oldFut.onDone(f.result()));
        if (forcedRebFut != null)
            forcedRebFut.add(fut);
        rebalanceFut = fut;
        for (final GridCacheContext cctx : grp.caches()) {
            if (cctx.statisticsEnabled()) {
                final CacheMetricsImpl metrics = cctx.cache().metrics0();
                metrics.clearRebalanceCounters();
                for (GridDhtPartitionDemandMessage msg : assignments.values()) {
                    for (Integer partId : msg.partitions().fullSet()) metrics.onRebalancingKeysCountEstimateReceived(grp.topology().globalPartSizes().get(partId));
                    CachePartitionPartialCountersMap histMap = msg.partitions().historicalMap();
                    for (int i = 0; i < histMap.size(); i++) {
                        long from = histMap.initialUpdateCounterAt(i);
                        long to = histMap.updateCounterAt(i);
                        metrics.onRebalancingKeysCountEstimateReceived(to - from);
                    }
                }
                metrics.startRebalance(0);
            }
        }
        fut.sendRebalanceStartedEvent();
        return fut;
    } else if (delay > 0) {
        for (GridCacheContext cctx : grp.caches()) {
            if (cctx.statisticsEnabled()) {
                final CacheMetricsImpl metrics = cctx.cache().metrics0();
                metrics.startRebalance(delay);
            }
        }
        GridTimeoutObject obj = lastTimeoutObj.get();
        if (obj != null)
            ctx.time().removeTimeoutObject(obj);
        final GridDhtPartitionsExchangeFuture exchFut = lastExchangeFut;
        assert exchFut != null : "Delaying rebalance process without topology event.";
        obj = new GridTimeoutObjectAdapter(delay) {

            @Override
            public void onTimeout() {
                exchFut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

                    @Override
                    public void apply(IgniteInternalFuture<AffinityTopologyVersion> f) {
                        ctx.exchange().forceRebalance(exchFut.exchangeId());
                    }
                });
            }
        };
        lastTimeoutObj.set(obj);
        ctx.time().addTimeoutObject(obj);
    }
    return null;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) Collectors.counting(java.util.stream.Collectors.counting) IteratorWrapper(org.apache.ignite.internal.util.lang.GridIterableAdapter.IteratorWrapper) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) EVT_CACHE_REBALANCE_STARTED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STARTED) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) EVT_CACHE_REBALANCE_STOPPED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STOPPED) EVT_CACHE_REBALANCE_PART_LOADED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_LOADED) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) Collectors.toSet(java.util.stream.Collectors.toSet) CACHE_GROUP_METRICS_PREFIX(org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) AtomicReferenceFieldUpdater(java.util.concurrent.atomic.AtomicReferenceFieldUpdater) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DR_PRELOAD(org.apache.ignite.internal.processors.dr.GridDrType.DR_PRELOAD) Set(java.util.Set) NavigableSet(java.util.NavigableSet) UUID(java.util.UUID) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) Objects.nonNull(java.util.Objects.nonNull) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) EVT_CACHE_REBALANCE_OBJECT_LOADED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_OBJECT_LOADED) GridCachePartitionExchangeManager(org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager) LongAdder(java.util.concurrent.atomic.LongAdder) DR_NONE(org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Collectors.partitioningBy(java.util.stream.Collectors.partitioningBy) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgnitePredicateX(org.apache.ignite.internal.util.lang.IgnitePredicateX) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) AtomicReference(java.util.concurrent.atomic.AtomicReference) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) LT(org.apache.ignite.internal.util.typedef.internal.LT) ArrayList(java.util.ArrayList) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter) S(org.apache.ignite.internal.util.typedef.internal.S) MOVING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.MOVING) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) PAGE_SNAPSHOT_TAKEN(org.apache.ignite.internal.processors.cache.persistence.CheckpointState.PAGE_SNAPSHOT_TAKEN) FINISHED(org.apache.ignite.internal.processors.cache.persistence.CheckpointState.FINISHED) F(org.apache.ignite.internal.util.typedef.F) GridIterableAdapter(org.apache.ignite.internal.util.lang.GridIterableAdapter) Iterator(java.util.Iterator) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) TTL_ETERNAL(org.apache.ignite.internal.processors.cache.GridCacheUtils.TTL_ETERNAL) GridMutableLong(org.apache.ignite.internal.util.GridMutableLong) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) GridToStringInclude(org.apache.ignite.internal.util.tostring.GridToStringInclude) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) WalStateManager(org.apache.ignite.internal.processors.cache.WalStateManager) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) GridCacheMvccEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo) Collections(java.util.Collections) TxState(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxState) PRELOAD_SIZE_UNDER_CHECKPOINT_LOCK(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl.PRELOAD_SIZE_UNDER_CHECKPOINT_LOCK) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CacheMetricsImpl (org.apache.ignite.internal.processors.cache.CacheMetricsImpl)12 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)4 UUID (java.util.UUID)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2