Skip to content

Commit d1348ed

Browse files
authored
IGNITE-28436 Introduce PartitionPageMemory for further reuse (#7917)
1 parent ccef3df commit d1348ed

47 files changed

Lines changed: 720 additions & 338 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/page-memory/src/integrationTest/java/org/apache/ignite/internal/pagememory/tree/AbstractBplusTreePageMemoryTest.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.apache.ignite.internal.logger.IgniteLogger;
8383
import org.apache.ignite.internal.pagememory.FullPageId;
8484
import org.apache.ignite.internal.pagememory.PageMemory;
85+
import org.apache.ignite.internal.pagememory.PartitionPageMemory;
8586
import org.apache.ignite.internal.pagememory.TestPageIoRegistry;
8687
import org.apache.ignite.internal.pagememory.datastructure.DataStructure;
8788
import org.apache.ignite.internal.pagememory.io.IoVersions;
@@ -142,6 +143,9 @@ public abstract class AbstractBplusTreePageMemoryTest extends BaseIgniteAbstract
142143
@Nullable
143144
protected PageMemory pageMem;
144145

146+
@Nullable
147+
protected PartitionPageMemory partitionPageMemory;
148+
145149
@Nullable
146150
private ReuseList reuseList;
147151

@@ -165,8 +169,9 @@ protected void beforeEach() throws Exception {
165169
rnd = new Random(seed);
166170

167171
pageMem = createPageMemory();
172+
partitionPageMemory = pageMem.createPartitionPageMemory(GROUP_ID, 0);
168173

169-
reuseList = createReuseList(GROUP_ID, 0, pageMem, 0, true);
174+
reuseList = createReuseList(GROUP_ID, 0, partitionPageMemory, 0, true);
170175
}
171176

172177
@AfterEach
@@ -234,7 +239,7 @@ protected long getTestTimeout() {
234239
protected abstract @Nullable ReuseList createReuseList(
235240
int grpId,
236241
int partId,
237-
PageMemory pageMem,
242+
PartitionPageMemory pageMem,
238243
long rootId,
239244
boolean initNew
240245
) throws Exception;
@@ -2578,7 +2583,7 @@ private static void findNextForKeys(TestTree tree, long keyCount) throws Excepti
25782583
}
25792584

25802585
private TestTree reCreateTestTree(TestTree tree, long globalRmvId) throws Exception {
2581-
return new TestTree(tree.metaFullPageId(), reuseList, tree.canGetRow, pageMem, new AtomicLong(globalRmvId), false);
2586+
return new TestTree(tree.metaFullPageId(), reuseList, tree.canGetRow, partitionPageMemory, new AtomicLong(globalRmvId), false);
25822587
}
25832588

25842589
private void doTestRandomPutRemoveMultithreaded(boolean canGetRow) throws Exception {
@@ -2772,7 +2777,7 @@ private static int size(Cursor<?> c) {
27722777
}
27732778

27742779
private TestTree createTestTree(boolean canGetRow, AtomicLong globalRmvId) throws Exception {
2775-
var tree = new TestTree(allocateMetaPage(), reuseList, canGetRow, pageMem, globalRmvId, true);
2780+
var tree = new TestTree(allocateMetaPage(), reuseList, canGetRow, partitionPageMemory, globalRmvId, true);
27762781

27772782
assertEquals(0, tree.size());
27782783
assertEquals(0, tree.rootLevel());
@@ -2785,7 +2790,7 @@ protected TestTree createTestTree(boolean canGetRow) throws Exception {
27852790
}
27862791

27872792
private FullPageId allocateMetaPage() throws Exception {
2788-
return new FullPageId(pageMem.allocatePage(reuseList, GROUP_ID, 0, FLAG_AUX), GROUP_ID);
2793+
return new FullPageId(partitionPageMemory.allocatePage(reuseList, GROUP_ID, 0, FLAG_AUX), GROUP_ID);
27892794
}
27902795

27912796
/** Test tree. */
@@ -2812,7 +2817,7 @@ protected static class TestTree extends BplusTree<Long, Long> {
28122817
FullPageId metaPageId,
28132818
@Nullable ReuseList reuseList,
28142819
boolean canGetRow,
2815-
PageMemory pageMem,
2820+
PartitionPageMemory pageMem,
28162821
AtomicLong globalRmvId,
28172822
boolean initNew
28182823
) throws Exception {

modules/page-memory/src/integrationTest/java/org/apache/ignite/internal/pagememory/tree/AbstractBplusTreeReusePageMemoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.ignite.internal.lang.IgniteInternalCheckedException;
2121
import org.apache.ignite.internal.pagememory.PageMemory;
22+
import org.apache.ignite.internal.pagememory.PartitionPageMemory;
2223
import org.apache.ignite.internal.pagememory.freelist.FreeListImpl;
2324
import org.apache.ignite.internal.pagememory.reuse.ReuseList;
2425

@@ -31,7 +32,7 @@ public abstract class AbstractBplusTreeReusePageMemoryTest extends AbstractBplus
3132
protected ReuseList createReuseList(
3233
int grpId,
3334
int partId,
34-
PageMemory pageMem,
35+
PartitionPageMemory pageMem,
3536
long rootId,
3637
boolean initNew
3738
) throws IgniteInternalCheckedException {

modules/page-memory/src/integrationTest/java/org/apache/ignite/internal/pagememory/tree/ItBplusTreeReplaceRemoveRaceTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.ignite.internal.lang.IgniteInternalCheckedException;
3535
import org.apache.ignite.internal.pagememory.FullPageId;
3636
import org.apache.ignite.internal.pagememory.PageMemory;
37+
import org.apache.ignite.internal.pagememory.PartitionPageMemory;
3738
import org.apache.ignite.internal.pagememory.TestPageIoRegistry;
3839
import org.apache.ignite.internal.pagememory.configuration.VolatileDataRegionConfiguration;
3940
import org.apache.ignite.internal.pagememory.inmemory.VolatilePageMemory;
@@ -67,9 +68,13 @@ public class ItBplusTreeReplaceRemoveRaceTest extends BaseIgniteAbstractTest {
6768
@Nullable
6869
protected PageMemory pageMem;
6970

71+
@Nullable
72+
protected PartitionPageMemory partitionPageMemory;
73+
7074
@BeforeEach
7175
protected void beforeEach() throws Exception {
7276
pageMem = createPageMemory();
77+
partitionPageMemory = pageMem.createPartitionPageMemory(GROUP_ID, 0);
7378
}
7479

7580
@AfterEach
@@ -92,7 +97,7 @@ protected PageMemory createPageMemory() throws Exception {
9297
}
9398

9499
private FullPageId allocateMetaPage() throws IgniteInternalCheckedException {
95-
return new FullPageId(pageMem.allocatePageNoReuse(GROUP_ID, 0, FLAG_AUX), GROUP_ID);
100+
return new FullPageId(partitionPageMemory.allocatePageNoReuse(GROUP_ID, 0, FLAG_AUX), GROUP_ID);
96101
}
97102

98103
/**
@@ -126,7 +131,7 @@ protected static class TestPairTree extends BplusTree<Pair, Pair> {
126131
*/
127132
public TestPairTree(
128133
FullPageId metaPageId,
129-
PageMemory pageMem
134+
PartitionPageMemory pageMem
130135
) throws IgniteInternalCheckedException {
131136
super(
132137
"test",
@@ -419,7 +424,7 @@ public void testConcurrentPutRemoveSameRow() throws Exception {
419424
* @throws Exception If failed.
420425
*/
421426
private TestPairTree prepareBplusTree() throws Exception {
422-
TestPairTree tree = new TestPairTree(allocateMetaPage(), pageMem);
427+
TestPairTree tree = new TestPairTree(allocateMetaPage(), partitionPageMemory);
423428

424429
tree.putx(new Pair(1, 0));
425430
tree.putx(new Pair(2, 0));

modules/page-memory/src/integrationTest/java/org/apache/ignite/internal/pagememory/tree/inmemory/ItBplusTreeFakeReuseVolatilePageMemoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.ignite.internal.pagememory.tree.inmemory;
1919

2020
import java.util.concurrent.ConcurrentLinkedDeque;
21-
import org.apache.ignite.internal.pagememory.PageMemory;
21+
import org.apache.ignite.internal.pagememory.PartitionPageMemory;
2222
import org.apache.ignite.internal.pagememory.io.PageIo;
2323
import org.apache.ignite.internal.pagememory.reuse.ReuseBag;
2424
import org.apache.ignite.internal.pagememory.reuse.ReuseList;
@@ -32,7 +32,7 @@ public class ItBplusTreeFakeReuseVolatilePageMemoryTest extends ItBplusTreeVolat
3232
protected ReuseList createReuseList(
3333
int grpId,
3434
int partId,
35-
PageMemory pageMem,
35+
PartitionPageMemory pageMem,
3636
long rootId,
3737
boolean initNew
3838
) {

modules/page-memory/src/integrationTest/java/org/apache/ignite/internal/pagememory/tree/inmemory/ItBplusTreeVolatilePageMemoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
2121
import org.apache.ignite.internal.pagememory.PageMemory;
22+
import org.apache.ignite.internal.pagememory.PartitionPageMemory;
2223
import org.apache.ignite.internal.pagememory.TestPageIoRegistry;
2324
import org.apache.ignite.internal.pagememory.configuration.VolatileDataRegionConfiguration;
2425
import org.apache.ignite.internal.pagememory.inmemory.VolatilePageMemory;
@@ -65,7 +66,7 @@ protected long acquiredPages() {
6566
protected @Nullable ReuseList createReuseList(
6667
int grpId,
6768
int partId,
68-
PageMemory pageMem,
69+
PartitionPageMemory pageMem,
6970
long rootId,
7071
boolean initNew
7172
) {

modules/page-memory/src/integrationTest/java/org/apache/ignite/internal/pagememory/tree/persistence/ItBplusTreePersistentPageMemoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
2525
import org.apache.ignite.internal.lang.IgniteSystemProperties;
2626
import org.apache.ignite.internal.pagememory.PageMemory;
27+
import org.apache.ignite.internal.pagememory.PartitionPageMemory;
2728
import org.apache.ignite.internal.pagememory.TestPageIoRegistry;
2829
import org.apache.ignite.internal.pagememory.configuration.PersistentDataRegionConfiguration;
2930
import org.apache.ignite.internal.pagememory.persistence.PageHeader;
@@ -92,7 +93,7 @@ protected long acquiredPages() {
9293
protected @Nullable ReuseList createReuseList(
9394
int grpId,
9495
int partId,
95-
PageMemory pageMem,
96+
PartitionPageMemory pageMem,
9697
long rootId,
9798
boolean initNew
9899
) {

modules/page-memory/src/jmh/java/org/apache/ignite/internal/pagememory/benchmark/PageReplacementBenchmark.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.TimeUnit;
2525
import java.util.concurrent.TimeoutException;
2626
import org.apache.ignite.internal.lang.IgniteInternalCheckedException;
27+
import org.apache.ignite.internal.pagememory.PartitionPageMemory;
2728
import org.apache.ignite.internal.pagememory.TestPageIoModule.TestSimpleValuePageIo;
2829
import org.apache.ignite.internal.pagememory.configuration.ReplacementMode;
2930
import org.apache.ignite.internal.pagememory.io.PageIo;
@@ -92,6 +93,7 @@ public class PageReplacementBenchmark extends PersistentPageMemoryBenchmarkBase
9293
public CachePressure cachePressure;
9394

9495
private long[] pageIds;
96+
private PartitionPageMemory[] partitionPageMemories;
9597

9698
private int workingSetSize;
9799

@@ -262,6 +264,7 @@ public void setup(Blackhole blackhole) throws Exception {
262264
*/
263265
private void prepareWorkingSet() throws Exception {
264266
pageIds = new long[workingSetSize];
267+
partitionPageMemories = new PartitionPageMemory[workingSetSize];
265268

266269
// Allocate 80% of capacity at a time to avoid hitting dirty pages limit.
267270
int batchSize = (int) Math.round(REGION_CAPACITY_PAGES * 0.8);
@@ -276,12 +279,13 @@ private void prepareWorkingSet() throws Exception {
276279
// Distribute pages randomly across partitions.
277280
for (int i = batchStart; i < batchEnd; i++) {
278281
int partitionId = partitionRandom.nextInt(PARTITION_COUNT);
279-
pageIds[i] = persistentPageMemory().allocatePage(null, GROUP_ID, partitionId, FLAG_DATA);
282+
PartitionPageMemory partitionPageMemory = partitionPageMemory(partitionId);
283+
pageIds[i] = partitionPageMemory.allocatePage(null, GROUP_ID, partitionId, FLAG_DATA);
284+
partitionPageMemories[i] = partitionPageMemory;
280285
}
281286

282287
for (int i = batchStart; i < batchEnd; i++) {
283-
long pageId = pageIds[i];
284-
writePage(pageId, pageIo);
288+
writePage(i, pageIo);
285289
}
286290
} finally {
287291
checkpointManager().checkpointTimeoutLock().checkpointReadUnlock();
@@ -325,9 +329,8 @@ private void warmupCache(Blackhole blackhole) throws IgniteInternalCheckedExcept
325329
try {
326330
for (int i = 0; i < warmupPages; i++) {
327331
int index = warmupDistribution.next();
328-
long pageId = pageIds[index];
329332

330-
accessPageReadOnly(pageId, 0, blackhole);
333+
accessPageReadOnly(index, 0, blackhole);
331334
}
332335
} finally {
333336
checkpointManager().checkpointTimeoutLock().checkpointReadUnlock();
@@ -387,13 +390,15 @@ public void zipfianLatencyFourThreads(ThreadState state, Blackhole blackhole)
387390

388391
private void benchmarkIteration(ThreadState state, Blackhole blackhole) throws IgniteInternalCheckedException {
389392
int index = state.nextZipfianIndex();
390-
long pageId = pageIds[index];
391-
accessPageReadOnly(pageId, state.threadIndex(), blackhole);
393+
accessPageReadOnly(index, state.threadIndex(), blackhole);
392394
}
393395

394-
private void accessPageReadOnly(long pageId, int threadIndex, Blackhole blackhole)
396+
private void accessPageReadOnly(int index, int threadIndex, Blackhole blackhole)
395397
throws IgniteInternalCheckedException {
396-
long page = persistentPageMemory().acquirePage(GROUP_ID, pageId);
398+
long pageId = pageIds[index];
399+
PartitionPageMemory partitionPageMemory = partitionPageMemories[index];
400+
401+
long page = partitionPageMemory.acquirePage(GROUP_ID, pageId);
397402

398403
if (page == 0) {
399404
throw new IllegalStateException(String.format(
@@ -408,22 +413,25 @@ private void accessPageReadOnly(long pageId, int threadIndex, Blackhole blackhol
408413
try {
409414
blackhole.consume(page);
410415
} finally {
411-
persistentPageMemory().releasePage(GROUP_ID, pageId, page);
416+
partitionPageMemory.releasePage(GROUP_ID, pageId, page);
412417
}
413418
}
414419

415-
private void writePage(long pageId, PageIo pageIo) throws IgniteInternalCheckedException {
416-
long page = persistentPageMemory().acquirePage(GROUP_ID, pageId);
420+
private void writePage(int index, PageIo pageIo) throws IgniteInternalCheckedException {
421+
long pageId = pageIds[index];
422+
PartitionPageMemory partitionPageMemory = partitionPageMemories[index];
423+
424+
long page = partitionPageMemory.acquirePage(GROUP_ID, pageId);
417425
try {
418-
long pageAddr = persistentPageMemory().writeLock(GROUP_ID, pageId, page);
426+
long pageAddr = partitionPageMemory.writeLock(GROUP_ID, pageId, page);
419427
try {
420428
pageIo.initNewPage(pageAddr, pageId, PAGE_SIZE);
421429
TestSimpleValuePageIo.setLongValue(pageAddr, pageId);
422430
} finally {
423-
persistentPageMemory().writeUnlock(GROUP_ID, pageId, page, true);
431+
partitionPageMemory.writeUnlock(GROUP_ID, pageId, page, true);
424432
}
425433
} finally {
426-
persistentPageMemory().releasePage(GROUP_ID, pageId, page);
434+
partitionPageMemory.releasePage(GROUP_ID, pageId, page);
427435
}
428436
}
429437

modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/PageIdAllocator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/**
3232
* Class responsible for allocating/freeing page IDs.
3333
*/
34+
// TODO IGNITE-28429 Remove "groupId" parameter from all methods.
3435
public interface PageIdAllocator {
3536
/**
3637
* Flag for a Data page. Also used by partition meta and tracking pages. This type doesn't use the Page ID rotation mechanism.

modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/PageMemory.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@
1717

1818
package org.apache.ignite.internal.pagememory;
1919

20-
import java.nio.ByteBuffer;
2120
import org.apache.ignite.internal.lang.IgniteInternalException;
22-
import org.apache.ignite.internal.pagememory.io.PageIo;
23-
import org.apache.ignite.internal.pagememory.io.PageIoRegistry;
2421

2522
/**
2623
* Class responsible for pages storage and handling.
2724
*/
2825
// TODO IGNITE-16350 Improve javadoc in this class.
29-
public interface PageMemory extends PageIdAllocator, PageSupport {
26+
// TODO IGNITE-28429 Remove the inheritance.
27+
public interface PageMemory {
3028
/**
3129
* Stops page memory.
3230
*
33-
* @param deallocate {@code True} to deallocate memory, {@code false} to allow memory reuse on subsequent {@link #start()}
31+
* @param deallocate {@code True} to deallocate memory, {@code false} to allow memory reuse on subsequent {@code start()}
3432
*/
3533
void stop(boolean deallocate) throws IgniteInternalException;
3634

@@ -39,35 +37,22 @@ public interface PageMemory extends PageIdAllocator, PageSupport {
3937
*/
4038
int pageSize();
4139

42-
/**
43-
* Returns a page size without the encryption overhead, in bytes.
44-
*
45-
* @param groupId Group id.
46-
*/
47-
// TODO IGNITE-16350 Consider renaming.
48-
int realPageSize(int groupId);
49-
5040
/**
5141
* Returns a page's size with system overhead, in bytes.
5242
*/
5343
// TODO IGNITE-16350 Consider renaming.
5444
int systemPageSize();
5545

56-
/**
57-
* Wraps a page address, obtained by a {@code readLock}/{@code writeLock} or their variants, into a direct byte buffer.
58-
*
59-
* @param pageAddr Page address.
60-
* @return Page byte buffer.
61-
*/
62-
ByteBuffer pageBuffer(long pageAddr);
63-
6446
/**
6547
* Returns the total number of pages loaded into memory.
6648
*/
6749
long loadedPages();
6850

6951
/**
70-
* Returns a registry to obtain {@link PageIo} instances for pages.
52+
* Creates a new instance of {@link PartitionPageMemory} for a specified partition.
53+
*
54+
* @param groupId Group ID for the specific partition.
55+
* @param partitionId Partition ID of the specific partition.
7156
*/
72-
PageIoRegistry ioRegistry();
57+
PartitionPageMemory createPartitionPageMemory(int groupId, int partitionId);
7358
}

0 commit comments

Comments
 (0)