org.apache.ignite.internal.processors.cache.persistence.checkpoint

## Class CheckpointHistory

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory

    public class CheckpointHistory
    extends Object

Checkpoint history. Holds chronological ordered map with `CheckpointEntries`. Data is loaded from corresponding checkpoint directory. This directory holds files for checkpoint start and end.

### Field Summary

Fields
`static int` `DFLT_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addCheckpoint(CheckpointEntry entry, Map<Integer,CacheState> cacheStates)` Adds checkpoint entry after the corresponding WAL record has been written to WAL.
`Collection<Long>` `checkpoints()`
`Collection<Long>` `checkpoints(boolean descending)`
`EarliestCheckpointMapSnapshot` `earliestCheckpointsMapSnapshot()` Creates a snapshot of `earliestCp` map.
`WALPointer` `firstCheckpointPointer()`
`boolean` `hasSpace()`
`void` `initialize(List<CheckpointEntry> checkpoints, EarliestCheckpointMapSnapshot snapshot)`
`boolean` `isCheckpointApplicableForGroup(int grpId, CheckpointEntry cp)` Checkpoint is not applicable when: 1) WAL was disabled somewhere after given checkpoint. 2) Checkpoint doesn't contain specified `grpId`.
`@Nullable CheckpointEntry` `lastCheckpoint()`
`List<CheckpointEntry>` `onCheckpointFinished(org.apache.ignite.internal.processors.cache.persistence.checkpoint.Checkpoint chp)` Logs and clears checkpoint history after checkpoint finish.
`List<CheckpointEntry>` `onWalTruncated(WALPointer highBound)` Clears checkpoint history after WAL truncation.
`List<CheckpointEntry>` `removeCheckpoints(int countToRemove)` Removes checkpoints from history.
`CheckpointEntry` `removeFromEarliestCheckpoints(Integer grpId)` Removes last checkpoint in history from the earliest checkpoints map by group id and returns the latest checkpoint in the history.
`CheckpointHistoryResult` `searchAndReserveCheckpoints(Map<Integer,Set<Integer>> groupsAndPartitions)` Finds and reserves earliest valid checkpoint for each of given groups and partitions.
`Map<GroupPartitionId,CheckpointEntry>` `searchCheckpointEntry(Map<T2<Integer,Integer>,Long> searchCntrMap)` Tries to search for a WAL pointer for the given partition counter start.
`@Nullable WALPointer` `searchEarliestWalPointer(int grpId, Map<Integer,Long> partsCounter, long margin)` Search the earliest WAL pointer for particular group, matching by counter for partitions.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DFLT_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE

    public static final int DFLT_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE

See Also:
  `IgniteSystemProperties.IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE`, Constant Field Values

### Method Detail

#### initialize

    public void initialize(List<CheckpointEntry> checkpoints,
                           EarliestCheckpointMapSnapshot snapshot)

Parameters:
  `checkpoints` - Checkpoints.
  `snapshot` - Earliest checkpoint map snapshot.

#### lastCheckpoint

    @Nullable
    public @Nullable CheckpointEntry lastCheckpoint()

Returns:
  Last checkpoint entry if exists.

#### firstCheckpointPointer

    public WALPointer firstCheckpointPointer()

Returns:
  First checkpoint WAL pointer if exists. Otherwise `null`.

#### checkpoints

    public Collection<Long> checkpoints(boolean descending)

Returns:
  Collection of checkpoint timestamps.

#### checkpoints

    public Collection<Long> checkpoints()

#### addCheckpoint

    public void addCheckpoint(CheckpointEntry entry,
                              Map<Integer,CacheState> cacheStates)

Adds checkpoint entry after the corresponding WAL record has been written to WAL. The checkpoint itself is not finished yet.

Parameters:
  `entry` - Entry to add.
  `cacheStates` - Cache states map.

#### removeFromEarliestCheckpoints

    public CheckpointEntry removeFromEarliestCheckpoints(Integer grpId)

Removes last checkpoint in history from the earliest checkpoints map by group id and returns the latest checkpoint in the history.

Parameters:
  `grpId` - Group id.
Returns:
  Latest checkpoint in the history.

#### hasSpace

    public boolean hasSpace()

Returns:
  `true` if there is space for next checkpoint.

#### onWalTruncated

    public List<CheckpointEntry> onWalTruncated(WALPointer highBound)

Clears checkpoint history after WAL truncation.

Parameters:
  `highBound` - Upper bound.
Returns:
  List of checkpoint entries removed from history.

#### removeCheckpoints

    public List<CheckpointEntry> removeCheckpoints(int countToRemove)

Removes checkpoints from history.

Returns:
  List of checkpoint entries removed from history.

#### onCheckpointFinished

    public List<CheckpointEntry> onCheckpointFinished(org.apache.ignite.internal.processors.cache.persistence.checkpoint.Checkpoint chp)

Logs and clears checkpoint history after checkpoint finish.

Parameters:
  `chp` - Finished checkpoint.
Returns:
  List of checkpoints removed from history.

#### searchEarliestWalPointer

    @Nullable
    public @Nullable WALPointer searchEarliestWalPointer(int grpId,
                                                                   Map<Integer,Long> partsCounter,
                                                                   long margin)
                                                            throws IgniteCheckedException

Search the earliest WAL pointer for particular group, matching by counter for partitions.

Parameters:
  `grpId` - Group id.
  `partsCounter` - Partition mapped to update counter.
  `margin` - Margin pointer.
Returns:
  Earliest WAL pointer for group specified.
Throws:
  `IgniteCheckedException`

#### searchCheckpointEntry

    public Map<GroupPartitionId,CheckpointEntry> searchCheckpointEntry(Map<T2<Integer,Integer>,Long> searchCntrMap)

Tries to search for a WAL pointer for the given partition counter start.

Parameters:
  `searchCntrMap` - Search map contains (Group Id, partition, counter).
Returns:
  Map of group-partition on checkpoint entry or empty map if nothing found.

#### searchAndReserveCheckpoints

    public CheckpointHistoryResult searchAndReserveCheckpoints(Map<Integer,Set<Integer>> groupsAndPartitions)

Finds and reserves earliest valid checkpoint for each of given groups and partitions.

Parameters:
  `groupsAndPartitions` - Groups and partitions to find and reserve earliest valid checkpoint.
Returns:
  Checkpoint history reult: Map (groupId, Reason (the reason why reservation cannot be made deeper): Map (partitionId, earliest valid checkpoint to history search)) and reserved checkpoint.

#### isCheckpointApplicableForGroup

    public boolean isCheckpointApplicableForGroup(int grpId,
                                                  CheckpointEntry cp)
                                           throws IgniteCheckedException

Checkpoint is not applicable when: 1) WAL was disabled somewhere after given checkpoint. 2) Checkpoint doesn't contain specified `grpId`.

Parameters:
  `grpId` - Group ID.
  `cp` - Checkpoint.
Throws:
  `IgniteCheckedException`

#### earliestCheckpointsMapSnapshot

    public EarliestCheckpointMapSnapshot earliestCheckpointsMapSnapshot()

Creates a snapshot of `earliestCp` map. Guarded by checkpoint read lock.

Returns:
  Snapshot of a map.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.14.0
Release Date | : September 29 2022