Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-13190 #7984

Closed
wants to merge 112 commits into from
Closed
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
5c0bb03
Simplest test added
May 27, 2020
f9abfb4
Test improvements
May 28, 2020
a979a2a
Defragmentation events listener
Jun 1, 2020
8e361c4
Minor refactoring to extract inner class
Jun 2, 2020
d922b36
GridCacheDataStore moved to separate class for reuse
Jun 2, 2020
495c68e
DefragmentationContext abstraction introduced, core is rewritten base…
Jun 5, 2020
9e6754e
Simplest test added
May 27, 2020
4ccb5a0
Test improvements
May 28, 2020
1e013a7
Defragmentation events listener
Jun 1, 2020
8990604
Minor refactoring to extract inner class
Jun 2, 2020
da70362
GridCacheDataStore moved to separate class for reuse
Jun 2, 2020
560ad16
DefragmentationContext abstraction introduced, core is rewritten base…
Jun 5, 2020
5066364
Added PageStoreCollection
alievmirza Jun 29, 2020
62d6fdd
IGNITE-13190 Changes from feature branch integrated
Jul 14, 2020
e506a1b
IGNITE-13190 Add link mapping tree.
SammyVimes Jul 21, 2020
e000ab2
IGNITE-13190 Encrypted file page store factory
SammyVimes Aug 4, 2020
8e68138
IGNITE-13190 New outer classes moved back to prevent merge conflicts.
ibessonov Aug 5, 2020
e173af0
IGNITE-13190 GridGain licenses removed from code.
ibessonov Aug 5, 2020
f104b0b
IGNITE-13190 PageStore management improved. Code reorganized and clea…
ibessonov Aug 6, 2020
51706e8
IGNITE-13190 Ability to checkpoint pages from new regions. Small code…
ibessonov Aug 6, 2020
3a150fe
IGNITE-13190 Basic failover code, not fully completed yet. Checkpoint…
ibessonov Aug 7, 2020
0ffb7e6
IGNITE-13190 Few small bugs fixed. Partition metadata copying impleme…
ibessonov Aug 13, 2020
b395fff
IGNITE-13190 Utility class extracted from manager.
ibessonov Aug 14, 2020
cf88708
IGNITE-13190 wip
ibessonov Aug 14, 2020
1d6f103
IGNITE-13190 Filtering of CacheDataStores fixed to find needed partition
sergey-chugunov-1985 Aug 28, 2020
deb3527
IGNITE-13190 Partial revert to avoid merge conflicts.
ibessonov Aug 31, 2020
e04858d
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Aug 31, 2020
2f50851
IGNITE-13190 Merge conflicts reapplied.
ibessonov Aug 31, 2020
6ab14b7
IGNITE-13190 Merge conflicts reapplied.
ibessonov Aug 31, 2020
8ff3e5f
Merge remote-tracking branch 'professional/ignite-13190' into ignite-…
ibessonov Aug 31, 2020
9563932
IGNITE-13190 JVM Crash fixed; Number of partitions in test lowered ba…
ibessonov Aug 31, 2020
678f46b
IGNITE-13190 Improved failover; Refactoring.
ibessonov Sep 2, 2020
5270a26
IGNITE-13190 Failover tests.
ibessonov Sep 2, 2020
7100748
IGNITE-13190 Creation of new row in defragmented partition fixed.
ibessonov Sep 4, 2020
30fba1f
IGNITE-13190 Index defragmentation.
SammyVimes Sep 3, 2020
6d28a7b
IGNITE-13190 Remove odd field.
SammyVimes Sep 7, 2020
dc3388e
IGNITE-13190 Failed tests fixed.
ibessonov Sep 8, 2020
a222a54
Merge remote-tracking branch 'professional/ignite-13190' into ignite-…
ibessonov Sep 8, 2020
7fb3362
IGNITE-13190 Fix index tree root creation.
SammyVimes Sep 8, 2020
e8509f1
IGNITE-13190 Test that defragmented index root is in meta tree.
SammyVimes Sep 8, 2020
555485a
IGNITE-13190 Refactoring; Eviction mode bug fixed.
ibessonov Sep 10, 2020
f4da2c5
IGNITE-13190 Fix indexing defragmentation for not inline indexes.
SammyVimes Sep 14, 2020
d4f5324
IGNITE-13190 [IGNITE-13190] Squashed Maintenance mode, unfinished.
ibessonov Sep 16, 2020
1daf29c
IGNITE-13190 Maintenance mode used for defragmentation but without au…
ibessonov Sep 17, 2020
6d4276e
IGNITE-13190 Eliminated some checkpoint future waits.
ibessonov Sep 18, 2020
a15b4cf
IGNITE-13190 Few javadocs.
ibessonov Sep 21, 2020
75ee7c3
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Sep 21, 2020
66e5c27
IGNITE-13190 MVCC indexes defragmentation and tests.
SammyVimes Sep 15, 2020
a937c07
IGNITE-13190 Checkpoint integration
akalash Sep 21, 2020
a1b7442
Merge branch 'master' into checkpoint-integration
akalash Sep 25, 2020
aa3c723
IGNITE-13190 Configuration; Checkpoint locks for index; Wrappers for …
ibessonov Sep 30, 2020
ff452df
IGNITE-13190 Few adjustments to the code.
ibessonov Oct 6, 2020
37cc862
IGNITE-13190 Few adjustments to the code.
ibessonov Oct 8, 2020
d21ac60
IGNITE-13190 Commented line removed.
ibessonov Oct 8, 2020
33acaa2
IGNITE-13190 Tiny log message at the end.
ibessonov Oct 15, 2020
6e91f1f
IGNITE-13190 Revert "IGNITE-13190 [IGNITE-13190] Squashed Maintenance…
akalash Oct 16, 2020
81db3b6
Merge branch 'master' into ignite-13190
akalash Oct 16, 2020
8785422
IGNITE-13190 Maintenance mode integration
akalash Oct 16, 2020
19ca7ee
IGNITE-13190 Deprecated system property removed.
ibessonov Oct 23, 2020
1b17c8b
IGNITE-13190 Defragmentation context mostly removed.
ibessonov Oct 23, 2020
dce6a73
IGNITE-13190 Defragmentation context mostly removed, part 2.
ibessonov Oct 26, 2020
bdc9662
IGNITE-13190 Crash fixed.
ibessonov Oct 26, 2020
ced2dac
IGNITE-13190 LICENSES
ibessonov Oct 26, 2020
7a244b9
IGNITE-13190 First checkpoint moved into defragmentation code.
ibessonov Oct 27, 2020
a3795fa
IGNITE-13190 Logs for the problem in benchmark scenario.
ibessonov Oct 27, 2020
52a5f4a
IGNITE-13190 Bunch of tiny fixes.
ibessonov Oct 27, 2020
7d752f6
IGNITE-13190 Tests ignored in MVCC suite.
ibessonov Oct 27, 2020
d3fc45f
IGNITE-13190 Javadoc
ibessonov Oct 27, 2020
bc2e16c
IGNITE-13190 Indexing fix.
ibessonov Oct 27, 2020
9abcf15
IGNITE-13190 Lost log message returned back.
ibessonov Oct 28, 2020
1c899d2
IGNITE-13190 MVCC suite 4.
ibessonov Oct 28, 2020
7e15622
IGNITE-13190 Few more tests fixed.
ibessonov Oct 28, 2020
99c5d99
IGNITE-13190 One more test fixed.
ibessonov Oct 28, 2020
8d96744
IGNITE-13190 Extra formatting removed. We don't need it, patch is alr…
ibessonov Oct 28, 2020
88464df
IGNITE-13190 Checkpoint listeners leak removed.
ibessonov Oct 29, 2020
2cf598f
Merge branch 'apache-master' into ignite-13190
ibessonov Oct 29, 2020
f32d2ac
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Oct 29, 2020
cbc5614
IGNITE-13190 Compilation error fixed.
ibessonov Oct 29, 2020
10af061
IGNITE-13190 New meta page version supported.
ibessonov Oct 29, 2020
7d2a375
IGNITE-13190 "Defragmentation started." message added.
ibessonov Oct 29, 2020
ce9d890
IGNITE-13190 Encryption test; Context removed completely.
ibessonov Oct 30, 2020
c5aedc3
IGNITE-13190 Missing checkpoint lock.
ibessonov Nov 5, 2020
4b16d75
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Nov 6, 2020
ce6715c
IGNITE-13190 Compilation error fixed
ibessonov Nov 6, 2020
adfbd5c
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Nov 12, 2020
c943aab
IGNITE-13684 Compilation errors fixed.
ibessonov Nov 12, 2020
9a28415
IGNITE-13190 Incompatible changes merged.
ibessonov Nov 12, 2020
96944ff
IGNITE-13190 Several TODO removed.
ibessonov Nov 12, 2020
893ed7d
IGNITE-13190 Removed some debug logging.
ibessonov Nov 12, 2020
e6b3830
IGNITE-13190 Unused code removed.
ibessonov Nov 13, 2020
d0efe52
IGNITE-13190 A bit of dead code removed.
ibessonov Nov 16, 2020
3fce806
IGNITE-13190 Several review remarks addressed.
ibessonov Nov 17, 2020
bb18443
IGNITE-13190 Several review remarks addressed #2.
ibessonov Nov 17, 2020
87fd6fc
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Nov 17, 2020
fb3b458
IGNITE-13190 Compilation errors.
ibessonov Nov 17, 2020
3c19a84
IGNITE-13190 Reconfiguring region size if defragmentation is needed
akalash Nov 18, 2020
58125c1
IGNITE-13190 Improved indexing tests.
ibessonov Nov 19, 2020
d9f3836
IGNITE-13190 LinkMapTest
ibessonov Nov 19, 2020
8382f6b
IGNITE-13190 LinkMapTest
ibessonov Nov 19, 2020
4809e35
IGNITE-13190 More fair regions configuration.
ibessonov Nov 24, 2020
cbcd198
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Nov 24, 2020
4ea97a9
IGNITE-13190 Fix of review remarks.
ibessonov Nov 25, 2020
b86f240
IGNITE-13190 Default changed.
ibessonov Nov 26, 2020
55b08fe
IGNITE-13190 Refactoring of indexing API.
ibessonov Nov 27, 2020
bc45e61
IGNITE-13190 Eliminated explicit busy lock usage.
ibessonov Nov 27, 2020
64fa01e
IGNITE-13190 More unchecked exceptions used.
ibessonov Nov 27, 2020
da4e14e
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Nov 27, 2020
8118ec4
IGNITE-13190 More review remarks addressed.
ibessonov Nov 30, 2020
1b7d8ee
IGNITE-13190 TimeTracker removed.
ibessonov Dec 1, 2020
c1c6747
Merge remote-tracking branch 'origin/master' into ignite-13190
ibessonov Dec 2, 2020
15554bd
IGNITE-13697 Test fixed
ibessonov Dec 2, 2020
1f5a1cf
IGNITE-13190 Unused class removed.
ibessonov Dec 3, 2020
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 @@ -81,6 +81,7 @@
import static org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition.DFLT_ATOMIC_CACHE_DELETE_HISTORY_SIZE;
import static org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition.DFLT_CACHE_REMOVE_ENTRIES_TTL;
import static org.apache.ignite.internal.processors.cache.mvcc.MvccCachingManager.DFLT_MVCC_TX_SIZE_CACHING_THRESHOLD;
import static org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.DFLT_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE;
import static org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.DFLT_PDS_WAL_REBALANCE_THRESHOLD;
import static org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory.DFLT_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE;
import static org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointWorkflow.DFLT_CHECKPOINT_PARALLEL_SORT_THRESHOLD;
Expand Down Expand Up @@ -1948,6 +1949,19 @@ public final class IgniteSystemProperties {
type = Boolean.class)
public static final String IGNITE_TEST_ENV = "IGNITE_TEST_ENV";

