Search in sources :

Example 1 with GridCompoundIdentityFuture

use of org.apache.ignite.internal.util.future.GridCompoundIdentityFuture in project ignite by apache.

the class CacheMvccAbstractTest method runVacuumSync.

/**
 * Runs vacuum on all nodes and waits for its completion.
 *
 * @throws IgniteCheckedException If failed.
 */
private void runVacuumSync() throws IgniteCheckedException {
    GridCompoundIdentityFuture<VacuumMetrics> fut = new GridCompoundIdentityFuture<>();
    // Run vacuum manually.
    for (Ignite node : G.allGrids()) {
        if (!node.configuration().isClientMode()) {
            MvccProcessorImpl crd = mvccProcessor(node);
            if (!crd.mvccEnabled() || GridTestUtils.getFieldValue(crd, "vacuumWorkers") == null)
                continue;
            assert GridTestUtils.getFieldValue(crd, "txLog") != null;
            fut.add(crd.runVacuum());
        }
    }
    fut.markInitialized();
    // Wait vacuum finished.
    fut.get(getTestTimeout());
}
Also used : Ignite(org.apache.ignite.Ignite) GridCompoundIdentityFuture(org.apache.ignite.internal.util.future.GridCompoundIdentityFuture)

Example 2 with GridCompoundIdentityFuture

use of org.apache.ignite.internal.util.future.GridCompoundIdentityFuture in project ignite by apache.

the class MvccProcessorImpl method continueRunVacuum.

/**
 * @param res Result.
 * @param snapshot Snapshot.
 */
private void continueRunVacuum(GridFutureAdapter<VacuumMetrics> res, MvccSnapshot snapshot) {
    ackTxCommit(snapshot).listen(new IgniteInClosure<IgniteInternalFuture>() {

        @Override
        public void apply(IgniteInternalFuture fut) {
            Throwable err;
            if ((err = fut.error()) != null) {
                U.error(log, "Vacuum error.", err);
                res.onDone(err);
            } else if (snapshot.cleanupVersion() <= MVCC_COUNTER_NA)
                res.onDone(new VacuumMetrics());
            else {
                try {
                    if (log.isDebugEnabled())
                        log.debug("Started vacuum with cleanup version=" + snapshot.cleanupVersion() + '.');
                    synchronized (mux) {
                        if (cleanupQueue == null) {
                            res.onDone(vacuumCancelledException());
                            return;
                        }
                        GridCompoundIdentityFuture<VacuumMetrics> res0 = new GridCompoundIdentityFuture<VacuumMetrics>(new VacuumMetricsReducer()) {

                            /**
                             * {@inheritDoc}
                             */
                            @Override
                            protected void logError(IgniteLogger log, String msg, Throwable e) {
                            // no-op
                            }

                            /**
                             * {@inheritDoc}
                             */
                            @Override
                            protected void logDebug(IgniteLogger log, String msg) {
                            // no-op
                            }
                        };
                        for (CacheGroupContext grp : ctx.cache().cacheGroups()) {
                            if (grp.mvccEnabled()) {
                                grp.topology().readLock();
                                try {
                                    for (GridDhtLocalPartition part : grp.topology().localPartitions()) {
                                        VacuumTask task = new VacuumTask(snapshot, part);
                                        cleanupQueue.offer(task);
                                        res0.add(task);
                                    }
                                } finally {
                                    grp.topology().readUnlock();
                                }
                            }
                        }
                        res0.markInitialized();
                        res0.listen(future -> {
                            VacuumMetrics metrics = null;
                            Throwable ex = null;
                            try {
                                metrics = future.get();
                                txLog.removeUntil(snapshot.coordinatorVersion(), snapshot.cleanupVersion());
                                if (log.isDebugEnabled())
                                    log.debug("Vacuum completed. " + metrics);
                            } catch (Throwable e) {
                                if (X.hasCause(e, NodeStoppingException.class)) {
                                    if (log.isDebugEnabled())
                                        log.debug("Cannot complete vacuum (node is stopping).");
                                    metrics = new VacuumMetrics();
                                } else
                                    ex = new GridClosureException(e);
                            }
                            res.onDone(metrics, ex);
                        });
                    }
                } catch (Throwable e) {
                    completeWithException(res, e);
                }
            }
        }
    });
}
Also used : GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) IgniteLogger(org.apache.ignite.IgniteLogger) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridCompoundIdentityFuture(org.apache.ignite.internal.util.future.GridCompoundIdentityFuture)

Aggregations

GridCompoundIdentityFuture (org.apache.ignite.internal.util.future.GridCompoundIdentityFuture)2 Ignite (org.apache.ignite.Ignite)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)1 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)1 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)1