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>>

    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

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

### Constructor Summary

Constructors
`protected` `AbstractWalRecordsIterator(IgniteLogger log, GridCacheSharedContext sharedCtx, RecordSerializer serializer, FileIOFactory ioFactory, int bufSize)`

### Method Summary

Methods
`protected void` `advance()` Switches records iterator to the next record.
`protected abstract FileWriteAheadLogManager.ReadFileHandle` `advanceSegment(FileWriteAheadLogManager.ReadFileHandle curWalSegment)` Switches records iterator to the next WAL segment as result of this method, new reference to segment should be returned.
`protected FileWriteAheadLogManager.ReadFileHandle` `closeCurrentWalSegment()` Closes and returns WAL segment (if any)
`protected void` `handleRecordException(Exception e, FileWALPointer ptr)` Handler for record deserialization exception
`protected FileWriteAheadLogManager.ReadFileHandle` `initReadHandle(FileWriteAheadLogManager.FileDescriptor desc, FileWALPointer start)`
`protected static FileWriteAheadLogManager.FileDescriptor[]` `loadFileDescriptors(File walFilesDir)` Scans provided folder for a WAL segment files
`protected boolean` `onHasNext()`
`protected IgniteBiTuple<WALPointer,WALRecord>` `onNext()`

### Methods inherited from class org.apache.ignite.internal.util.GridCloseableIteratorAdapter

`checkClosed, close, hasNextX, isClosed, nextX, onClose, 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

`iterator`

### Methods inherited from interface java.util.Iterator

`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

#### 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
                              RecordSerializer serializer,
                              @NotNull
                              FileIOFactory ioFactory,
                              int bufSize)

Parameters:
  `log` - Logger
  `sharedCtx` - Shared context
  `serializer` - Serializer of current version to read headers.
  `bufSize` - buffer for reading records size

### Method Detail

#### loadFileDescriptors

    protected static FileWriteAheadLogManager.FileDescriptor[] loadFileDescriptors(@NotNull
                                                                File walFilesDir)
                                                                            throws IgniteCheckedException

Scans provided folder for a WAL segment files

Parameters:
  `walFilesDir` - directory to scan
Returns:
  found WAL file descriptors
Throws:
  `IgniteCheckedException`

#### 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.

#### 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 FileWriteAheadLogManager.ReadFileHandle closeCurrentWalSegment()
                                                                      throws IgniteCheckedException

Closes and returns WAL segment (if any)

Returns:
  closed handle
Throws:
  `IgniteCheckedException` - if IO failed

#### advanceSegment

    protected abstract FileWriteAheadLogManager.ReadFileHandle advanceSegment(@Nullable
                                                         FileWriteAheadLogManager.ReadFileHandle 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

#### 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 FileWriteAheadLogManager.ReadFileHandle initReadHandle(@NotNull
                                                         FileWriteAheadLogManager.FileDescriptor 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.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.1.0
Release Date | : July 20 2017