/**
* Defragmentation region size percentage of configured region size.
* This percentage will be calculated from largest configured region size and then proportionally subtracted
* from all configured regions.
*/
@SystemProperty(value = "Defragmentation region size percentage of configured region size. " +
"This percentage will be calculated from largest configured region size and then proportionally subtracted " +
"from all configured regions.",
type = Integer.class,
defaults = "" + DFLT_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE)
public static final String IGNITE_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE =
"IGNITE_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE";

/**
* Enforces singleton.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ else if (isMaintenanceMode()) {
*/
private void proceedWithMaintenance() {
for (Map.Entry<String, MaintenanceWorkflowCallback> cbE : workflowCallbacks.entrySet()) {
MaintenanceAction mntcAct = cbE.getValue().automaticAction();
MaintenanceAction<?> mntcAct = cbE.getValue().automaticAction();

if (mntcAct != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ void decrementSize(int cacheId) {
return grp.mvccEnabled() ? dataTree.isEmpty() : storageSize.get() == 0;
}
catch (IgniteCheckedException e) {
U.error(log, "Failed to perform operation.", e);
U.error(grp.shared().logger(IgniteCacheOffheapManagerImpl.class), "Failed to perform operation.", e);

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@
import org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress;
import org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointStatus;
import org.apache.ignite.internal.processors.cache.persistence.checkpoint.Checkpointer;
import org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager;
import org.apache.ignite.internal.processors.cache.persistence.checkpoint.ReservationReason;
import org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager;
import org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationPageReadWriteManager;
import org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationWorkflowCallback;
import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
import org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory;
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore;
Expand Down Expand Up @@ -145,6 +149,7 @@
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.SB;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiPredicate;
Expand All @@ -162,6 +167,7 @@

import static java.util.Objects.nonNull;
import static java.util.function.Function.identity;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_PREFER_WAL_REBALANCE;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_RECOVERY_SEMAPHORE_PERMITS;
Expand All @@ -178,7 +184,10 @@
import static org.apache.ignite.internal.processors.cache.persistence.CheckpointState.FINISHED;
import static org.apache.ignite.internal.processors.cache.persistence.CheckpointState.LOCK_RELEASED;
import static org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointReadWriteLock.CHECKPOINT_LOCK_HOLD_COUNT;
import static org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.DEFRAGMENTATION_MNTC_TASK_NAME;
import static org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters.fromStore;
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CORRUPTED_DATA_FILES_MNTC_TASK_NAME;
import static org.apache.ignite.internal.util.IgniteUtils.GB;
import static org.apache.ignite.internal.util.IgniteUtils.checkpointBufferSize;

/**
Expand Down Expand Up @@ -207,6 +216,12 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
/** Description of the system view for a {@link MetaStorage}. */
public static final String METASTORE_VIEW_DESC = "Local metastorage data";

/** */
public static final String DEFRAGMENTATION_PART_REGION_NAME = "defragPartitionsDataRegion";

/** */
public static final String DEFRAGMENTATION_MAPPING_REGION_NAME = "defragMappingDataRegion";

/**
* Threshold to calculate limit for pages list on-heap caches.
* <p>
Expand All @@ -223,6 +238,9 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
/** @see IgniteSystemProperties#IGNITE_PDS_WAL_REBALANCE_THRESHOLD */
public static final int DFLT_PDS_WAL_REBALANCE_THRESHOLD = 500;

/** @see IgniteSystemProperties#IGNITE_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE */
public static final int DFLT_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE = 60;

/** */
private final int walRebalanceThreshold =
getInteger(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, DFLT_PDS_WAL_REBALANCE_THRESHOLD);
Expand All @@ -234,6 +252,10 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
private final String throttlingPolicyOverride = IgniteSystemProperties.getString(
IgniteSystemProperties.IGNITE_OVERRIDE_WRITE_THROTTLING_ENABLED);

/** Defragmentation regions size percentage of configured ones. */
private final int defragmentationRegionSizePercentageOfConfiguredSize =
getInteger(IGNITE_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE, DFLT_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE);

/** */
private static final String MBEAN_NAME = "DataStorageMetrics";

Expand Down Expand Up @@ -318,6 +340,9 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
/** Lock for releasing history for preloading. */
private ReentrantLock releaseHistForPreloadingLock = new ReentrantLock();

/** */
private CachePartitionDefragmentationManager defrgMgr;

/** Data regions which should be checkpointed. */
protected final Set<DataRegion> checkpointedDataRegions = new GridConcurrentHashSet<>();

Expand Down Expand Up @@ -447,6 +472,32 @@ private DataRegionConfiguration createMetastoreDataRegionConfig(DataStorageConfi
return cfg;
}

/** */
private DataRegionConfiguration createDefragmentationDataRegionConfig(long regionSize) {
Mmuzaf marked this conversation as resolved.
Show resolved Hide resolved
DataRegionConfiguration cfg = new DataRegionConfiguration();

cfg.setName(DEFRAGMENTATION_PART_REGION_NAME);
cfg.setInitialSize(regionSize);
cfg.setMaxSize(regionSize);
cfg.setPersistenceEnabled(true);
cfg.setLazyMemoryAllocation(false);

return cfg;
}

/** */
private DataRegionConfiguration createDefragmentationMappingRegionConfig(long regionSize) {
DataRegionConfiguration cfg = new DataRegionConfiguration();

cfg.setName(DEFRAGMENTATION_MAPPING_REGION_NAME);
cfg.setInitialSize(regionSize);
cfg.setMaxSize(regionSize);
cfg.setPersistenceEnabled(true);
cfg.setLazyMemoryAllocation(false);

return cfg;
}

/** {@inheritDoc} */
@Override protected void start0() throws IgniteCheckedException {
super.start0();
Expand Down Expand Up @@ -497,6 +548,99 @@ private DataRegionConfiguration createMetastoreDataRegionConfig(DataStorageConfi
}
}

/** {@inheritDoc} */
@Override protected void initDataRegions(DataStorageConfiguration memCfg) throws IgniteCheckedException {
if (isDefragmentationScheduled() && !dataRegionsInitialized) {
//Region size configuration will be changed for defragmentation needs.
memCfg = configureDataRegionForDefragmentation(memCfg);
}

super.initDataRegions(memCfg);
}

/**
* Configure data regions:
* <p> Size of configured cache data regions will be decreased in order of freeing space for</p>
* <p>defragmentation needs. * New defragmentation regions will be created which size would be based on freed space
* from previous step.</p>
*
* @param memCfg Data storage configuration with data region configurations.
* @return New data storage configuration which contains data regions with changed size.
* @throws IgniteCheckedException If fail.
*/
private DataStorageConfiguration configureDataRegionForDefragmentation(
DataStorageConfiguration memCfg
) throws IgniteCheckedException {
List<DataRegionConfiguration> regionConfs = new ArrayList<>();

DataStorageConfiguration dataConf = memCfg;//not do the changes in-place it's better to make the copy of memCfg.

regionConfs.add(dataConf.getDefaultDataRegionConfiguration());

if (dataConf.getDataRegionConfigurations() != null)
regionConfs.addAll(Arrays.asList(dataConf.getDataRegionConfigurations()));

long totalDefrRegionSize = 0;
long totalRegionsSize = 0;

for (DataRegionConfiguration regionCfg : regionConfs) {
totalDefrRegionSize = Math.max(
totalDefrRegionSize,
(long)(regionCfg.getMaxSize() * 0.01 * defragmentationRegionSizePercentageOfConfiguredSize)
);

totalRegionsSize += regionCfg.getMaxSize();
}

double shrinkPercentage = 1d * (totalRegionsSize - totalDefrRegionSize) / totalRegionsSize;

for (DataRegionConfiguration region : regionConfs) {
long newSize = (long)(region.getMaxSize() * shrinkPercentage);
long newInitSize = Math.min(region.getInitialSize(), newSize);

log.info("Region size was reassigned by defragmentation reason: " +
"region = '" + region.getName() + "', " +
"oldInitialSize = '" + region.getInitialSize() + "', " +
"newInitialSize = '" + newInitSize + "', " +
"oldMaxSize = '" + region.getMaxSize() + "', " +
"newMaxSize = '" + newSize
);

region.setMaxSize(newSize);
region.setInitialSize(newInitSize);
region.setCheckpointPageBufferSize(0);
}

long mappingRegionSize = Math.min(GB, (long)(totalDefrRegionSize * 0.1));

checkpointedDataRegions.remove(
addDataRegion(
memCfg,
createDefragmentationDataRegionConfig(totalDefrRegionSize - mappingRegionSize),
true,
new DefragmentationPageReadWriteManager(cctx.kernalContext(), "defrgPartitionsStore")
)
);

checkpointedDataRegions.remove(
addDataRegion(
memCfg,
createDefragmentationMappingRegionConfig(mappingRegionSize),
true,
new DefragmentationPageReadWriteManager(cctx.kernalContext(), "defrgLinkMappingStore")
)
);

return dataConf;
}

/**
* @return {@code true} if maintenance mode is on and defragmentation task exists.
*/
private boolean isDefragmentationScheduled() {
return cctx.kernalContext().maintenanceRegistry().activeMaintenanceTask(DEFRAGMENTATION_MNTC_TASK_NAME) != null;
}

/** */
public Collection<DataRegion> checkpointedDataRegions() {
return checkpointedDataRegions;
Expand Down Expand Up @@ -603,10 +747,51 @@ private void releaseFileLock() {
fileLockHolder.close();
}

/** */
private void prepareCacheDefragmentation(List<Integer> cacheGroupIds) throws IgniteCheckedException {
GridKernalContext kernalCtx = cctx.kernalContext();
DataStorageConfiguration dsCfg = kernalCtx.config().getDataStorageConfiguration();

assert CU.isPersistenceEnabled(dsCfg);

List<DataRegion> regions = Arrays.asList(
dataRegion(DEFRAGMENTATION_MAPPING_REGION_NAME),
dataRegion(DEFRAGMENTATION_PART_REGION_NAME)
);

LightweightCheckpointManager lightCheckpointMgr = new LightweightCheckpointManager(
kernalCtx::log,
cctx.igniteInstanceName(),
"db-checkpoint-thread-defrag",
kernalCtx.workersRegistry(),
persistenceCfg,
() -> regions,
this::getPageMemoryForCacheGroup,
resolveThrottlingPolicy(),
snapshotMgr,
persistentStoreMetricsImpl(),
kernalCtx.longJvmPauseDetector(),
kernalCtx.failure(),
kernalCtx.cache()
);

lightCheckpointMgr.start();

defrgMgr = new CachePartitionDefragmentationManager(
cacheGroupIds,
cctx,
this,
(FilePageStoreManager)cctx.pageStore(),
checkpointManager,
lightCheckpointMgr,
persistenceCfg.getPageSize()
);
}

/** {@inheritDoc} */
@Override public DataRegion addDataRegion(DataStorageConfiguration dataStorageCfg, DataRegionConfiguration dataRegionCfg,
boolean trackable) throws IgniteCheckedException {
DataRegion region = super.addDataRegion(dataStorageCfg, dataRegionCfg, trackable);
boolean trackable, PageReadWriteManager pmPageMgr) throws IgniteCheckedException {
DataRegion region = super.addDataRegion(dataStorageCfg, dataRegionCfg, trackable, pmPageMgr);

checkpointedDataRegions.add(region);

Expand Down Expand Up @@ -636,6 +821,16 @@ private void readMetastore() throws IgniteCheckedException {
registerSystemView();

notifyMetastorageReadyForRead();

cctx.kernalContext().maintenanceRegistry()
.registerWorkflowCallbackIfTaskExists(
DEFRAGMENTATION_MNTC_TASK_NAME,
task -> {
prepareCacheDefragmentation(fromStore(task).cacheGroupIds());

return new DefragmentationWorkflowCallback(cctx.kernalContext()::log, defrgMgr);
}
);
}
finally {
metaStorage = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1357,8 +1357,19 @@ private void saveIndexReencryptionStatus(int grpId) throws IgniteCheckedExceptio
}

/** */
public GridSpinBusyLock busyLock() {
return busyLock;
public GridCacheDataStore createGridCacheDataStore(
Mmuzaf marked this conversation as resolved.
Show resolved Hide resolved
CacheGroupContext grpCtx,
int partId,
boolean exists,
IgniteLogger log
) {
return new GridCacheDataStore(
grpCtx,
partId,
true,
busyLock,
log
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
protected final Map<String, DataRegionMetrics> memMetricsMap = new ConcurrentHashMap<>();

/** */
private volatile boolean dataRegionsInitialized;
protected volatile boolean dataRegionsInitialized;

/** */
private volatile boolean dataRegionsStarted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
import org.apache.ignite.internal.processors.cache.persistence.DataRegion;
import org.apache.ignite.internal.processors.cache.persistence.DataStorageMetricsImpl;
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx;
import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl;
import org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteCacheSnapshotManager;
Expand Down Expand Up @@ -106,8 +105,7 @@ public LightweightCheckpointManager(
DataStorageMetricsImpl persStoreMetrics,
LongJVMPauseDetector longJvmPauseDetector,
FailureProcessor failureProcessor,
GridCacheProcessor cacheProcessor,
FilePageStoreManager pageStoreManager
GridCacheProcessor cacheProcessor
) throws IgniteCheckedException {
CheckpointReadWriteLock lock = new CheckpointReadWriteLock(logger);

Expand Down Expand Up @@ -139,7 +137,7 @@ public LightweightCheckpointManager(
logger,
snapshotMgr,
(pageMemEx, fullPage, buf, tag) ->
pageStoreManager.write(fullPage.groupId(), fullPage.pageId(), buf, tag, true),
pageMemEx.pageManager().write(fullPage.groupId(), fullPage.pageId(), buf, tag, true),
persStoreMetrics,
throttlingPolicy,
threadBuf,
Expand Down
Loading