Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ public enum CheckpointWriteOrder {
* All checkpoint pages are collected into single list and sorted by page index.
* Provides almost sequential disk writes, which can be much faster on some SSD models.
*/
SEQUENTIAL;
SEQUENTIAL,

/**
* All checkpoint pages are sorted by page index. But for each new partition, the first page is one with the
* maximum page id, followed by pages sorted in ascending order. As a result, the first page for a given partition
* preallocates all necessary disk space for the file on the current checkpoint.
*/
SEQUENTIAL_WITH_PREALLOCATION;

/**
* Enumerated values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.pagemem.FullPageId;
import org.apache.ignite.internal.pagemem.PageIdUtils;
import org.apache.ignite.internal.pagemem.store.PageStore;
import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
import org.apache.ignite.internal.pagemem.wal.record.CacheState;
Expand Down Expand Up @@ -491,7 +492,7 @@
cpPagesPerRegion.add(new T2<>(regPages.getKey(), pages));
}

if (checkpointWriteOrder == CheckpointWriteOrder.SEQUENTIAL) {
if (checkpointWriteOrder != CheckpointWriteOrder.RANDOM) {
Comparator<FullPageId> cmp = Comparator.comparingInt(FullPageId::groupId)
.thenComparingLong(FullPageId::effectivePageId);

Expand All @@ -506,11 +507,58 @@

if (pool != null)
pool.shutdown();

if (checkpointWriteOrder == CheckpointWriteOrder.SEQUENTIAL_WITH_PREALLOCATION) {
for (T2<PageMemoryEx, FullPageId[]> pagesPerReg : cpPagesPerRegion)
arrangeForPreallocation(pagesPerReg.getValue());
}
}

return new GridConcurrentMultiPairQueue<>(cpPagesPerRegion);
}

/**
* Arranges the array of pages in such a way that for each new partition, the first page is one with the
* maximum page id, followed by pages sorted in ascending order. As a result, the first page for a given partition
* preallocates all necessary disk space for the file on the current checkpoint.
*
* @param pageIds Sorted (by group id and page id) array of page ids.
*/
public static void arrangeForPreallocation(FullPageId[] pageIds) {
if (pageIds.length <= 1)
return;

int partStartIdx = 0;
FullPageId prevFullPageId = pageIds[0];
int prevGrpId = prevFullPageId.groupId();
int prevPartId = PageIdUtils.partId(prevFullPageId.pageId());

for (int i = 1; i < pageIds.length; i++) {
assert pageIds[i].groupId() >= pageIds[i - 1].groupId() : "Unsorted page IDs array";

Check warning on line 537 in modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/checkpoint/CheckpointWorkflow.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this assert with a proper check.

See more on https://sonarcloud.io/project/issues?id=apache_ignite&issues=AZ4nNh76ek4mpMlUIufP&open=AZ4nNh76ek4mpMlUIufP&pullRequest=13137
assert pageIds[i].groupId() != pageIds[i - 1].groupId()
|| pageIds[i].effectivePageId() >= pageIds[i - 1].effectivePageId() : "Unsorted page IDs array";

Check warning on line 539 in modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/checkpoint/CheckpointWorkflow.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this assert with a proper check.

See more on https://sonarcloud.io/project/issues?id=apache_ignite&issues=AZ4nNh76ek4mpMlUIufQ&open=AZ4nNh76ek4mpMlUIufQ&pullRequest=13137

int curGrpId = pageIds[i].groupId();
int curPartId = PageIdUtils.partId(pageIds[i].pageId());

if (curGrpId == prevGrpId && curPartId == prevPartId) {
FullPageId tmp = pageIds[i];
pageIds[i] = prevFullPageId;
prevFullPageId = tmp;
continue;
}

pageIds[partStartIdx] = prevFullPageId;

prevGrpId = curGrpId;
prevPartId = curPartId;
prevFullPageId = pageIds[i];
partStartIdx = i;
}

pageIds[partStartIdx] = prevFullPageId;
}

/**
* Performs parallel sort in isolated fork join pool.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.configuration.BinaryConfiguration;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.CheckpointWriteOrder;
import org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
Expand All @@ -47,16 +48,27 @@
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;

/**
*
*/
/** */
@RunWith(Parameterized.class)
public class IgnitePersistentStoreCacheGroupsTest extends GridCommonAbstractTest {
/** Checkpoint write order. */
@Parameterized.Parameter
public CheckpointWriteOrder cpWriteOrder;

/** */
@Parameterized.Parameters(name = "cpWriteOrder={0}")
public static Object[] parameters() {
return CheckpointWriteOrder.values();
}

/** */
private static final String GROUP1 = "grp1";

Expand Down Expand Up @@ -88,6 +100,7 @@ public class IgnitePersistentStoreCacheGroupsTest extends GridCommonAbstractTest
.setDefaultDataRegionConfiguration(
new DataRegionConfiguration().setMaxSize(100L * 1024 * 1024).setPersistenceEnabled(true))
.setPageSize(1024)
.setCheckpointWriteOrder(cpWriteOrder)
.setWalMode(WALMode.LOG_ONLY);

cfg.setDataStorageConfiguration(memCfg);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.processors.cache.persistence.db.checkpoint;

import org.apache.ignite.internal.pagemem.FullPageId;
import org.apache.ignite.internal.pagemem.PageIdAllocator;
import org.apache.ignite.internal.pagemem.PageIdUtils;
import org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointWorkflow;
import org.junit.Assert;
import org.junit.Test;

/**
* Test for CheckpointWorkflow.arrangeForPreallocation method.
*/
public class PageIdsArrangeForPreallocationTest {
/** */
@Test
public void testSinglePageId() {
FullPageId[] pageIds = new FullPageId[] {
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 1),
};

CheckpointWorkflow.arrangeForPreallocation(pageIds);

FullPageId[] exp = new FullPageId[] {
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 1),
};

Assert.assertArrayEquals(exp, pageIds);
}

/** */
@Test
public void testSinglePartition() {
FullPageId[] pageIds = new FullPageId[] {
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 2), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 3), 1),
};

