use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl in project ignite by apache.
the class PageMemoryImplTest method createPageMemory.
/**
* @param throttlingPlc Throttling Policy.
* @throws Exception If creating mock failed.
*/
private PageMemoryImpl createPageMemory(int maxSize, PageMemoryImpl.ThrottlingPolicy throttlingPlc, IgnitePageStoreManager mgr, PageStoreWriter replaceWriter, @Nullable IgniteInClosure<FullPageId> cpBufChecker) throws Exception {
long[] sizes = new long[5];
for (int i = 0; i < sizes.length; i++) sizes[i] = maxSize * MB / 4;
sizes[4] = maxSize * MB / 4;
DirectMemoryProvider provider = new UnsafeMemoryProvider(log);
IgniteConfiguration igniteCfg = new IgniteConfiguration();
igniteCfg.setDataStorageConfiguration(new DataStorageConfiguration());
igniteCfg.setFailureHandler(new NoOpFailureHandler());
igniteCfg.setEncryptionSpi(new NoopEncryptionSpi());
igniteCfg.setMetricExporterSpi(new NoopMetricExporterSpi());
igniteCfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi());
igniteCfg.setEventStorageSpi(new NoopEventStorageSpi());
GridTestKernalContext kernalCtx = new GridTestKernalContext(new GridTestLog4jLogger(), igniteCfg);
kernalCtx.add(new IgnitePluginProcessor(kernalCtx, igniteCfg, Collections.<PluginProvider>emptyList()));
kernalCtx.add(new GridInternalSubscriptionProcessor(kernalCtx));
kernalCtx.add(new PerformanceStatisticsProcessor(kernalCtx));
kernalCtx.add(new GridEncryptionManager(kernalCtx));
kernalCtx.add(new GridMetricManager(kernalCtx));
kernalCtx.add(new GridSystemViewManager(kernalCtx));
kernalCtx.add(new GridEventStorageManager(kernalCtx));
FailureProcessor failureProc = new FailureProcessor(kernalCtx);
failureProc.start();
kernalCtx.add(failureProc);
GridCacheSharedContext<Object, Object> sharedCtx = new GridCacheSharedContext<>(kernalCtx, null, null, null, mgr, new NoOpWALManager(), null, new IgniteCacheDatabaseSharedManager(), null, null, null, null, null, null, null, null, null, null, null, null, null);
CheckpointProgressImpl cl0 = Mockito.mock(CheckpointProgressImpl.class);
IgniteOutClosure<CheckpointProgress> noThrottle = Mockito.mock(IgniteOutClosure.class);
Mockito.when(noThrottle.apply()).thenReturn(cl0);
Mockito.when(cl0.currentCheckpointPagesCount()).thenReturn(1_000_000);
Mockito.when(cl0.evictedPagesCounter()).thenReturn(new AtomicInteger(0));
Mockito.when(cl0.syncedPagesCounter()).thenReturn(new AtomicInteger(1_000_000));
Mockito.when(cl0.writtenPagesCounter()).thenReturn(new AtomicInteger(1_000_000));
PageMemoryImpl mem = cpBufChecker == null ? new PageMemoryImpl(provider, sizes, sharedCtx, sharedCtx.pageStore(), PAGE_SIZE, replaceWriter, new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {
@Override
public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) {
}
}, () -> true, new DataRegionMetricsImpl(igniteCfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration(), kernalCtx), throttlingPlc, noThrottle) : new PageMemoryImpl(provider, sizes, sharedCtx, sharedCtx.pageStore(), PAGE_SIZE, replaceWriter, new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {
@Override
public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) {
}
}, () -> true, new DataRegionMetricsImpl(igniteCfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration(), kernalCtx), throttlingPlc, noThrottle) {
@Override
public FullPageId pullPageFromCpBuffer() {
FullPageId pageId = super.pullPageFromCpBuffer();
cpBufChecker.apply(pageId);
return pageId;
}
};
mem.metrics().enableMetrics();
mem.start();
return mem;
}
use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl in project ignite by apache.
the class IgniteThrottlingUnitTest method wakeupSpeedBaseThrottledThreadOnCheckpointFinish.
/**
* @throws IgniteInterruptedCheckedException if failed.
*/
@Test
public void wakeupSpeedBaseThrottledThreadOnCheckpointFinish() throws IgniteInterruptedCheckedException {
// given: Enabled throttling with EXPONENTIAL level.
CheckpointProgressImpl cl0 = mock(CheckpointProgressImpl.class);
when(cl0.writtenPagesCounter()).thenReturn(new AtomicInteger(200));
IgniteOutClosure<CheckpointProgress> cpProgress = mock(IgniteOutClosure.class);
when(cpProgress.apply()).thenReturn(cl0);
PagesWriteThrottlePolicy plc = new PagesWriteSpeedBasedThrottle(pageMemory2g, cpProgress, stateChecker, log) {
@Override
protected void doPark(long throttleParkTimeNs) {
// Force parking to long time.
super.doPark(TimeUnit.SECONDS.toNanos(1));
}
};
simulateCheckpointBufferInDangerZoneSituation();
AtomicBoolean stopLoad = new AtomicBoolean();
List<Thread> loadThreads = new ArrayList<>();
for (int i = 0; i < 10; i++) {
loadThreads.add(new Thread(() -> {
while (!stopLoad.get()) plc.onMarkDirty(true);
}, "load-" + i));
}
try {
loadThreads.forEach(Thread::start);
// and: All load threads are parked.
for (Thread t : loadThreads) assertTrue(t.getName(), waitForCondition(() -> t.getState() == TIMED_WAITING, 1000L));
// when: Disable throttling
simulateCheckpointBufferInSafeZoneSituation();
stopReportingCheckpointProgress(cpProgress);
// and: Finish the checkpoint.
plc.onFinishCheckpoint();
// then: All load threads should be unparked.
for (Thread t : loadThreads) assertTrue(t.getName(), waitForCondition(() -> t.getState() != TIMED_WAITING, 500L));
for (Thread t : loadThreads) assertNotEquals(t.getName(), TIMED_WAITING, t.getState());
} finally {
stopLoad.set(true);
}
}
Aggregations