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

## 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
`protected static interface` `AbstractWalRecordsIterator.AbstractFileDescriptor`
`protected static interface` `AbstractWalRecordsIterator.AbstractReadFileHandle`

### Field Summary

Fields
`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
`protected long` `curWalSegmIdx` Current WAL segment absolute index.
`protected FileIOFactory` `ioFactory` Factory to provide I/O interfaces for read/write operations with files
`protected IgniteLogger` `log` Logger
`protected GridCacheSharedContext` `sharedCtx` Shared context for creating serializer of required version and grid name access.

### Constructor Summary

Constructors
`protected` `AbstractWalRecordsIterator(IgniteLogger log, GridCacheSharedContext sharedCtx, RecordSerializerFactory serializerFactory, FileIOFactory ioFactory, int bufSize)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`protected void` `advance()` Switches records iterator to the next record.
`protected abstract AbstractWalRecordsIterator.AbstractReadFileHandle` `advanceSegment(AbstractWalRecordsIterator.AbstractReadFileHandle curWalSegment)` Switches records iterator to the next WAL segment as result of this method, new reference to segment should be returned.
`protected AbstractWalRecordsIterator.AbstractReadFileHandle` `closeCurrentWalSegment()` Closes and returns WAL segment (if any)
`protected abstract AbstractWalRecordsIterator.AbstractReadFileHandle` `createReadFileHandle(FileIO fileIO, long idx, RecordSerializer ser, FileInput in)`
`protected void` `handleRecordException(Exception e, FileWALPointer ptr)` Handler for record deserialization exception
`protected AbstractWalRecordsIterator.AbstractReadFileHandle` `initReadHandle(AbstractWalRecordsIterator.AbstractFileDescriptor desc, FileWALPointer start)`
`protected void` `onClose()` Invoked on iterator close.
`protected boolean` `onHasNext()`
`protected IgniteBiTuple<WALPointer,WALRecord>` `onNext()`
`protected WALRecord` `postProcessRecord(WALRecord rec)` Performs final conversions with record loaded from WAL.

### 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 IgniteLogger log

Logger

#### sharedCtx

    @NotNull
    protected final 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 FileIOFactory ioFactory

Factory to provide I/O interfaces for read/write operations with files

### Constructor Detail

#### AbstractWalRecordsIterator

    protected AbstractWalRecordsIterator(@NotNull
                                         IgniteLogger log,
                                         @NotNull
                                         GridCacheSharedContext sharedCtx,
                                         @NotNull
                                         RecordSerializerFactory serializerFactory,
                                         @NotNull
                                         FileIOFactory ioFactory,
                                         int bufSize)

Parameters:
  `log` - Logger.
  `sharedCtx` - Shared context.
  `serializerFactory` - Serializer of current version to read headers.
  `ioFactory` - ioFactory for file IO access.
  `bufSize` - buffer for reading records size.

### Method Detail

#### onNext

    protected IgniteBiTuple<WALPointer,WALRecord> onNext()
                                                  throws IgniteCheckedException

Specified by:
  `onNext` in class `GridCloseableIteratorAdapter<IgniteBiTuple<WALPointer,WALRecord>>`
Returns:
  Next element.
Throws:
  `IgniteCheckedException` - If failed.

#### onHasNext

    protected boolean onHasNext()
                         throws IgniteCheckedException

Specified by:
  `onHasNext` in class `GridCloseableIteratorAdapter<IgniteBiTuple<WALPointer,WALRecord>>`
Returns:
  `True` if iterator has next element.
Throws:
  `IgniteCheckedException` - If failed.

#### onClose

    protected void onClose()
                    throws IgniteCheckedException

Invoked on iterator close.

Overrides:
  `onClose` in class `GridCloseableIteratorAdapter<IgniteBiTuple<WALPointer,WALRecord>>`
Throws:
  `IgniteCheckedException` - If closing failed.

#### advance

    protected void advance()
                    throws IgniteCheckedException

Switches records iterator to the next record.

- `curRec` will be updated.
- If end of segment reached, switch to new segment is called. `currWalSegment` will be updated.

`advance()` runs a step ahead `GridIteratorAdapter.next()`

Throws:
  `IgniteCheckedException` - If failed.

#### closeCurrentWalSegment

    @Nullable
    protected 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
                                                                                        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

#### postProcessRecord

    @NotNull
    protected WALRecord postProcessRecord(@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 void handleRecordException(@NotNull
                                         Exception e,
                                         @Nullable
                                         FileWALPointer ptr)

Handler for record deserialization exception

Parameters:
  `e` - problem from records reading
  `ptr` - file pointer was accessed

#### initReadHandle

    protected AbstractWalRecordsIterator.AbstractReadFileHandle initReadHandle(@NotNull
                                                                               AbstractWalRecordsIterator.AbstractFileDescriptor desc,
                                                                               @Nullable
                                                                               FileWALPointer start)
                                                                        throws IgniteCheckedException,
                                                                               FileNotFoundException

Parameters:
  `desc` - File descriptor.
  `start` - Optional start pointer. Null means read from the beginning
Returns:
  Initialized file handle.
Throws:
  `FileNotFoundException` - If segment file is missing.
  `IgniteCheckedException` - If initialized failed due to another unexpected error.

#### createReadFileHandle

    protected abstract AbstractWalRecordsIterator.AbstractReadFileHandle createReadFileHandle(FileIO fileIO,
                                                                                              long idx,
                                                                                              RecordSerializer ser,
                                                                                              FileInput in)

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.5.0
Release Date | : May 23 2018