public class FileTierPartitionState extends java.lang.Object implements TierPartitionState, java.lang.AutoCloseable
TierPartitionState.AppendResult, TierPartitionState.RestoreResult
Constructor and Description |
---|
FileTierPartitionState(java.io.File dir,
kafka.server.LogDirFailureChannel logDirFailureChannel,
org.apache.kafka.common.TopicPartition topicPartition,
boolean tieringEnabled) |
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.
|
java.io.File |
dir()
The directory where the TierPartition is stored on disk.
|
long |
endOffset()
Return the uncommitted end offset spanned by the TierPartitionState.
|
java.util.Collection<TierObjectMetadata> |
fencedSegments() |
void |
flush()
flush data contained in this TierPartitionState to disk.
|
java.lang.String |
flushedPath() |
boolean |
isTieringEnabled() |
static java.util.Optional<FileTierPartitionIterator> |
iterator(org.apache.kafka.common.TopicPartition topicPartition,
java.nio.channels.FileChannel channel) |
OffsetAndEpoch |
lastLocalMaterializedSrcOffsetAndEpoch()
Return the last materialized source offset and epoch
|
java.util.concurrent.Future<TierObjectMetadata> |
materializeUpto(long targetOffset)
Sets up a listener for this tier partition state for use by the replica fetcher.
|
java.util.concurrent.CompletableFuture<java.util.Optional<TierObjectMetadata>> |
materializeUptoEpoch(int targetEpoch)
Sets up a listener for this tier partition state.
|
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.
|
java.util.Optional<TierObjectMetadata> |
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.
|
static java.util.Optional<Header> |
readHeader(java.nio.channels.FileChannel channel) |
TierPartitionState.RestoreResult |
restoreState(TierPartitionForceRestore metadata,
java.nio.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.
|
org.apache.kafka.common.utils.CloseableIterator<TierObjectMetadata> |
segments()
Get an iterator for all readable tiered segments.
|
org.apache.kafka.common.utils.CloseableIterator<TierObjectMetadata> |
segments(long from,
long to)
Get an iterator for all readable tiered segments in a given range.
|
void |
setTieringDisabled()
Reset the tier(ing) enabled flag at TierPartitionState.
|
boolean |
setTieringEnabled()
Called when tiering is enabled for this tier topic partition.
|
boolean |
setTopicId(java.util.UUID topicId)
Sets the TopicIdPartition for this TierPartitionState.
|
java.util.Optional<java.lang.Long> |
startOffset()
Determine start offset spanned by the TierPartitionState.
|
TierPartitionStatus |
status()
Return the current status of the TierPartitionState.
|
int |
tierEpoch()
Return the current tierEpoch.
|
java.util.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.
|
java.lang.String |
toString() |
long |
totalSize()
Sum the size of all segment spanned by this TierPartitionState.
|
void |
updateDir(java.io.File dir)
Update the directory reference for the log and indices in this segment.
|
public FileTierPartitionState(java.io.File dir, kafka.server.LogDirFailureChannel logDirFailureChannel, org.apache.kafka.common.TopicPartition topicPartition, boolean tieringEnabled) throws java.io.IOException
java.io.IOException
public org.apache.kafka.common.TopicPartition topicPartition()
TierPartitionState
topicPartition
in interface TierPartitionState
public java.util.Optional<TopicIdPartition> topicIdPartition()
TierPartitionState
topicIdPartition
in interface TierPartitionState
public boolean setTopicId(java.util.UUID topicId) throws java.io.IOException
TierPartitionState
setTopicId
in interface TierPartitionState
topicId
- The topic id to assignjava.io.IOException
public boolean isTieringEnabled()
isTieringEnabled
in interface TierPartitionState
public boolean setTieringEnabled() throws java.io.IOException
TierPartitionState
setTieringEnabled
in interface TierPartitionState
java.io.IOException
public void setTieringDisabled()
TierPartitionState
setTieringDisabled
in interface TierPartitionState
public java.util.Optional<java.lang.Long> startOffset()
TierPartitionState
startOffset
in interface TierPartitionState
public long endOffset()
TierPartitionState
endOffset
in interface TierPartitionState
public long committedEndOffset()
TierPartitionState
committedEndOffset
in interface TierPartitionState
public long totalSize()
TierPartitionState
totalSize
in interface TierPartitionState
public void flush() throws java.io.IOException
TierPartitionState
flush
in interface TierPartitionState
java.io.IOException
public int tierEpoch()
TierPartitionState
tierEpoch
in interface TierPartitionState
public java.io.File dir()
TierPartitionState
dir
in interface TierPartitionState
public void delete() throws java.io.IOException
TierPartitionState
delete
in interface TierPartitionState
java.io.IOException
public void updateDir(java.io.File dir)
TierPartitionState
updateDir
in interface TierPartitionState
dir
- The new directorypublic TierPartitionState.RestoreResult restoreState(TierPartitionForceRestore metadata, java.nio.ByteBuffer targetState, TierPartitionStatus targetStatus, OffsetAndEpoch offsetAndEpoch)
TierPartitionState
restoreState
in interface TierPartitionState
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 void closeHandlers() throws java.io.IOException
closeHandlers
in interface TierPartitionState
java.io.IOException
public TierPartitionStatus status()
TierPartitionState
status
in interface TierPartitionState
public void beginCatchup()
TierPartitionState
beginCatchup
in interface TierPartitionState
public void onCatchUpComplete()
TierPartitionState
onCatchUpComplete
in interface TierPartitionState
public int numSegments(long from, long to)
TierPartitionState
numSegments
in interface TierPartitionState
from
- 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()
TierPartitionState
numSegments
in interface TierPartitionState
public java.util.concurrent.Future<TierObjectMetadata> materializeUpto(long targetOffset) throws java.io.IOException
TierPartitionState
materializeUpto
in interface TierPartitionState
targetOffset
- the offset awaiting materializationjava.io.IOException
public java.util.concurrent.CompletableFuture<java.util.Optional<TierObjectMetadata>> materializeUptoEpoch(int targetEpoch) throws java.io.IOException
TierPartitionState
materializeUptoEpoch
in interface TierPartitionState
targetEpoch
- the leader epoch awaiting materializationjava.io.IOException
public void close() throws java.io.IOException
TierPartitionState
close
in interface java.lang.AutoCloseable
close
in interface TierPartitionState
java.io.IOException
public TierPartitionState.AppendResult append(AbstractTierMetadata metadata, OffsetAndEpoch offsetAndEpoch)
TierPartitionState
append
in interface TierPartitionState
metadata
- AbstractTierMetadata entry to be appended to the tier partition log.offsetAndEpoch
- Offset and epoch corresponding to this metadata entrypublic org.apache.kafka.common.utils.CloseableIterator<TierObjectMetadata> segments()
TierPartitionState
segments
in interface TierPartitionState
public org.apache.kafka.common.utils.CloseableIterator<TierObjectMetadata> segments(long from, long to)
TierPartitionState
segments
in interface TierPartitionState
from
- 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 java.util.Optional<TierObjectMetadata> metadata(long targetOffset) throws java.io.IOException
TierPartitionState
metadata
in interface TierPartitionState
targetOffset
- the target offset to lookup the overlapping or next metadata for.java.io.IOException
- if disk error encounteredpublic OffsetAndEpoch lastLocalMaterializedSrcOffsetAndEpoch()
TierPartitionState
lastLocalMaterializedSrcOffsetAndEpoch
in interface TierPartitionState
public java.lang.String flushedPath()
public java.util.Collection<TierObjectMetadata> fencedSegments()
fencedSegments
in interface TierPartitionState
public java.lang.String toString()
toString
in class java.lang.Object
public static java.util.Optional<Header> readHeader(java.nio.channels.FileChannel channel) throws java.io.IOException
java.io.IOException
public static java.util.Optional<FileTierPartitionIterator> iterator(org.apache.kafka.common.TopicPartition topicPartition, java.nio.channels.FileChannel channel) throws java.io.IOException
java.io.IOException
public boolean mayContainTieredData()
TierPartitionState
mayContainTieredData
in interface TierPartitionState
public boolean maybeOpenChannelOnOffsetTieredException() throws java.io.IOException
TierPartitionState
maybeOpenChannelOnOffsetTieredException
in interface TierPartitionState
java.io.IOException