public class FileTierPartitionState extends Object implements TierPartitionState, AutoCloseable
| Modifier and Type | Class and Description |
|---|---|
static interface |
FileTierPartitionState.MaterializationListener |
TierPartitionState.AppendResult, TierPartitionState.RecoveryOperation, TierPartitionState.RestoreResult| Modifier and Type | Field and Description |
|---|---|
static short |
SUPER_BLOCK_LENGTH_ADLER |
static short |
SUPER_BLOCK_LENGTH_NO_CHECKSUM |
| Constructor and Description |
|---|
FileTierPartitionState(File dir,
kafka.server.LogDirFailureChannel logDirFailureChannel,
org.apache.kafka.common.TopicPartition topicPartition,
boolean tieringEnabled,
kafka.utils.Scheduler scheduler,
boolean checksumEnabled) |
| Modifier and Type | Method and Description |
|---|---|
TierPartitionState.AppendResult |
append(AbstractTierMetadata metadata,
OffsetAndEpoch offsetAndEpoch)
Appends abstract metadata to the tier partition.
|
void |
beginCatchup()
Begin catchup phase for tier partition state.
|
void |
close()
Close TierPartition, flushing to disk.
|
void |
closeHandlers() |
long |
committedEndOffset()
Return the end offset spanned by the TierPartitionState that has been committed to disk.
|
void |
delete()
Delete this TierPartitionState from local storage.
|
File |
dir()
The directory where the TierPartition is stored on disk.
|
long |
endOffset()
Return the uncommitted end offset spanned by the TierPartitionState.
|
Collection<kafka.log.TierLogSegment> |
fencedSegments() |
boolean |
flush()
Flush data contained in this TierPartitionState to disk.
|
String |
flushedPath() |
kafka.common.FollowerRestorePoint |
followerRestorePoint(long localLogStartOffset)
Fetch and return the FollowerRestorePoint for the given localLogStartOffset.
|
TierPartitionState.RestoreResult |
forceRestoreState(TierPartitionForceRestore metadata,
ByteBuffer targetState,
TierPartitionStatus targetStatus,
OffsetAndEpoch offsetAndEpoch)
Performs a TierPartitionState restore, swapping the current state file
from buffer and replacing any internal state with the contents of the new TierPartitionState,
setting the TierPartitionStatus of the state to status.
|
boolean |
isErrorStatusReachedViaFenceEvent() |
boolean |
isTieringEnabled() |
static Optional<FileTierPartitionIterator> |
iterator(org.apache.kafka.common.TopicPartition topicPartition,
CheckedFileIO channel) |
OffsetAndEpoch |
lastLocalMaterializedSrcOffsetAndEpoch()
Return the last materialized source offset and epoch
|
long |
materializationLag()
Return the current tier materialization lag.
|
CompletableFuture<Optional<kafka.log.TierLogSegment>> |
materializeUptoLeaderEpoch(int targetEpoch)
Listen for the flushed materialization state to reach or surpass the provided LeaderEpoch.
|
CompletableFuture<kafka.log.TierLogSegment> |
materializeUptoObjectIdAndRestoreEpoch(long upperBoundEndOffset,
UUID targetObjectId,
int targetRestoreEpoch)
Listen for the flushed materialization state to materialize a fully uploaded segment matching the provided targetObjectId.
|
CompletableFuture<kafka.log.TierLogSegment> |
materializeUptoOffset(long targetOffset)
Listen for the flushed materialization state to reach or surpass the provided targetOffset.
|
boolean |
maybeOpenChannelOnOffsetTieredException()
Called when a replica receives OFFSET_TIERED exception while replicating from leader.
|
boolean |
mayContainTieredData()
Indicates if a partition may have some tiered data, essentially whether tiered storage is currently enabled or was enabled
earlier for this partition.
|
Optional<kafka.log.TierLogSegment> |
metadata(long targetOffset)
Lookup the TierObjectMetadata which will contain data for a target offset.
|
int |
numSegments()
Scan the ObjectMetadata (segment) entries in this tier partition, and return the count.
|
int |
numSegments(long from,
long to)
Count of the number of segments lying within a range
|
void |
onCatchUpComplete()
Mark catchup completed for tier partition state.
|
Optional<SegmentState> |
previousMetadataBeforeOffset(long targetStartOffset)
Get the in-memory metadata for the immediate previous segment (even beyond retention) to target startOffset
|
TierPartitionState.RestoreResult |
processRestoreEvents(AbstractTierMetadata event,
Optional<ByteBuffer> targetStateOpt,
TierPartitionStatus targetStatus,
OffsetAndEpoch offsetAndEpoch)
Processes one of the recovery events TierPartitionForceRestore or TierPartitionUnfreezeLogStartOffset.
|
TierPartitionState.RestoreResult |
processUnfreezeLogStartOffset(TierPartitionUnfreezeLogStartOffset metadata,
TierPartitionStatus restoreStatus,
OffsetAndEpoch sourceOffsetAndEpoch)
Unfreeze log start offset at the MergedLog.
|
static Optional<Header> |
readHeader(CheckedFileIO channel) |
List<SegmentState> |
segmentInMemoryMetadataRange(long from,
long to)
List of all the segment (minimal) metadata whose startOffset is in the range (even if they are beyond retention).
|
Iterator<kafka.log.TierLogSegment> |
segments()
Get an iterator for all readable tiered segments.
|
Iterator<kafka.log.TierLogSegment> |
segments(long from,
long to)
Get an iterator for all readable tiered segments in a given range.
|
void |
setTieredPartitionRecoveryWorkflowCb(Consumer<TierPartitionState.RecoveryOperation> cb)
Sets the callback function used by tier partition state to communicate to the MergedLog layer during recovery of
a tiered partition.
|
void |
setTieringDisabled()
Reset the tier(ing) enabled flag at TierPartitionState.
|
boolean |
setTieringEnabled()
Called when tiering is enabled for this tier topic partition.
|
boolean |
setTopicId(UUID topicId)
Sets the TopicIdPartition for this TierPartitionState.
|
Optional<Long> |
startOffset()
Determine start offset spanned by the TierPartitionState.
|
TierPartitionStatus |
status()
Return the current status of the TierPartitionState.
|
int |
tierEpoch()
Return the current tierEpoch.
|
Optional<TopicIdPartition> |
topicIdPartition()
Optional TopicIdPartition corresponding to this TierPartition
If one has not been set, returns empty
|
org.apache.kafka.common.TopicPartition |
topicPartition()
The topic-partition corresponding to this TierPartition.
|
String |
toString() |
long |
totalSize()
Sum the size of all segment spanned by this TierPartitionState.
|
CompletableFuture<Boolean> |
trackMetadataInitialization(int targetLeaderEpoch)
Listen for the flushed materialization state to materialize up to or past the provided leader epoch.
|
void |
updateDir(File dir)
Update the directory reference for the log and indices in this segment.
|
boolean |
validateChecksum()
Validates the integrity by computing the checksum and validating the checksum.
|
static void |
writeHeader(CheckedFileIO channel,
Header header) |
public static final short SUPER_BLOCK_LENGTH_ADLER
public static final short SUPER_BLOCK_LENGTH_NO_CHECKSUM
public FileTierPartitionState(File dir, kafka.server.LogDirFailureChannel logDirFailureChannel, org.apache.kafka.common.TopicPartition topicPartition, boolean tieringEnabled, kafka.utils.Scheduler scheduler, boolean checksumEnabled) throws IOException
IOExceptionpublic org.apache.kafka.common.TopicPartition topicPartition()
TierPartitionStatetopicPartition in interface TierPartitionStatepublic Optional<TopicIdPartition> topicIdPartition()
TierPartitionStatetopicIdPartition in interface TierPartitionStatepublic boolean setTopicId(UUID topicId) throws IOException
TierPartitionStatesetTopicId in interface TierPartitionStatetopicId - The topic id to assignIOExceptionpublic boolean isTieringEnabled()
isTieringEnabled in interface TierPartitionStatepublic boolean setTieringEnabled()
throws IOException
TierPartitionStatesetTieringEnabled in interface TierPartitionStateIOExceptionpublic void setTieringDisabled()
TierPartitionStatesetTieringDisabled in interface TierPartitionStatepublic Optional<Long> startOffset()
TierPartitionStatestartOffset in interface TierPartitionStatepublic long endOffset()
TierPartitionStateendOffset in interface TierPartitionStatepublic long committedEndOffset()
TierPartitionStatecommittedEndOffset in interface TierPartitionStatepublic long totalSize()
TierPartitionStatetotalSize in interface TierPartitionStatepublic boolean flush()
throws IOException
TierPartitionStateflush in interface TierPartitionStateIOException - if the flush operation failedpublic boolean validateChecksum()
throws IOException,
InstantiationException,
IllegalAccessException
TierPartitionStatevalidateChecksum in interface TierPartitionStateIOExceptionInstantiationExceptionIllegalAccessExceptionpublic int tierEpoch()
TierPartitionStatetierEpoch in interface TierPartitionStatepublic File dir()
TierPartitionStatedir in interface TierPartitionStatepublic void delete()
throws IOException
TierPartitionStatedelete in interface TierPartitionStateIOExceptionpublic void updateDir(File dir)
TierPartitionStateupdateDir in interface TierPartitionStatedir - The new directorypublic TierPartitionState.RestoreResult forceRestoreState(TierPartitionForceRestore metadata, ByteBuffer targetState, TierPartitionStatus targetStatus, OffsetAndEpoch offsetAndEpoch)
metadata - the TierPartitionForceRestore metadata including the coordinates and
metadata about the state to be restored.targetState - ByteBuffer containing the contents of the TierPartitionState to restoretargetStatus - the status that the TierPartitionState will be transitioned to upon
successful restorationoffsetAndEpoch - Offset and epoch corresponding to this metadata entrypublic TierPartitionState.RestoreResult processRestoreEvents(AbstractTierMetadata event, Optional<ByteBuffer> targetStateOpt, TierPartitionStatus targetStatus, OffsetAndEpoch offsetAndEpoch)
TierPartitionStateprocessRestoreEvents in interface TierPartitionStateevent - the metadata event to be processedtargetStateOpt - ByteBuffer containing the contents of the TierPartitionState to restoretargetStatus - the status that the TierPartitionState will be transitioned to upon
successful restorationoffsetAndEpoch - Offset and epoch corresponding to this metadata entrypublic TierPartitionState.RestoreResult processUnfreezeLogStartOffset(TierPartitionUnfreezeLogStartOffset metadata, TierPartitionStatus restoreStatus, OffsetAndEpoch sourceOffsetAndEpoch) throws org.apache.kafka.common.errors.KafkaStorageException
metadata - metadata event to unfreeze log start offsetrestoreStatus - TierPartitionStatus to restore the topic partition to, once log start offset is unfrozen.
Valid values are TierPartitionStatus.ONLINE and TierPartitionStatus.CATCHUPsourceOffsetAndEpoch - offset and epoch for the metadata eventorg.apache.kafka.common.errors.KafkaStorageExceptionpublic void closeHandlers()
throws IOException
closeHandlers in interface TierPartitionStateIOExceptionpublic TierPartitionStatus status()
TierPartitionStatestatus in interface TierPartitionStatepublic long materializationLag()
TierPartitionStatematerializationLag in interface TierPartitionStatepublic void beginCatchup()
TierPartitionStatebeginCatchup in interface TierPartitionStatepublic void onCatchUpComplete()
TierPartitionStateonCatchUpComplete in interface TierPartitionStatepublic int numSegments(long from,
long to)
TierPartitionStatenumSegments in interface TierPartitionStatefrom - Start of the range, include segment which contains "from" (inclusive)to - End of the range, upper bound exclusive offset to include or the end of the log if "to" is past the endpublic int numSegments()
TierPartitionStatenumSegments in interface TierPartitionStatepublic CompletableFuture<kafka.log.TierLogSegment> materializeUptoOffset(long targetOffset) throws IOException
materializeUptoOffset in interface TierPartitionStatetargetOffset - The minimum materialized offset required to complete this listener.IOException - Propagated from the listener.public CompletableFuture<kafka.log.TierLogSegment> materializeUptoObjectIdAndRestoreEpoch(long upperBoundEndOffset, UUID targetObjectId, int targetRestoreEpoch) throws IOException
materializeUptoObjectIdAndRestoreEpoch in interface TierPartitionStateupperBoundEndOffset - The upper bound end offset of the targetObjectId. This is used to set an upper bound for which the targetObjectId (at the targetRestoreEpoch) will not be found above.
The upperBoundEndOffset is also used to provide approximate materialization progress for the materialization lag metric.targetObjectId - The objectId of the target TierObjectMetadata. The listener will only complete if this objectId is found.targetRestoreEpoch - The target TierPartitionState restore epoch. The listener will only complete if materialization has made it up to or surpassed this restore epoch.IOException - Propagated from the listener.public CompletableFuture<Optional<kafka.log.TierLogSegment>> materializeUptoLeaderEpoch(int targetEpoch) throws IOException
materializeUptoLeaderEpoch in interface TierPartitionStatetargetEpoch - The minimum LeaderEpoch required to complete this listener.IOException - Propagated from the listener.public CompletableFuture<Boolean> trackMetadataInitialization(int targetLeaderEpoch) throws IOException
trackMetadataInitialization in interface TierPartitionStatetargetLeaderEpoch - The minimum leader epoch required to complete this listener.IllegalStateException - Thrown if there was an existing metadata initialization listener registered.IOException - Propagated from the listener.public void close()
throws IOException
TierPartitionStateclose in interface AutoCloseableclose in interface TierPartitionStateIOExceptionpublic TierPartitionState.AppendResult append(AbstractTierMetadata metadata, OffsetAndEpoch offsetAndEpoch)
TierPartitionStateappend in interface TierPartitionStatemetadata - AbstractTierMetadata entry to be appended to the tier partition log.offsetAndEpoch - Offset and epoch corresponding to this metadata entrypublic Iterator<kafka.log.TierLogSegment> segments()
TierPartitionStatesegments in interface TierPartitionStatepublic Iterator<kafka.log.TierLogSegment> segments(long from, long to)
TierPartitionStatesegments in interface TierPartitionStatefrom - Start of the range, include segment which contains "from" (inclusive)to - End of the range, upper bound exclusive offset to include or the end of the log if "to" is past the endpublic List<SegmentState> segmentInMemoryMetadataRange(long from, long to)
TierPartitionStatesegmentInMemoryMetadataRange in interface TierPartitionStatefrom - Inclusive startOffset positionto - Inclusive endOffset positionpublic Optional<SegmentState> previousMetadataBeforeOffset(long targetStartOffset)
TierPartitionStatepreviousMetadataBeforeOffset in interface TierPartitionStatetargetStartOffset - target startOffsetpublic kafka.common.FollowerRestorePoint followerRestorePoint(long localLogStartOffset)
followerRestorePoint in interface TierPartitionStatelocalLogStartOffset - target startOffsetpublic Optional<kafka.log.TierLogSegment> metadata(long targetOffset) throws IOException
TierPartitionStatemetadata in interface TierPartitionStatetargetOffset - the target offset to lookup the overlapping or next metadata for.IOException - if disk error encounteredpublic OffsetAndEpoch lastLocalMaterializedSrcOffsetAndEpoch()
TierPartitionStatelastLocalMaterializedSrcOffsetAndEpoch in interface TierPartitionStatepublic String flushedPath()
public Collection<kafka.log.TierLogSegment> fencedSegments()
fencedSegments in interface TierPartitionStatepublic static Optional<Header> readHeader(CheckedFileIO channel) throws IOException
IOExceptionpublic static Optional<FileTierPartitionIterator> iterator(org.apache.kafka.common.TopicPartition topicPartition, CheckedFileIO channel) throws IOException
IOExceptionpublic boolean mayContainTieredData()
TierPartitionStatemayContainTieredData in interface TierPartitionStatepublic boolean maybeOpenChannelOnOffsetTieredException()
throws IOException
TierPartitionStatemaybeOpenChannelOnOffsetTieredException in interface TierPartitionStateIOExceptionpublic static void writeHeader(CheckedFileIO channel, Header header) throws IOException
IOExceptionpublic void setTieredPartitionRecoveryWorkflowCb(Consumer<TierPartitionState.RecoveryOperation> cb)
TierPartitionStatesetTieredPartitionRecoveryWorkflowCb in interface TierPartitionStatecb - callback function that takes a TierPartitionState.RecoveryOperation as a parameterpublic boolean isErrorStatusReachedViaFenceEvent()