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 Description SegmentAware(IgniteLogger log, int walSegmentsCnt, boolean compactionEnabled, long minWalArchiveSize, long maxWalArchiveSize)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSize(long idx, long sizeChange)Adding the WAL segment size in the archive.longawaitAvailableTruncateArchive()Waiting for segment truncation to be available.voidawaitExceedMaxArchiveSize(long max)Waiting for exceeding the maximum WAL archive size.voidawaitSegment(long absSegIdx)Waiting until current WAL index will be greater or equal than given one.voidawaitSegmentArchived(long awaitIdx)Method will wait archivation of particular WAL segment index.voidawaitSegmentCompressed(long awaitIdx)Method will wait activation of particular WAL segment index.longcurAbsWalIdx()voidcurAbsWalIdx(long curAbsWalIdx)Update current WAL index.voidforceInterrupt()Interrupt waiting on related objects.voidinterrupt()Interrupt waiting on related objects.longlastArchivedAbsoluteIndex()voidlastCheckpointIdx(long absIdx)Update segment of last completed checkpoint.longlastCompressedIdx()longlastTruncatedArchiveIdx()Getting last truncated segment.voidlastTruncatedArchiveIdx(long absIdx)Update last truncated segment.booleanlock(long absIdx)Segment lock.booleanlocked(long absIdx)Check if WAL segment locked (protected from move to archive).voidmarkAsMovedToArchive(long toArchive)Mark segment as moved to archive under lock.booleanminLockIndex(long absIdx)Increasing minimum segment index after that can be locked.booleanminReserveIndex(long absIdx)Increasing minimum segment index after that can be reserved.longnextAbsoluteSegmentIndex()Calculate next segment index or wait if needed.voidonSegmentCompressed(long compressedIdx)Callback after segment compression finish.voidrelease(long absIdx)booleanreserve(long absIdx)Segment reservation.booleanreserved(long absIdx)Checks if segment is currently reserved (protected from deletion during WAL cleanup).voidreset()Reset interrupted flag.voidresetWalArchiveSizes()Reset the current and reserved WAL archive sizes.voidsetLastArchivedAbsoluteIndex(long lastAbsArchivedIdx)voidstartAutoReleaseSegments()Start automatically releasing segments when reachingDataStorageConfiguration.getMaxWalArchiveSize().voidunlock(long absIdx)longwaitNextSegmentForArchivation()Waiting until archivation of next segment will be allowed.longwaitNextSegmentToCompress()Pessimistically tries to reserve segment for compression in order to avoid concurrent truncation.
-
-
-
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 orDataStorageConfiguration.UNLIMITED_WAL_ARCHIVE.maxWalArchiveSize- Maximum size of the WAL archive in bytes orDataStorageConfiguration.UNLIMITED_WAL_ARCHIVE.
-
-
Method Detail
-
awaitSegment
public void awaitSegment(long absSegIdx) throws IgniteInterruptedCheckedExceptionWaiting until current WAL index will be greater or equal than given one.- Parameters:
absSegIdx- Target WAL index.- Throws:
IgniteInterruptedCheckedException
-
nextAbsoluteSegmentIndex
public long nextAbsoluteSegmentIndex() throws IgniteInterruptedCheckedExceptionCalculate 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 IgniteInterruptedCheckedExceptionWaiting until archivation of next segment will be allowed.
-
markAsMovedToArchive
public void markAsMovedToArchive(long toArchive) throws IgniteInterruptedCheckedExceptionMark 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 IgniteInterruptedCheckedExceptionMethod will wait archivation of particular WAL segment index.- Parameters:
awaitIdx- absolute indexlastArchivedAbsoluteIndex()to become true.- Throws:
IgniteInterruptedCheckedException- if interrupted.
-
awaitSegmentCompressed
public void awaitSegmentCompressed(long awaitIdx) throws IgniteInterruptedCheckedExceptionMethod will wait activation of particular WAL segment index.- Parameters:
awaitIdx- absolute indexlastCompressedIdx()to become true.- Throws:
IgniteInterruptedCheckedException- if interrupted.
-
waitNextSegmentToCompress
public long waitNextSegmentToCompress() throws IgniteInterruptedCheckedExceptionPessimistically tries to reserve segment for compression in order to avoid concurrent truncation. Waits if there's no segment to archive right now.
-
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 theminimum.- Parameters:
absIdx- Index for reservation.- Returns:
Trueif 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:
Trueif 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:
Trueif index is locked.
-
lock
public boolean lock(long absIdx)
Segment lock. It will be successful if segment is>than thelast archived.- Parameters:
absIdx- Index to lock.- Returns:
Trueif 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:
Trueif 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:
Trueif 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 IgniteInterruptedCheckedExceptionWaiting for exceeding the maximum WAL archive size. To track size of WAL archive, need to useaddSize(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 IgniteInterruptedCheckedExceptionWaiting for segment truncation to be available. To get the number of segments available for truncation, uselastTruncatedArchiveIdx(long),lastCheckpointIdx(long),reserve(long)andlastArchivedAbsoluteIndex()(to restart the node correctly) and is calculated aslastTruncatedArchiveIdx-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 reachingDataStorageConfiguration.getMaxWalArchiveSize().
-
-