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

## Class RecordV1Serializer

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer

All Implemented Interfaces:
  RecordSerializer

    public class RecordV1Serializer
    extends Object
    implements RecordSerializer

Record V1 serializer. Stores records in following format:

- Record type from `Enum.ordinal()` incremented by 1
- WAL pointer to double check consistency
- Data
- CRC or zero padding

### Field Summary

Fields
`static int` `CRC_SIZE` Length of CRC value
`static int` `FILE_WAL_POINTER_SIZE` Length of WAL Pointer: Index (8) + File offset (4).
`static int` `HEADER_RECORD_SIZE` Total length of HEADER record.
`static int` `REC_TYPE_SIZE` Length of Type
`static boolean` `skipCrc` Skip CRC calculation/check flag

### Constructor Summary

Constructors
Constructor and Description
`RecordV1Serializer(RecordDataV1Serializer dataSerializer, boolean writePointer, boolean marshalledMode, boolean skipPositionCheck, IgniteBiPredicate<WALRecord.RecordType,WALPointer> recordFilter)` Create an instance of V1 serializer.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static void` `putPosition(ByteBuffer buf, FileWALPointer ptr)` Saves position, WAL pointer (requires `FILE_WAL_POINTER_SIZE` bytes)
`static FileWALPointer` `readPosition(DataInput in)`
`WALRecord` `readRecord(FileInput in0, WALPointer expPtr)` Loads record from input
`static SegmentHeader` `readSegmentHeader(SegmentIO io, SegmentFileInputFactory segmentFileInputFactory)` Reads stored record from provided `io`.
`int` `size(WALRecord record)` Calculates record size in byte including expected wal pointer, CRC and type field
`int` `version()`
`boolean` `writePointer()` Flag to write (or not) wal pointer to record
`void` `writeRecord(WALRecord rec, ByteBuffer buf)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### REC_TYPE_SIZE

    public static final int REC_TYPE_SIZE

Length of Type

See Also:
  Constant Field Values

#### FILE_WAL_POINTER_SIZE

    public static final int FILE_WAL_POINTER_SIZE

Length of WAL Pointer: Index (8) + File offset (4).

See Also:
  Constant Field Values

#### CRC_SIZE

    public static final int CRC_SIZE

Length of CRC value

See Also:
  Constant Field Values

#### HEADER_RECORD_SIZE

    public static final int HEADER_RECORD_SIZE

Total length of HEADER record.

See Also:
  Constant Field Values

#### skipCrc

    public static boolean skipCrc

Skip CRC calculation/check flag

### Constructor Detail

#### RecordV1Serializer

    public RecordV1Serializer(RecordDataV1Serializer dataSerializer,
                              boolean writePointer,
                              boolean marshalledMode,
                              boolean skipPositionCheck,
                              IgniteBiPredicate<WALRecord.RecordType,WALPointer> recordFilter)

Create an instance of V1 serializer.

Parameters:
  `dataSerializer` - V1 data serializer.
  `writePointer` - Write pointer.
  `marshalledMode` - Marshalled mode.
  `skipPositionCheck` - Skip position check mode.
  `recordFilter` - Record type filter. `FilteredRecord` is deserialized instead of original record

### Method Detail

#### version

    public int version()

Specified by:
  `version` in interface `RecordSerializer`
Returns:
  serializer version

#### writePointer

    public boolean writePointer()

Flag to write (or not) wal pointer to record

Specified by:
  `writePointer` in interface `RecordSerializer`

#### writeRecord

    public void writeRecord(WALRecord rec,
                            ByteBuffer buf)
                     throws IgniteCheckedException

Specified by:
  `writeRecord` in interface `RecordSerializer`
Parameters:
  `rec` - Entry to write.
  `buf` - Buffer.
Throws:
  `IgniteCheckedException`

#### readRecord

    public WALRecord readRecord(FileInput in0,
                                WALPointer expPtr)
                         throws IOException,
                                IgniteCheckedException

Loads record from input

Specified by:
  `readRecord` in interface `RecordSerializer`
Parameters:
  `in0` - Data input to read data from.
  `expPtr` - expected WAL pointer for record. Used to validate actual position against expected from the file
Returns:
  Read entry.
Throws:
  `IOException`
  `IgniteCheckedException`

#### size

    public int size(WALRecord record)
             throws IgniteCheckedException

Calculates record size in byte including expected wal pointer, CRC and type field

Specified by:
  `size` in interface `RecordSerializer`
Parameters:
  `record` - Record.
Returns:
  Size in bytes.
Throws:
  `IgniteCheckedException`

#### putPosition

    public static void putPosition(ByteBuffer buf,
                                   FileWALPointer ptr)

Saves position, WAL pointer (requires `FILE_WAL_POINTER_SIZE` bytes)

Parameters:
  `buf` - Byte buffer to serialize version to.
  `ptr` - File WAL pointer to write.

#### readSegmentHeader

    public static SegmentHeader readSegmentHeader(SegmentIO io,
                                                  SegmentFileInputFactory segmentFileInputFactory)
                                           throws IgniteCheckedException,
                                                  IOException

Reads stored record from provided `io`. NOTE: Method mutates position of `io`.

Parameters:
  `io` - I/O interface for file.
  `segmentFileInputFactory` - File input factory.
Returns:
  Instance of `SegmentHeader` extracted from the file.
Throws:
  `IgniteCheckedException` - If failed to read serializer version.
  `IOException`

#### readPosition

    public static FileWALPointer readPosition(DataInput in)
                                       throws IOException

Parameters:
  `in` - Data input to read pointer from.
Returns:
  Read file WAL pointer.
Throws:
  `IOException` - If failed to write.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.5
Release Date | : June 4 2019