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;
}
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);
}
}
Aggregations