tkalkirill commented on code in PR #822:
URL: https://github.com/apache/ignite-3/pull/822#discussion_r885463561
##########
modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/PageMemoryImplNoLoadTest.java:
##########
@@ -78,56 +82,193 @@ public void testPageHandleDeallocation() {
}
@Test
- void testDirtyPages() throws Exception {
- PageMemoryImpl memory = (PageMemoryImpl) memory();
+ void testDirtyPages(
+ @InjectConfiguration PageMemoryCheckpointConfiguration
checkpointConfig,
+ @WorkDirectory Path workDir
+ ) throws Exception {
+ FilePageStoreManager filePageStoreManager =
createFilePageStoreManager(workDir);
+
+ Collection<PageMemoryDataRegion> dataRegions = new ArrayList<>();
+
+ CheckpointManager checkpointManager =
createCheckpointManager(checkpointConfig, workDir, filePageStoreManager,
dataRegions);
+
+ PageMemoryImpl pageMemoryImpl =
createPageMemoryImpl(defaultSegmentSizes(), filePageStoreManager,
checkpointManager);
+
+ dataRegions.add(newDataRegion(true, pageMemoryImpl));
- memory.start();
+ filePageStoreManager.start();
+
+ checkpointManager.start();
+
+ pageMemoryImpl.start();
try {
- Set<FullPageId> dirtyPages = Set.of(allocatePage(memory),
allocatePage(memory));
+ initGroupFilePageStores(filePageStoreManager);
+
+ checkpointManager.checkpointTimeoutLock().checkpointReadLock();
- assertThat(memory.dirtyPages(), equalTo(dirtyPages));
+ try {
+ Set<FullPageId> dirtyPages =
Set.of(createDirtyPage(pageMemoryImpl), createDirtyPage(pageMemoryImpl));
+
+ assertThat(pageMemoryImpl.dirtyPages(), equalTo(dirtyPages));
+ } finally {
+
checkpointManager.checkpointTimeoutLock().checkpointReadUnlock();
+ }
- // TODO: IGNITE-16984 After the checkpoint check that there are no
dirty pages
+ checkpointManager
+ .forceCheckpoint("for_test_flash_dirty_pages", null)
+ .futureFor(FINISHED)
+ .get(100, MILLISECONDS);
+
+ assertThat(pageMemoryImpl.dirtyPages(), empty());
} finally {
- memory.stop(true);
+ closeAll(
+ () -> pageMemoryImpl.stop(true),
+ checkpointManager::stop,
+ filePageStoreManager::stop
+ );
}
}
@Test
- void testSafeToUpdate() throws Exception {
+ void testSafeToUpdate(
+ @InjectConfiguration PageMemoryCheckpointConfiguration
checkpointConfig,
+ @WorkDirectory Path workDir
+ ) throws Exception {
+ FilePageStoreManager filePageStoreManager =
createFilePageStoreManager(workDir);
+
+ Collection<PageMemoryDataRegion> dataRegions = new ArrayList<>();
+
+ CheckpointManager checkpointManager =
createCheckpointManager(checkpointConfig, workDir, filePageStoreManager,
dataRegions);
+
long systemPageSize = PAGE_SIZE + PAGE_OVERHEAD;
- dataRegionCfg
- .change(c -> c.changeInitSize(128 *
systemPageSize).changeMaxSize(128 * systemPageSize))
- .get(1, SECONDS);
+ dataRegionCfg.change(c -> c.changeInitSize(128 *
systemPageSize).changeMaxSize(128 * systemPageSize)).get(1, SECONDS);
- PageMemoryImpl memory = memory(new long[]{100 * systemPageSize, 28 *
systemPageSize});
+ PageMemoryImpl pageMemoryImpl = createPageMemoryImpl(
+ new long[]{100 * systemPageSize, 28 * systemPageSize},
+ filePageStoreManager,
+ checkpointManager
+ );
+
+ dataRegions.add(newDataRegion(true, pageMemoryImpl));
+
+ filePageStoreManager.start();
+
+ checkpointManager.start();
- memory.start();
+ pageMemoryImpl.start();
try {
- long maxPages = memory.totalPages();
+ initGroupFilePageStores(filePageStoreManager);
+
+ long maxPages = pageMemoryImpl.totalPages();
long maxDirtyPages = (maxPages * 3 / 4);
assertThat(maxDirtyPages, greaterThanOrEqualTo(50L));
- for (int i = 0; i < maxDirtyPages - 1; i++) {
- allocatePage(memory);
+ checkpointManager.checkpointTimeoutLock().checkpointReadLock();
- assertTrue(memory.safeToUpdate(), "i=" + i);
- }
+ try {
+ for (int i = 0; i < maxDirtyPages - 1; i++) {
+ createDirtyPage(pageMemoryImpl);
- for (int i = (int) maxDirtyPages - 1; i < maxPages; i++) {
- allocatePage(memory);
+ assertTrue(pageMemoryImpl.safeToUpdate(), "i=" + i);
+ }
- assertFalse(memory.safeToUpdate(), "i=" + i);
+ for (int i = (int) maxDirtyPages - 1; i < maxPages; i++) {
+ createDirtyPage(pageMemoryImpl);
+
+ assertFalse(pageMemoryImpl.safeToUpdate(), "i=" + i);
+ }
+ } finally {
+
checkpointManager.checkpointTimeoutLock().checkpointReadUnlock();
}
- // TODO: IGNITE-16984 After the checkpoint check
assertTrue(memory.safeToUpdate())
+ checkpointManager
+ .forceCheckpoint("for_test_safe_to_update", null)
+ .futureFor(FINISHED)
+ .get(100, MILLISECONDS);
+
+ assertTrue(pageMemoryImpl.safeToUpdate());
} finally {
- memory.stop(true);
+ closeAll(
+ () -> pageMemoryImpl.stop(true),
+ checkpointManager::stop,
+ filePageStoreManager::stop
+ );
+ }
+ }
+
+ protected PageMemoryImpl createPageMemoryImpl(
+ long[] sizes,
+ @Nullable FilePageStoreManager filePageStoreManager,
+ @Nullable CheckpointManager checkpointManager
+ ) {
+ PageIoRegistry ioRegistry = new PageIoRegistry();
+
+ ioRegistry.loadFromServiceLoader();
+
+ return new PageMemoryImpl(
+ new UnsafeMemoryProvider(null),
Review Comment:
**DirectMemoryProvider** and **MemoryAllocator** are different things, above
I asked about **UnsafeMemoryProvider**.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]