Skip to content

Commit bbc5790

Browse files
committed
IGNITE-7935 Code cleanup.
1 parent 80adb2b commit bbc5790

2 files changed

Lines changed: 55 additions & 46 deletions

File tree

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/AbstractFreeList.java

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ public abstract class AbstractFreeList<T extends Storable> extends PagesList imp
9292
/** */
9393
private final PageEvictionTracker evictionTracker;
9494

95-
/** */
96-
private final int maxPayloadSize = pageSize() - AbstractDataPageIO.MIN_DATA_PAGE_OVERHEAD;
97-
9895
/**
9996
*
10097
*/
@@ -343,7 +340,7 @@ private class WriteRowsHandler extends WriteRowHandler {
343340
T row = rows.get(idx);
344341

345342
int size = row.size();
346-
int payloadSize = size % maxPayloadSize;
343+
int payloadSize = size % MIN_SIZE_FOR_DATA_PAGE;
347344

348345
// If there is not enough space on page.
349346
if (remainSpace < payloadSize)
@@ -352,7 +349,7 @@ private class WriteRowsHandler extends WriteRowHandler {
352349
if (pageIsEmpty)
353350
rows0.add(row);
354351
else {
355-
int written = size > maxPayloadSize ?
352+
int written = size > MIN_SIZE_FOR_DATA_PAGE ?
356353
addRowFragment(pageId, page, pageAddr, iox, row, size - payloadSize, size) :
357354
addRow(pageId, page, pageAddr, iox, row, size);
358355

@@ -383,11 +380,11 @@ private class WriteRowsHandler extends WriteRowHandler {
383380
private int getPageEntrySize(T row, AbstractDataPageIO<T> io) throws IgniteCheckedException {
384381
int size = row.size();
385382

386-
int sizeSetup = size > maxPayloadSize ?
383+
int sizeSetup = size > MIN_SIZE_FOR_DATA_PAGE ?
387384
AbstractDataPageIO.SHOW_PAYLOAD_LEN | AbstractDataPageIO.SHOW_LINK | AbstractDataPageIO.SHOW_ITEM :
388385
AbstractDataPageIO.SHOW_PAYLOAD_LEN | AbstractDataPageIO.SHOW_ITEM;
389386

390-
return io.getPageEntrySize(size % maxPayloadSize, sizeSetup);
387+
return io.getPageEntrySize(size % MIN_SIZE_FOR_DATA_PAGE, sizeSetup);
391388
}
392389
}
393390

@@ -646,43 +643,38 @@ else if (PageIdUtils.tag(pageId) != PageIdAllocator.FLAG_DATA)
646643

647644
/** {@inheritDoc} */
648645
@Override public void insertDataRows(Collection<T> rows, IoStatisticsHolder statHolder) throws IgniteCheckedException {
649-
// Data rows <-> count of pages needed
650-
List<T> largeRows = new ArrayList<>(8);
646+
// Objects that don't fit into a single data page.
647+
List<T> largeRows = new ArrayList<>();
651648

652-
// other objects
649+
// Ordinary objects and the remaining parts of large objects.
653650
List<T> regularRows = new ArrayList<>(8);
654651

655652
for (T dataRow : rows) {
656653
int size = dataRow.size();
657654

658-
if (size < maxPayloadSize)
655+
if (size < MIN_SIZE_FOR_DATA_PAGE)
659656
regularRows.add(dataRow);
660657
else {
661658
largeRows.add(dataRow);
662659

663-
if (size % maxPayloadSize > 0)
660+
if (size % MIN_SIZE_FOR_DATA_PAGE > 0)
664661
regularRows.add(dataRow);
665662
}
666663
}
667664

668665
for (T row : largeRows) {
669-
int rowSize = row.size();
666+
int size = row.size();
670667

671668
int written = 0;
672669

673670
do {
674-
if (written != 0)
675-
memMetrics.incrementLargeEntriesPages();
676-
677-
int remaining = rowSize - written;
671+
int remaining = size - written;
678672

679-
long pageId;
680-
681-
if (remaining >= MIN_SIZE_FOR_DATA_PAGE)
682-
pageId = takeEmptyPage(REUSE_BUCKET, ioVersions(), statHolder);
683-
else
673+
if (remaining < MIN_SIZE_FOR_DATA_PAGE)
684674
break;
685675

676+
long pageId = takeEmptyPage(REUSE_BUCKET, ioVersions(), statHolder);
677+
686678
AbstractDataPageIO<T> initIo = null;
687679

688680
if (pageId == 0L) {
@@ -698,28 +690,28 @@ else if (PageIdUtils.tag(pageId) != PageIdAllocator.FLAG_DATA)
698690
written = write(pageId, writeRow, initIo, row, written, FAIL_I, statHolder);
699691

700692
assert written != FAIL_I; // We can't fail here.
693+
694+
memMetrics.incrementLargeEntriesPages();
701695
}
702696
while (written != COMPLETE);
703697
}
704698

705699
for (int writtenCnt = 0; writtenCnt < regularRows.size(); ) {
706700
T row = regularRows.get(writtenCnt);
707701

708-
int size = row.size() % maxPayloadSize;
709-
710-
int minBucket = bucket(size, false) + 1;
702+
int size = row.size() % MIN_SIZE_FOR_DATA_PAGE;
711703

712-
long pageId = 0;
704+
int minBucket = bucket(size, false);
713705

714706
AbstractDataPageIO<T> initIo = null;
715707

716-
if (size != MIN_SIZE_FOR_DATA_PAGE) {
717-
for (int b = REUSE_BUCKET - 1; b >= minBucket; b--) {
718-
pageId = takeEmptyPage(b, ioVersions(), statHolder);
708+
long pageId = 0;
719709

720-
if (pageId != 0L)
721-
break;
722-
}
710+
for (int b = REUSE_BUCKET - 1; b > minBucket; b--) {
711+
pageId = takeEmptyPage(b, ioVersions(), statHolder);
712+
713+
if (pageId != 0L)
714+
break;
723715
}
724716

725717
if (pageId == 0)

modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListPreloadWithBatchUpdatesTest.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,45 +51,54 @@
5151

5252
import static org.apache.ignite.IgniteSystemProperties.IGNITE_DATA_STORAGE_BATCH_PAGE_WRITE;
5353
import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD;
54+
import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_PAGE_SIZE;
5455

5556
/**
5657
*
5758
*/
5859
@RunWith(Parameterized.class)
5960
public class FreeListPreloadWithBatchUpdatesTest extends GridCommonAbstractTest {
60-
/** */
61-
private static final int HDR_SIZE = 8 + 32;
62-
6361
/** */
6462
private static final long DEF_REG_SIZE_INIT = 3400 * 1024 * 1024L;
6563

6664
/** */
6765
private static final long DEF_REG_SIZE = 6144 * 1024 * 1024L;
6866

67+
/** */
68+
private static final int LARGE_PAGE = 16 * 1024;
69+
6970
/** */
7071
private static final String DEF_CACHE_NAME = "some-cache";
7172

7273
/** */
73-
@Parameterized.Parameters(name = "with atomicity={0} and persistence={1}")
74+
@Parameterized.Parameters(name = " atomicity={0}, persistence={1}, pageSize={2}")
7475
public static Iterable<Object[]> setup() {
7576
return Arrays.asList(new Object[][]{
76-
{CacheAtomicityMode.ATOMIC, false},
77-
{CacheAtomicityMode.ATOMIC, true},
78-
{CacheAtomicityMode.TRANSACTIONAL, false},
79-
{CacheAtomicityMode.TRANSACTIONAL, true},
80-
{CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT, false},
81-
{CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT, true}
77+
{CacheAtomicityMode.ATOMIC, false, DFLT_PAGE_SIZE},
78+
{CacheAtomicityMode.ATOMIC, true, DFLT_PAGE_SIZE},
79+
{CacheAtomicityMode.ATOMIC, false, LARGE_PAGE},
80+
{CacheAtomicityMode.ATOMIC, true, LARGE_PAGE},
81+
{CacheAtomicityMode.TRANSACTIONAL, false, DFLT_PAGE_SIZE},
82+
{CacheAtomicityMode.TRANSACTIONAL, true, DFLT_PAGE_SIZE},
83+
{CacheAtomicityMode.TRANSACTIONAL, false, LARGE_PAGE},
84+
{CacheAtomicityMode.TRANSACTIONAL, true, LARGE_PAGE},
85+
{CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT, false, DFLT_PAGE_SIZE},
86+
{CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT, true, DFLT_PAGE_SIZE}
8287
});
8388
}
8489

8590
/** */
86-
@Parameterized.Parameter()
91+
@Parameterized.Parameter
8792
public CacheAtomicityMode cacheAtomicityMode;
8893

8994
/** */
9095
@Parameterized.Parameter(1)
9196
public boolean persistence;
9297

98+
/** */
99+
@Parameterized.Parameter(2)
100+
public Integer pageSize;
101+
93102
/** {@inheritDoc} */
94103
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
95104
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
@@ -102,6 +111,7 @@ public static Iterable<Object[]> setup() {
102111
DataStorageConfiguration storeCfg = new DataStorageConfiguration();
103112

104113
storeCfg.setDefaultDataRegionConfiguration(def);
114+
storeCfg.setPageSize(pageSize);
105115

106116
if (persistence) {
107117
storeCfg.setWalMode(WALMode.LOG_ONLY);
@@ -250,14 +260,14 @@ public void testBatchHistoricalRebalance() throws Exception {
250260

251261
log.info("Updating values on node #1.");
252262

253-
for (int i = 100; i < 1000; i++) {
254-
if (i % 33 == 0) {
263+
for (int i = 100; i < 2000; i++) {
264+
if (i % 3 == 0) {
255265
cache.remove(i);
256266

257267
srcMap.remove(i);
258268
}
259269
else {
260-
byte[] bytes = new byte[512];
270+
byte[] bytes = new byte[ThreadLocalRandom.current().nextInt(16384)];
261271

262272
Arrays.fill(bytes, (byte)1);
263273

@@ -266,6 +276,13 @@ public void testBatchHistoricalRebalance() throws Exception {
266276
}
267277
}
268278

279+
for (int i = 10_000; i < 11_000; i++) {
280+
byte[] bytes = new byte[ThreadLocalRandom.current().nextInt(16384)];
281+
282+
srcMap.put(i, bytes);
283+
cache.put(i, bytes);
284+
}
285+
269286
forceCheckpoint();
270287

271288
log.info("Starting node #2.");

0 commit comments

Comments
 (0)