Search in sources :

Example 1 with DatabaseLifecycleListener

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

the class GridDhtPartitionsExchangeFuture method initCachesOnLocalJoin.

/**
 * @throws IgniteCheckedException If failed.
 */
private IgniteInternalFuture<?> initCachesOnLocalJoin() throws IgniteCheckedException {
    if (!cctx.kernalContext().clientNode() && !isLocalNodeInBaseline()) {
        cctx.exchange().exchangerBlockingSectionBegin();
        try {
            List<DatabaseLifecycleListener> listeners = cctx.kernalContext().internalSubscriptionProcessor().getDatabaseListeners();
            for (DatabaseLifecycleListener lsnr : listeners) lsnr.onBaselineChange();
        } finally {
            cctx.exchange().exchangerBlockingSectionEnd();
        }
        timeBag.finishGlobalStage("Baseline change callback");
    }
    cctx.exchange().exchangerBlockingSectionBegin();
    try {
        cctx.activate();
    } finally {
        cctx.exchange().exchangerBlockingSectionEnd();
    }
    timeBag.finishGlobalStage("Components activation");
    IgniteInternalFuture<?> cachesRegistrationFut = cctx.cache().startCachesOnLocalJoin(initialVersion(), exchActions == null ? null : exchActions.localJoinContext());
    if (!cctx.kernalContext().clientNode())
        cctx.cache().shutdownNotFinishedRecoveryCaches();
    ensureClientCachesStarted();
    return cachesRegistrationFut;
}
Also used : DatabaseLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.DatabaseLifecycleListener)

Example 2 with DatabaseLifecycleListener

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

the class GridCachePartitionExchangeManagerWarningsTest method testDumpLongRunningOperationsWaitForFullyInitializedExchangeManager.

/**
 */
@Test
public void testDumpLongRunningOperationsWaitForFullyInitializedExchangeManager() throws Exception {
    long waitingTimeout = 5_000;
    PrintStream errStream = System.err;
    CountDownLatch startLatch = new CountDownLatch(1);
    CountDownLatch waitLatch = new CountDownLatch(1);
    try {
        // GridCachePartitionExchangeManager#dumpLongRunningOperations() uses diagnostic log,
        // which can be non-initialized, and so, error messgaes are logged into standard error output stream.
        ByteArrayOutputStream testOut = new ByteArrayOutputStream(16 * 1024);
        System.setErr(new PrintStream(testOut));
        AtomicReference<IgniteInternalFuture<?>> dumpOpsFut = new AtomicReference<>();
        IgniteInternalFuture<Ignite> startFut = null;
        // Lyficycle bean allows to register DatabaseLifecycleListener and trigger dumpLongRunningOperations
        // before GridCachePartitionExchangeManager is started.
        lifecycleBean = new LifecycleBean() {

            /**
             * Ignite instance.
             */
            @IgniteInstanceResource
            IgniteEx ignite;

            /**
             * {@inheritDoc}
             */
            @Override
            public void onLifecycleEvent(LifecycleEventType evt) throws IgniteException {
                if (evt == LifecycleEventType.BEFORE_NODE_START) {
                    ignite.context().internalSubscriptionProcessor().registerDatabaseListener(new DatabaseLifecycleListener() {

                        @Override
                        public void onInitDataRegions(IgniteCacheDatabaseSharedManager mgr) throws IgniteCheckedException {
                            dumpOpsFut.set(GridTestUtils.runAsync(() -> ignite.context().cache().context().exchange().dumpLongRunningOperations(1_000)));
                            // Let's allow to check that dumpLongRunningOperations is triggered.
                            startLatch.countDown();
                            // Wait for the check
                            try {
                                if (!waitLatch.await(waitingTimeout * 3, TimeUnit.MILLISECONDS))
                                    throw new IgniteCheckedException("Failed to wait for a check of dumpLongRunningOperations");
                            } catch (InterruptedException e) {
                                throw new IgniteCheckedException(e);
                            }
                        }
                    });
                }
            }
        };
        startFut = GridTestUtils.runAsync(new Callable<Ignite>() {

            @Override
            public Ignite call() throws Exception {
                return startGrid(0);
            }
        });
        assertTrue("Server node did not start in " + waitingTimeout + " ms.", startLatch.await(waitingTimeout, TimeUnit.MILLISECONDS));
        // Check that dumpLongRunningOperations did not produce any error.
        if (GridTestUtils.waitForCondition(() -> dumpOpsFut.get().isDone(), waitingTimeout)) {
            // Check that error output stream does not contain NullPointerException.
            String output = testOut.toString();
            assertTrue("Unexpected error [err=" + output + ']', output.isEmpty());
        }
        // Unblock starting the node.
        waitLatch.countDown();
        assertTrue("Dumping log running operations is not completed yet.", GridTestUtils.waitForCondition(() -> dumpOpsFut.get().isDone(), waitingTimeout));
        // Check that error output stream does not contain any error.
        String output = testOut.toString();
        assertTrue("Unexpected error [err=" + output + ']', output.isEmpty());
        startFut.get(waitingTimeout, TimeUnit.MILLISECONDS);
    } finally {
        startLatch.countDown();
        waitLatch.countDown();
        System.setErr(errStream);
    }
}
Also used : PrintStream(java.io.PrintStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteException(org.apache.ignite.IgniteException) LifecycleBean(org.apache.ignite.lifecycle.LifecycleBean) Ignite(org.apache.ignite.Ignite) LifecycleEventType(org.apache.ignite.lifecycle.LifecycleEventType) DatabaseLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.DatabaseLifecycleListener) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

DatabaseLifecycleListener (org.apache.ignite.internal.processors.cache.persistence.DatabaseLifecycleListener)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 LifecycleBean (org.apache.ignite.lifecycle.LifecycleBean)1 LifecycleEventType (org.apache.ignite.lifecycle.LifecycleEventType)1 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1