timoninmaxim commented on code in PR #10798:
URL: https://github.com/apache/ignite/pull/10798#discussion_r1258240204


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/serializer/RecordV2Serializer.java:
##########
@@ -266,7 +265,7 @@ private static WALPointer readPositionAndCheckPoint(
         int fileOff = in.readInt();
         int len = in.readInt();
 
-        if (!F.eq(idx, expPtr.index()) || (!skipPositionCheck && 
!F.eq(fileOff, expPtr.fileOffset())))
+        if (expPtr != null && (!F.eq(idx, expPtr.index()) || 
(!skipPositionCheck && !F.eq(fileOff, expPtr.fileOffset()))))

Review Comment:
   Do we still need this check?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferWalIterator.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.pagemem.wal.record.WALRecord;
+import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactory;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.HEADER_RECORD;
+import static 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.HEADER_RECORD_SIZE;
+
+/** Byte Buffer WAL Iterator */
+public class ByteBufferWalIterator extends AbstractWalRecordsIteratorAdapter {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private final ByteBuffer buf;
+
+    /** */
+    private final RecordSerializer serializer;
+
+    /** */
+    private final ByteBufferBackedDataInputImpl dataInput;
+
+    /** */
+    private boolean hdrChecked;
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver) throws IgniteCheckedException {
+        this(log, cctx, byteBuf, ver, null);
+    }
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver,
+        IgniteBiPredicate<WALRecord.RecordType, WALPointer> readTypeFilter)
+        throws IgniteCheckedException {
+        super(log);
+
+        buf = byteBuf;
+
+        RecordSerializerFactory rsf = new RecordSerializerFactoryImpl(cctx, 
readTypeFilter);

Review Comment:
   No need in this variable, let's inline into `serializer` creation.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferWalIterator.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.pagemem.wal.record.WALRecord;
+import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactory;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.HEADER_RECORD;
+import static 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.HEADER_RECORD_SIZE;
+
+/** Byte Buffer WAL Iterator */
+public class ByteBufferWalIterator extends AbstractWalRecordsIteratorAdapter {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private final ByteBuffer buf;
+
+    /** */
+    private final RecordSerializer serializer;
+
+    /** */
+    private final ByteBufferBackedDataInputImpl dataInput;
+
+    /** */
+    private boolean hdrChecked;
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,

Review Comment:
   Avoid `@NotNull`



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferWalIterator.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.pagemem.wal.record.WALRecord;
+import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactory;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.HEADER_RECORD;
+import static 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.HEADER_RECORD_SIZE;
+
+/** Byte Buffer WAL Iterator */
+public class ByteBufferWalIterator extends AbstractWalRecordsIteratorAdapter {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private final ByteBuffer buf;
+
+    /** */
+    private final RecordSerializer serializer;
+
+    /** */
+    private final ByteBufferBackedDataInputImpl dataInput;
+
+    /** */
+    private boolean hdrChecked;
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver) throws IgniteCheckedException {
+        this(log, cctx, byteBuf, ver, null);
+    }
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver,
+        IgniteBiPredicate<WALRecord.RecordType, WALPointer> readTypeFilter)
+        throws IgniteCheckedException {
+        super(log);
+
+        buf = byteBuf;
+
+        RecordSerializerFactory rsf = new RecordSerializerFactoryImpl(cctx, 
readTypeFilter);
+
+        serializer = rsf.createSerializer(ver);
+
+        dataInput = new ByteBufferBackedDataInputImpl();
+
+        dataInput.buffer(buf);
+
+        advance();
+    }
+
+    /** */
+    private IgniteBiTuple<WALPointer, WALRecord> advanceRecord() throws 
IgniteCheckedException {
+        if (!buf.hasRemaining())
+            return null;
+
+        IgniteBiTuple<WALPointer, WALRecord> result;
+
+        try {
+            if (!hdrChecked) {
+                IgniteBiTuple<WALPointer, WALRecord> hdr = tryToReadHeader();
+
+                if (hdr != null)
+                    return hdr;
+            }
+            WALRecord rec = serializer.readRecord(dataInput, null);
+
+            result = new IgniteBiTuple<>(rec.position(), rec);
+        }
+        catch (SegmentEofException e) {
+            return null;
+        }
+        catch (IOException e) {
+            throw new IgniteCheckedException(e);
+        }
+
+        return result;
+    }
+
+    /** */
+    private IgniteBiTuple<WALPointer, WALRecord> tryToReadHeader() throws 
IgniteCheckedException, IOException {
+        hdrChecked = true;
+
+        int position = dataInput.buffer().position();
+
+        int type = dataInput.readUnsignedByte();
+
+        if (type == WALRecord.RecordType.STOP_ITERATION_RECORD_TYPE)
+            throw new SegmentEofException("Reached logical end of the 
segment", null);
+
+        WALRecord.RecordType recType = WALRecord.RecordType.fromIndex(type - 
1);
+
+        if (recType == HEADER_RECORD) {
+            long idx = dataInput.readLong();
+
+            int fileOff = dataInput.readInt();
+
+            WALPointer walPointer = new WALPointer(idx, fileOff, 
HEADER_RECORD_SIZE);
+
+            long magic = dataInput.readLong();
+
+            if (magic != HeaderRecord.REGULAR_MAGIC && magic != 
HeaderRecord.COMPACTED_MAGIC)
+                throw new EOFException("Magic is corrupted [actual=" + 
U.hexLong(magic) + ']');
+
+            int ver = dataInput.readInt();
+
+            HeaderRecord r = new HeaderRecord(ver);
+
+            r.position(walPointer);
+
+            // Read CRC.
+            dataInput.readInt();
+
+            return new IgniteBiTuple<>(walPointer, r);
+        }
+        else
+            dataInput.buffer().position(position);
+        return null;

Review Comment:
   Add an empty line before the return.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/Crc32CheckingDataInput.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.io.IOException;
+import org.apache.ignite.internal.processors.cache.persistence.wal.crc.FastCrc;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException;
+
+/**
+ * Checking of CRC32.
+ */
+public class Crc32CheckingDataInput extends ByteBufferBackedDataInputImpl 
implements AutoCloseable {
+    /** */
+    private final FastCrc crc = new FastCrc();
+
+    /**
+     * Last calc position.
+     */
+    private int lastCalcPosition;
+
+    /**
+     * Skip crc check.
+     */
+    private boolean skipCheck;

Review Comment:
   final



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferWalIterator.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.pagemem.wal.record.WALRecord;
+import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactory;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.HEADER_RECORD;
+import static 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.HEADER_RECORD_SIZE;
+
+/** Byte Buffer WAL Iterator */
+public class ByteBufferWalIterator extends AbstractWalRecordsIteratorAdapter {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private final ByteBuffer buf;
+
+    /** */
+    private final RecordSerializer serializer;
+
+    /** */
+    private final ByteBufferBackedDataInputImpl dataInput;
+
+    /** */
+    private boolean hdrChecked;
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver) throws IgniteCheckedException {

Review Comment:
   ```
       int ver
   ) throws IgniteCheckedException {
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferWalIterator.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.pagemem.wal.record.WALRecord;
+import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactory;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.HEADER_RECORD;
+import static 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.HEADER_RECORD_SIZE;
+
+/** Byte Buffer WAL Iterator */
+public class ByteBufferWalIterator extends AbstractWalRecordsIteratorAdapter {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private final ByteBuffer buf;
+
+    /** */
+    private final RecordSerializer serializer;
+
+    /** */
+    private final ByteBufferBackedDataInputImpl dataInput;
+
+    /** */
+    private boolean hdrChecked;
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver) throws IgniteCheckedException {
+        this(log, cctx, byteBuf, ver, null);
+    }
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver,
+        IgniteBiPredicate<WALRecord.RecordType, WALPointer> readTypeFilter)
+        throws IgniteCheckedException {
+        super(log);
+
+        buf = byteBuf;
+
+        RecordSerializerFactory rsf = new RecordSerializerFactoryImpl(cctx, 
readTypeFilter);
+
+        serializer = rsf.createSerializer(ver);
+
+        dataInput = new ByteBufferBackedDataInputImpl();
+
+        dataInput.buffer(buf);
+
+        advance();
+    }
+
+    /** */
+    private IgniteBiTuple<WALPointer, WALRecord> advanceRecord() throws 
IgniteCheckedException {
+        if (!buf.hasRemaining())
+            return null;
+
+        IgniteBiTuple<WALPointer, WALRecord> result;
+
+        try {
+            if (!hdrChecked) {

Review Comment:
   `if (currRec == null) {`? Do we need `hdrChecked` variable?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/Crc32CheckingDataInput.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.io.IOException;
+import org.apache.ignite.internal.processors.cache.persistence.wal.crc.FastCrc;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException;
+
+/**
+ * Checking of CRC32.
+ */
+public class Crc32CheckingDataInput extends ByteBufferBackedDataInputImpl 
implements AutoCloseable {
+    /** */
+    private final FastCrc crc = new FastCrc();
+
+    /**
+     * Last calc position.
+     */
+    private int lastCalcPosition;

Review Comment:
   final



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/ByteBufferWalIterator.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.pagemem.wal.record.WALRecord;
+import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactory;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.HEADER_RECORD;
+import static 
org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.HEADER_RECORD_SIZE;
+
+/** Byte Buffer WAL Iterator */
+public class ByteBufferWalIterator extends AbstractWalRecordsIteratorAdapter {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private final ByteBuffer buf;
+
+    /** */
+    private final RecordSerializer serializer;
+
+    /** */
+    private final ByteBufferBackedDataInputImpl dataInput;
+
+    /** */
+    private boolean hdrChecked;
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver) throws IgniteCheckedException {
+        this(log, cctx, byteBuf, ver, null);
+    }
+
+    /** */
+    public ByteBufferWalIterator(
+        @NotNull IgniteLogger log,
+        @NotNull GridCacheSharedContext<?, ?> cctx,
+        @NotNull ByteBuffer byteBuf,
+        int ver,
+        IgniteBiPredicate<WALRecord.RecordType, WALPointer> readTypeFilter)
+        throws IgniteCheckedException {
+        super(log);
+
+        buf = byteBuf;
+
+        RecordSerializerFactory rsf = new RecordSerializerFactoryImpl(cctx, 
readTypeFilter);
+
+        serializer = rsf.createSerializer(ver);
+
+        dataInput = new ByteBufferBackedDataInputImpl();
+
+        dataInput.buffer(buf);
+
+        advance();
+    }
+
+    /** */
+    private IgniteBiTuple<WALPointer, WALRecord> advanceRecord() throws 
IgniteCheckedException {
+        if (!buf.hasRemaining())
+            return null;
+
+        IgniteBiTuple<WALPointer, WALRecord> result;
+
+        try {
+            if (!hdrChecked) {
+                IgniteBiTuple<WALPointer, WALRecord> hdr = tryToReadHeader();
+
+                if (hdr != null)
+                    return hdr;

Review Comment:
   Missed check by `recordTypeFilter` if it's specified. User will receive 
unexpected record then.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to