org.apache.ignite.internal.processors.cache.persistence.wal.aware

## Class SegmentAware

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.persistence.wal.aware.SegmentAware

    public class SegmentAware
    extends Object

Holder of actual information of latest manipulation on WAL segments.

### Constructor Summary

Constructors
Constructor and Description
`SegmentAware(IgniteLogger log, int walSegmentsCnt, boolean compactionEnabled, long minWalArchiveSize, long maxWalArchiveSize)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addSize(long idx, long sizeChange)` Adding the WAL segment size in the archive.
`long` `awaitAvailableTruncateArchive()` Waiting for segment truncation to be available.
`void` `awaitExceedMaxArchiveSize(long max)` Waiting for exceeding the maximum WAL archive size.
`void` `awaitSegment(long absSegIdx)` Waiting until current WAL index will be greater or equal than given one.
`void` `awaitSegmentArchived(long awaitIdx)` Method will wait activation of particular WAL segment index.
`long` `curAbsWalIdx()`
`void` `curAbsWalIdx(long curAbsWalIdx)` Update current WAL index.
`void` `forceInterrupt()` Interrupt waiting on related objects.
`void` `interrupt()` Interrupt waiting on related objects.
`long` `lastArchivedAbsoluteIndex()`
`void` `lastCheckpointIdx(long absIdx)` Update segment of last completed checkpoint.
`long` `lastCompressedIdx()`
`long` `lastTruncatedArchiveIdx()` Getting last truncated segment.
`void` `lastTruncatedArchiveIdx(long absIdx)` Update last truncated segment.
`boolean` `lock(long absIdx)` Segment lock.
`boolean` `locked(long absIdx)` Check if WAL segment locked (protected from move to archive).
`void` `markAsMovedToArchive(long toArchive)` Mark segment as moved to archive under lock.
`boolean` `minLockIndex(long absIdx)` Increasing minimum segment index after that can be locked.
`boolean` `minReserveIndex(long absIdx)` Increasing minimum segment index after that can be reserved.
`long` `nextAbsoluteSegmentIndex()` Calculate next segment index or wait if needed.
`void` `onSegmentCompressed(long compressedIdx)` Callback after segment compression finish.
`void` `release(long absIdx)`
`boolean` `reserve(long absIdx)` Segment reservation.
`boolean` `reserved(long absIdx)` Checks if segment is currently reserved (protected from deletion during WAL cleanup).
`void` `reset()` Reset interrupted flag.
`void` `resetWalArchiveSizes()` Reset the current and reserved WAL archive sizes.
`void` `setLastArchivedAbsoluteIndex(long lastAbsArchivedIdx)`
`void` `startAutoReleaseSegments()` Start automatically releasing segments when reaching `DataStorageConfiguration.getMaxWalArchiveSize()`.
`void` `unlock(long absIdx)`
`long` `waitNextSegmentForArchivation()` Waiting until archivation of next segment will be allowed.
`long` `waitNextSegmentToCompress()` Pessimistically tries to reserve segment for compression in order to avoid concurrent truncation.

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

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

### Constructor Detail

#### SegmentAware

    public SegmentAware(IgniteLogger log,
                        int walSegmentsCnt,
                        boolean compactionEnabled,
                        long minWalArchiveSize,
                        long maxWalArchiveSize)

Constructor.

Parameters:
  `log` - Logger.
  `walSegmentsCnt` - Total WAL segments count.
  `compactionEnabled` - Is wal compaction enabled.
  `minWalArchiveSize` - Minimum size of the WAL archive in bytes or `DataStorageConfiguration.UNLIMITED_WAL_ARCHIVE`.
  `maxWalArchiveSize` - Maximum size of the WAL archive in bytes or `DataStorageConfiguration.UNLIMITED_WAL_ARCHIVE`.

### Method Detail

#### awaitSegment

    public void awaitSegment(long absSegIdx)
                      throws IgniteInterruptedCheckedException

Waiting until current WAL index will be greater or equal than given one.

Parameters:
  `absSegIdx` - Target WAL index.
Throws:
  `IgniteInterruptedCheckedException`

#### nextAbsoluteSegmentIndex

    public long nextAbsoluteSegmentIndex()
                                  throws IgniteInterruptedCheckedException

Calculate next segment index or wait if needed.

Returns:
  Next absolute segment index.
Throws:
  `IgniteInterruptedCheckedException`

#### curAbsWalIdx

    public long curAbsWalIdx()

Returns:
  Current WAL index.

#### waitNextSegmentForArchivation

    public long waitNextSegmentForArchivation()
                                       throws IgniteInterruptedCheckedException

Waiting until archivation of next segment will be allowed.

Throws:
  `IgniteInterruptedCheckedException`

#### markAsMovedToArchive

    public void markAsMovedToArchive(long toArchive)
                              throws IgniteInterruptedCheckedException

Mark segment as moved to archive under lock.

Parameters:
  `toArchive` - Segment which was should be moved to archive.
Throws:
  `IgniteInterruptedCheckedException` - if interrupted during waiting.

#### awaitSegmentArchived

    public void awaitSegmentArchived(long awaitIdx)
                              throws IgniteInterruptedCheckedException

Method will wait activation of particular WAL segment index.

Parameters:
  `awaitIdx` - absolute index `lastArchivedAbsoluteIndex()` to become true.