CheckpointWorkflow.arrangeForPreallocation(pageIds);

FullPageId[] exp = new FullPageId[] {
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 3), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 2), 1),
};

Assert.assertArrayEquals(exp, pageIds);
}

/** */
@Test
public void testSamePartitionDifferentGroups() {
FullPageId[] pageIds = new FullPageId[] {
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 2),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 2), 3),
};

CheckpointWorkflow.arrangeForPreallocation(pageIds);

FullPageId[] exp = new FullPageId[] {
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 2),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 2), 3),
};

Assert.assertArrayEquals(exp, pageIds);
}

/** */
@Test
public void testMixed() {
FullPageId[] pageIds = new FullPageId[] {
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 2), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 5), 1),
new FullPageId(PageIdUtils.pageId(2, PageIdAllocator.FLAG_DATA, 4), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 2),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 3), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 1), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 2), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 3), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 4), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 5), 2),
};

CheckpointWorkflow.arrangeForPreallocation(pageIds);

FullPageId[] exp = new FullPageId[] {
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 5), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 2), 1),
new FullPageId(PageIdUtils.pageId(2, PageIdAllocator.FLAG_DATA, 4), 1),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 3), 2),
new FullPageId(PageIdUtils.pageId(1, PageIdAllocator.FLAG_DATA, 1), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 5), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 1), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 2), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 3), 2),
new FullPageId(PageIdUtils.pageId(3, PageIdAllocator.FLAG_DATA, 4), 2),
};

Assert.assertArrayEquals(exp, pageIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsMarshallerMappingRestoreOnNodeStartTest;
import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsTxCacheRebalancingTest;
import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsTxHistoricalRebalancingTest;
import org.apache.ignite.internal.processors.cache.persistence.IgnitePersistenceSequentialCheckpointTest;
import org.apache.ignite.internal.processors.cache.persistence.IgnitePersistentStoreCacheGroupsTest;
import org.apache.ignite.internal.processors.cache.persistence.PersistenceDirectoryWarningLoggingTest;
import org.apache.ignite.internal.processors.cache.persistence.RestorePartitionStateDuringCheckpointTest;
Expand All @@ -36,6 +35,7 @@
import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsMultiNodePutGetRestartTest;
import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsPageEvictionTest;
import org.apache.ignite.internal.processors.cache.persistence.db.IgniteSequentialNodeCrashRecoveryTest;
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.PageIdsArrangeForPreallocationTest;
import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsCacheDestroyDuringCheckpointTest;
import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsCacheIntegrationTest;
import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsDiskErrorsRecoveringTest;
Expand Down Expand Up @@ -64,7 +64,7 @@
IgnitePdsPageEvictionTest.class,
IgnitePdsMultiNodePutGetRestartTest.class,
IgnitePersistentStoreCacheGroupsTest.class,
IgnitePersistenceSequentialCheckpointTest.class,
PageIdsArrangeForPreallocationTest.class,
PersistenceDirectoryWarningLoggingTest.class,
WalPathsTest.class,
WalRecoveryTxLogicalRecordsTest.class,
Expand Down
Loading