Class AbstractWalRecordsIterator
- java.lang.Object
-
- org.apache.ignite.internal.util.lang.GridIteratorAdapter<T>
-
- org.apache.ignite.internal.util.GridCloseableIteratorAdapter<IgniteBiTuple<WALPointer,WALRecord>>
-
- org.apache.ignite.internal.processors.cache.persistence.wal.AbstractWalRecordsIterator
-
- All Implemented Interfaces:
Serializable,AutoCloseable,Iterable<IgniteBiTuple<WALPointer,WALRecord>>,Iterator<IgniteBiTuple<WALPointer,WALRecord>>,WALIterator,GridSerializableIterator<IgniteBiTuple<WALPointer,WALRecord>>,GridCloseableIterator<IgniteBiTuple<WALPointer,WALRecord>>,GridIterator<IgniteBiTuple<WALPointer,WALRecord>>,IgniteSpiCloseableIterator<IgniteBiTuple<WALPointer,WALRecord>>
- Direct Known Subclasses:
SingleSegmentLogicalRecordsIterator
public abstract class AbstractWalRecordsIterator extends GridCloseableIteratorAdapter<IgniteBiTuple<WALPointer,WALRecord>> implements WALIterator
Iterator over WAL segments. This abstract class provides most functionality for reading records in log. Subclasses are to override segment switching functionality- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceAbstractWalRecordsIterator.AbstractFileDescriptorprotected static interfaceAbstractWalRecordsIterator.AbstractReadFileHandle
-
Field Summary
Fields Modifier and Type Field Description protected IgniteBiTuple<WALPointer,WALRecord>curRecCurrent record preloaded, to be returned on next()
Normally this should be not null because advance() method should already prepare some valueprotected longcurWalSegmIdxCurrent WAL segment absolute index.protected @Nullable WALPointerhighBoundOptional inclusive high bound.protected @NotNull FileIOFactoryioFactoryFactory to provide I/O interfaces for read/write operations with filesprotected @NotNull IgniteLoggerlogLoggerprotected @NotNull GridCacheSharedContextsharedCtxShared context for creating serializer of required version and grid name access.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractWalRecordsIterator(@NotNull IgniteLogger log, @NotNull GridCacheSharedContext sharedCtx, @NotNull RecordSerializerFactory serializerFactory, @NotNull FileIOFactory ioFactory, int initialReadBufferSize, @Nullable WALPointer highBound, SegmentFileInputFactory segmentFileInputFactory)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidadvance()Switches records iterator to the next record.protected IgniteBiTuple<WALPointer,WALRecord>advanceRecord(@Nullable AbstractWalRecordsIterator.AbstractReadFileHandle hnd)Switches to new record.protected abstract AbstractWalRecordsIterator.AbstractReadFileHandleadvanceSegment(@Nullable AbstractWalRecordsIterator.AbstractReadFileHandle curWalSegment)Switches records iterator to the next WAL segment as result of this method, new reference to segment should be returned.protected @Nullable AbstractWalRecordsIterator.AbstractReadFileHandlecloseCurrentWalSegment()Closes and returns WAL segment (if any)protected abstract AbstractWalRecordsIterator.AbstractReadFileHandlecreateReadFileHandle(SegmentIO fileIO, RecordSerializer ser, FileInput in)protected IgniteCheckedExceptionhandleRecordException(@NotNull Exception e, @Nullable WALPointer ptr)Handler for record deserialization exception.protected AbstractWalRecordsIterator.AbstractReadFileHandleinitReadHandle(@NotNull AbstractWalRecordsIterator.AbstractFileDescriptor desc, @Nullable WALPointer start)Assumes file descriptor will be opened in this method.protected AbstractWalRecordsIterator.AbstractReadFileHandleinitReadHandle(@NotNull AbstractWalRecordsIterator.AbstractFileDescriptor desc, @Nullable WALPointer start, @NotNull SegmentIO fileIO, @NotNull SegmentHeader segmentHeader)Assumes fileIO will be closed in this method in case of error occurred.Optional<WALPointer>lastRead()protected voidonClose()Invoked on iterator close.protected booleanonHasNext()protected IgniteBiTuple<WALPointer,WALRecord>onNext()protected @NotNull WALRecordpostProcessRecord(@NotNull WALRecord rec)Performs final conversions with record loaded from WAL.protected IgniteCheckedExceptionvalidateTailReachedException(WalSegmentTailReachedException tailReachedException, AbstractWalRecordsIterator.AbstractReadFileHandle currWalSegment)-
Methods inherited from class org.apache.ignite.internal.util.GridCloseableIteratorAdapter
checkClosed, close, hasNextX, isClosed, nextX, onRemove, removeX
-
Methods inherited from class org.apache.ignite.internal.util.lang.GridIteratorAdapter
hasNext, iterator, next, remove
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.internal.util.lang.GridCloseableIterator
close, isClosed
-
Methods inherited from interface org.apache.ignite.internal.util.lang.GridIterator
hasNextX, nextX, removeX
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
-
-
-
Field Detail
-
curRec
protected IgniteBiTuple<WALPointer,WALRecord> curRec
Current record preloaded, to be returned on next()
Normally this should be not null because advance() method should already prepare some value
-
curWalSegmIdx
protected long curWalSegmIdx
Current WAL segment absolute index.
Determined as lowest number of file at start, is changed during advance segment
-
log
@NotNull protected final @NotNull IgniteLogger log
Logger
-
sharedCtx
@NotNull protected final @NotNull GridCacheSharedContext sharedCtx
Shared context for creating serializer of required version and grid name access. Also cacheObjects processor from this context may be used to covert Data entry key and value from its binary representation into objects.
-
ioFactory
@NotNull protected final @NotNull FileIOFactory ioFactory
Factory to provide I/O interfaces for read/write operations with files
-
highBound
@Nullable protected final @Nullable WALPointer highBound
Optional inclusive high bound.
-
-
Constructor Detail
-
AbstractWalRecordsIterator
protected AbstractWalRecordsIterator(@NotNull @NotNull IgniteLogger log, @NotNull @NotNull GridCacheSharedContext sharedCtx, @NotNull @NotNull RecordSerializerFactory serializerFactory, @NotNull @NotNull FileIOFactory ioFactory, int initialReadBufferSize, @Nullable @Nullable WALPointer highBound, SegmentFileInputFactory segmentFileInputFactory)- Parameters:
log- Logger.sharedCtx- Shared context.serializerFactory- Serializer of current version to read headers.ioFactory- ioFactory for file IO access.initialReadBufferSize- buffer for reading records size.highBound- Optional inclusive high bound.segmentFileInputFactory- Factory to provide I/O interfaces for read primitives with files.
-
-
Method Detail
-
onNext
protected IgniteBiTuple<WALPointer,WALRecord> onNext() throws IgniteCheckedException
- Specified by:
onNextin classGridCloseableIteratorAdapter<IgniteBiTuple<WALPointer,WALRecord>>- Returns:
- Next element.
- Throws:
IgniteCheckedException- If failed.
-
onHasNext
protected boolean onHasNext() throws IgniteCheckedException- Specified by:
onHasNextin classGridCloseableIteratorAdapter<IgniteBiTuple<WALPointer,WALRecord>>- Returns:
Trueif iterator has next element.- Throws:
IgniteCheckedException- If failed.
-
onClose
protected void onClose() throws IgniteCheckedExceptionInvoked on iterator close.- Overrides:
onClosein classGridCloseableIteratorAdapter<IgniteBiTuple<WALPointer,WALRecord>>- Throws:
IgniteCheckedException- If closing failed.
-
advance
protected void advance() throws IgniteCheckedExceptionSwitches records iterator to the next record.curRecwill be updated.- If end of
segment reached, switch to new segment is called.
currWalSegmentwill be updated.
advance()runs a step aheadGridIteratorAdapter.next()- Throws:
IgniteCheckedException- If failed.
-
lastRead
public Optional<WALPointer> lastRead()
- Specified by:
lastReadin interfaceWALIterator- Returns:
- Pointer to the last record returned by the
Iterator.next()method. If records are filtered by theIgniteWalIteratorFactory.IteratorParametersBuilder.filter(IgniteBiPredicate)then pointer to the last valid record returned.
-
validateTailReachedException
protected IgniteCheckedException validateTailReachedException(WalSegmentTailReachedException tailReachedException, AbstractWalRecordsIterator.AbstractReadFileHandle currWalSegment)
- Parameters:
tailReachedException- Tail reached exception.currWalSegment- Current WAL segment read handler.- Returns:
- If need to throw exception after validation.
-
closeCurrentWalSegment
@Nullable protected @Nullable AbstractWalRecordsIterator.AbstractReadFileHandle closeCurrentWalSegment() throws IgniteCheckedException
Closes and returns WAL segment (if any)- Returns:
- closed handle
- Throws:
IgniteCheckedException- if IO failed
-
advanceSegment
protected abstract AbstractWalRecordsIterator.AbstractReadFileHandle advanceSegment(@Nullable @Nullable AbstractWalRecordsIterator.AbstractReadFileHandle curWalSegment) throws IgniteCheckedException
Switches records iterator to the next WAL segment as result of this method, new reference to segment should be returned. Null for current handle means stop of iteration.- Parameters:
curWalSegment- current open WAL segment or null if there is no open segment yet- Returns:
- new WAL segment to read or null for stop iteration
- Throws:
IgniteCheckedException- if reading failed
-
advanceRecord
protected IgniteBiTuple<WALPointer,WALRecord> advanceRecord(@Nullable @Nullable AbstractWalRecordsIterator.AbstractReadFileHandle hnd) throws IgniteCheckedException
Switches to new record.- Parameters:
hnd- currently opened read handle.- Returns:
- next advanced record.
- Throws:
IgniteCheckedException
-
postProcessRecord
@NotNull protected @NotNull WALRecord postProcessRecord(@NotNull @NotNull WALRecord rec)
Performs final conversions with record loaded from WAL. To be overridden by subclasses if any processing required.- Parameters:
rec- record to post process.- Returns:
- post processed record.
-
handleRecordException
protected IgniteCheckedException handleRecordException(@NotNull @NotNull Exception e, @Nullable @Nullable WALPointer ptr)
Handler for record deserialization exception.- Parameters:
e- problem from records readingptr- file pointer was accessed- Returns:
nullif the error was handled and we can go ahead,IgniteCheckedExceptionif the error was not handled, and we should stop the iteration.
-
initReadHandle
protected AbstractWalRecordsIterator.AbstractReadFileHandle initReadHandle(@NotNull @NotNull AbstractWalRecordsIterator.AbstractFileDescriptor desc, @Nullable @Nullable WALPointer start, @NotNull @NotNull SegmentIO fileIO, @NotNull @NotNull SegmentHeader segmentHeader) throws IgniteCheckedException
Assumes fileIO will be closed in this method in case of error occurred.- Parameters:
desc- File descriptor.start- Optional start pointer. Null means read from the beginning.fileIO- fileIO associated with file descriptorsegmentHeader- read segment header from fileIO- Returns:
- Initialized file read header.
- Throws:
IgniteCheckedException- If initialized failed due to another unexpected error.
-
initReadHandle
protected AbstractWalRecordsIterator.AbstractReadFileHandle initReadHandle(@NotNull @NotNull AbstractWalRecordsIterator.AbstractFileDescriptor desc, @Nullable @Nullable WALPointer start) throws IgniteCheckedException, FileNotFoundException
Assumes file descriptor will be opened in this method. The caller of this method must be responsible for closing opened file descriptor File descriptor will be closed ONLY in case of error occurred.- Parameters:
desc- File descriptor.start- Optional start pointer. Null means read from the beginning- Returns:
- Initialized file read header.
- Throws:
FileNotFoundException- If segment file is missing.IgniteCheckedException- If initialized failed due to another unexpected error.
-
createReadFileHandle
protected abstract AbstractWalRecordsIterator.AbstractReadFileHandle createReadFileHandle(SegmentIO fileIO, RecordSerializer ser, FileInput in)
-
-