Throws:
  `IgniteInterruptedCheckedException` - if interrupted.

#### waitNextSegmentToCompress

    public long waitNextSegmentToCompress()
                                   throws IgniteInterruptedCheckedException

Pessimistically tries to reserve segment for compression in order to avoid concurrent truncation. Waits if there's no segment to archive right now.

Throws:
  `IgniteInterruptedCheckedException`

#### onSegmentCompressed

    public void onSegmentCompressed(long compressedIdx)

Callback after segment compression finish.

Parameters:
  `compressedIdx` - Index of compressed segment.

#### lastCompressedIdx

    public long lastCompressedIdx()

Returns:
  Last compressed segment.

#### curAbsWalIdx

    public void curAbsWalIdx(long curAbsWalIdx)

Update current WAL index.

Parameters:
  `curAbsWalIdx` - New current WAL index.

#### lastTruncatedArchiveIdx

    public void lastTruncatedArchiveIdx(long absIdx)

Update last truncated segment.

Parameters:
  `absIdx` - Absolut segment index.

#### lastTruncatedArchiveIdx

    public long lastTruncatedArchiveIdx()

Getting last truncated segment.

Returns:
  Absolut segment index.

#### setLastArchivedAbsoluteIndex

    public void setLastArchivedAbsoluteIndex(long lastAbsArchivedIdx)

Parameters:
  `lastAbsArchivedIdx` - New value of last archived segment index.

#### lastArchivedAbsoluteIndex

    public long lastArchivedAbsoluteIndex()

Returns:
  Last archived segment absolute index.

#### reserve

    public boolean reserve(long absIdx)

Segment reservation. It will be successful if segment is `>` than the `minimum`.

Parameters:
  `absIdx` - Index for reservation.
Returns:
  `True` if the reservation was successful.

#### reserved

    public boolean reserved(long absIdx)

Checks if segment is currently reserved (protected from deletion during WAL cleanup).

Parameters:
  `absIdx` - Index for check reservation.
Returns:
  `True` if index is reserved.

#### release

    public void release(long absIdx)

Parameters:
  `absIdx` - Reserved index.

#### locked

    public boolean locked(long absIdx)

Check if WAL segment locked (protected from move to archive).

Parameters:
  `absIdx` - Index for check locking.
Returns:
  `True` if index is locked.

#### lock

    public boolean lock(long absIdx)

Segment lock. It will be successful if segment is `>` than the `last archived`.

Parameters:
  `absIdx` - Index to lock.
Returns:
  `True` if the lock was successful.

#### unlock

    public void unlock(long absIdx)

Parameters:
  `absIdx` - Index to unlock.

#### reset

    public void reset()

Reset interrupted flag.

#### interrupt

    public void interrupt()

Interrupt waiting on related objects.

#### forceInterrupt

    public void forceInterrupt()

Interrupt waiting on related objects.

#### minReserveIndex

    public boolean minReserveIndex(long absIdx)

Increasing minimum segment index after that can be reserved. Value will be updated if it is greater than the current one. If segment is already reserved, the update will fail.

Parameters:
  `absIdx` - Absolut segment index.
Returns:
  `True` if update is successful.

#### minLockIndex

    public boolean minLockIndex(long absIdx)

Increasing minimum segment index after that can be locked. Value will be updated if it is greater than the current one. If segment is already reserved, the update will fail.

Parameters:
  `absIdx` - Absolut segment index.
Returns:
  `True` if update is successful.

#### addSize

    public void addSize(long idx,
                        long sizeChange)

Adding the WAL segment size in the archive.

Parameters:
  `idx` - Absolut segment index.
  `sizeChange` - Segment size in bytes.

#### resetWalArchiveSizes

    public void resetWalArchiveSizes()

Reset the current and reserved WAL archive sizes.

#### awaitExceedMaxArchiveSize

    public void awaitExceedMaxArchiveSize(long max)
                                   throws IgniteInterruptedCheckedException

Waiting for exceeding the maximum WAL archive size. To track size of WAL archive, need to use `addSize(long, long)`.

Parameters:
  `max` - Maximum WAL archive size in bytes.
Throws:
  `IgniteInterruptedCheckedException` - If it was interrupted.

#### lastCheckpointIdx

    public void lastCheckpointIdx(long absIdx)

Update segment of last completed checkpoint. Required for binary recovery.

Parameters:
  `absIdx` - Absolut segment index.

#### awaitAvailableTruncateArchive

    public long awaitAvailableTruncateArchive()
                                       throws IgniteInterruptedCheckedException

Waiting for segment truncation to be available. To get the number of segments available for truncation, use `lastTruncatedArchiveIdx(long)`, `lastCheckpointIdx(long)`, `reserve(long)` and `lastArchivedAbsoluteIndex()` (to restart the node correctly) and is calculated as `lastTruncatedArchiveIdx` - `min(lastCheckpointIdx, reserve, lastArchivedAbsoluteIndex)`.

Returns:
  Number of segments available to truncate.
Throws:
  `IgniteInterruptedCheckedException` - If it was interrupted.

#### startAutoReleaseSegments

    public void startAutoReleaseSegments()

Start automatically releasing segments when reaching `DataStorageConfiguration.getMaxWalArchiveSize()`.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.12.0
Release Date | : January 10 2022