tkalkirill commented on code in PR #5443:
URL: https://github.com/apache/ignite-3/pull/5443#discussion_r2004997930


##########
modules/core/src/main/java/org/apache/ignite/internal/versioned/VersionedSerializer.java:
##########
@@ -136,10 +136,10 @@ protected static Set<String> 
readStringSet(IgniteDataInput in) throws IOExceptio
         return result;
     }
 
-    protected static void writeVarIntSet(Set<Integer> partitionIds, 
IgniteDataOutput out) throws IOException {
-        out.writeVarInt(partitionIds.size());
+    protected static void writeVarIntSet(Set<Integer> varIntSet, 
IgniteDataOutput out) throws IOException {
+        out.writeVarInt(varIntSet.size());

Review Comment:
   I think we can write the size of a set a little more efficiently, like 
`org.apache.ignite.internal.network.serialization.marshal.ProtocolMarshalling#writeUnsignedVarInt`



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/PartitionSnapshotInfo.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.partition.replicator.raft;
+
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.Set;
+import org.apache.ignite.internal.storage.lease.LeaseInfo;
+import org.apache.ignite.internal.tostring.S;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Class containing information about the last performed Raft snapshot.
+ */
+public class PartitionSnapshotInfo {
+    private final long lastAppliedIndex;
+
+    private final long lastAppliedTerm;
+
+    @Nullable
+    private final LeaseInfo leaseInfo;
+
+    private final byte[] configuration;

Review Comment:
   Let's rename to `configBytes`.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/PartitionSnapshotInfo.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.partition.replicator.raft;
+
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.Set;
+import org.apache.ignite.internal.storage.lease.LeaseInfo;
+import org.apache.ignite.internal.tostring.S;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Class containing information about the last performed Raft snapshot.
+ */
+public class PartitionSnapshotInfo {
+    private final long lastAppliedIndex;
+
+    private final long lastAppliedTerm;
+
+    @Nullable
+    private final LeaseInfo leaseInfo;
+
+    private final byte[] configuration;
+
+    private final Set<Integer> tableIds;
+
+    /**
+     * Constructor.
+     *
+     * @param lastAppliedIndex Applied index at the moment when the snapshot 
was taken.
+     * @param lastAppliedTerm Applied term at the moment when the snapshot was 
taken.
+     * @param leaseInfo Lease information.
+     * @param configuration Raft group configuration.
+     * @param tableIds IDs of tables that were part of the Raft group when the 
snapshot was taken.
+     */
+    public PartitionSnapshotInfo(
+            long lastAppliedIndex,
+            long lastAppliedTerm,
+            @Nullable LeaseInfo leaseInfo,
+            byte[] configuration,
+            Set<Integer> tableIds
+    ) {
+        this.lastAppliedIndex = lastAppliedIndex;
+        this.lastAppliedTerm = lastAppliedTerm;
+        this.leaseInfo = leaseInfo;
+        this.configuration = configuration;
+        this.tableIds = tableIds;

Review Comment:
   Let's make it immutable.



##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/engine/MvPartitionMeta.java:
##########
@@ -26,20 +27,50 @@
 public class MvPartitionMeta extends PrimitivePartitionMeta {
     private final byte[] groupConfig;
 
+    private final byte[] snapshotInfo;
+
     /** Constructor. */
     public MvPartitionMeta(
             long lastAppliedIndex,
             long lastAppliedTerm,
             byte[] groupConfig,
-            @Nullable LeaseInfo leaseInfo
+            @Nullable LeaseInfo leaseInfo,
+            byte[] snapshotInfo
     ) {
         super(lastAppliedIndex, lastAppliedTerm, leaseInfo);
 
         this.groupConfig = groupConfig;
+        this.snapshotInfo = snapshotInfo;

Review Comment:
   I just wanted to make sure, do you think there will be no problems with 
backward compatibility, say, when starting on a new version, if there is `null` 
here, then this is not a problem, what do you think?



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/snapshot/incoming/IncomingSnapshotCopier.java:
##########
@@ -486,39 +499,61 @@ private CompletableFuture<Void> 
completeRebalance(PartitionSnapshotMeta meta, @N
                     setError(RaftError.UNKNOWN, throwable.getMessage());
                 }
 
-                return abortRebalance().thenCompose(unused -> 
failedFuture(throwable));
+                return abortRebalance(partitionsByTableId).thenCompose(unused 
-> failedFuture(throwable));
             }
 
-            var raftGroupConfig = new RaftGroupConfiguration(
-                    meta.cfgIndex(),
-                    meta.cfgTerm(),
-                    meta.peersList(),
-                    meta.learnersList(),
-                    meta.oldPeersList(),
-                    meta.oldLearnersList()
-            );
-
-            LOG.info(
-                    "Copier completes the rebalancing of the partition: [{}, 
lastAppliedIndex={}, lastAppliedTerm={}, raftGroupConfig={}]",
-                    createPartitionInfo(),
-                    meta.lastIncludedIndex(),
-                    meta.lastIncludedTerm(),
-                    raftGroupConfig
-            );
+            if (LOG.isInfoEnabled()) {

Review Comment:
   I think that this check is not necessary since the message will not be 
written often.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/PartitionSnapshotInfo.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.partition.replicator.raft;
+
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.Set;
+import org.apache.ignite.internal.storage.lease.LeaseInfo;
+import org.apache.ignite.internal.tostring.S;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Class containing information about the last performed Raft snapshot.
+ */
+public class PartitionSnapshotInfo {
+    private final long lastAppliedIndex;
+
+    private final long lastAppliedTerm;
+
+    @Nullable
+    private final LeaseInfo leaseInfo;
+
+    private final byte[] configuration;
+
+    private final Set<Integer> tableIds;
+
+    /**
+     * Constructor.
+     *
+     * @param lastAppliedIndex Applied index at the moment when the snapshot 
was taken.
+     * @param lastAppliedTerm Applied term at the moment when the snapshot was 
taken.
+     * @param leaseInfo Lease information.
+     * @param configuration Raft group configuration.
+     * @param tableIds IDs of tables that were part of the Raft group when the 
snapshot was taken.
+     */
+    public PartitionSnapshotInfo(
+            long lastAppliedIndex,
+            long lastAppliedTerm,
+            @Nullable LeaseInfo leaseInfo,
+            byte[] configuration,
+            Set<Integer> tableIds
+    ) {
+        this.lastAppliedIndex = lastAppliedIndex;
+        this.lastAppliedTerm = lastAppliedTerm;
+        this.leaseInfo = leaseInfo;
+        this.configuration = configuration;
+        this.tableIds = tableIds;
+    }
+
+    public long lastAppliedIndex() {
+        return lastAppliedIndex;
+    }
+
+    public long lastAppliedTerm() {
+        return lastAppliedTerm;
+    }
+
+    @Nullable
+    public LeaseInfo leaseInfo() {
+        return leaseInfo;
+    }
+
+    public byte[] configuration() {

Review Comment:
   Maybe rename to `configBytes`?



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/PartitionSnapshotInfoSerializer.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.partition.replicator.raft;
+
+import java.io.IOException;
+import java.util.Set;
+import org.apache.ignite.internal.storage.lease.LeaseInfo;
+import org.apache.ignite.internal.storage.lease.LeaseInfoSerializer;
+import org.apache.ignite.internal.util.io.IgniteDataInput;
+import org.apache.ignite.internal.util.io.IgniteDataOutput;
+import org.apache.ignite.internal.versioned.VersionedSerializer;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Serializer implementation for {@link PartitionSnapshotInfo}.
+ */
+public class PartitionSnapshotInfoSerializer extends 
VersionedSerializer<PartitionSnapshotInfo> {
+    /** Serializer instance. */
+    public static final PartitionSnapshotInfoSerializer INSTANCE = new 
PartitionSnapshotInfoSerializer();
+
+    @Override
+    protected void writeExternalData(PartitionSnapshotInfo snapshotInfo, 
IgniteDataOutput out) throws IOException {
+        out.writeLong(snapshotInfo.lastAppliedIndex());
+        out.writeLong(snapshotInfo.lastAppliedTerm());
+
+        writeNullableObject(snapshotInfo.leaseInfo(), 
LeaseInfoSerializer.INSTANCE, out);
+
+        writeByteArray(snapshotInfo.configuration(), out);
+
+        writeVarIntSet(snapshotInfo.tableIds(), out);
+    }
+
+    @Override
+    protected PartitionSnapshotInfo readExternalData(byte protoVer, 
IgniteDataInput in) throws IOException {
+        long lastAppliedIndex = in.readLong();
+        long lastAppliedTerm = in.readLong();
+
+        LeaseInfo leaseInfo = readNullableObject(LeaseInfoSerializer.INSTANCE, 
in);
+
+        byte[] configuration = readByteArray(in);
+
+        Set<Integer> tableIds = readVarIntSet(in);
+
+        return new PartitionSnapshotInfo(lastAppliedIndex, lastAppliedTerm, 
leaseInfo, configuration, tableIds);
+    }
+
+    private static void writeByteArray(byte[] array, IgniteDataOutput out) 
throws IOException {

Review Comment:
   Looks like a common helper method like `writeVarIntSet`.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/PartitionSnapshotInfoSerializer.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.partition.replicator.raft;
+
+import java.io.IOException;
+import java.util.Set;
+import org.apache.ignite.internal.storage.lease.LeaseInfo;
+import org.apache.ignite.internal.storage.lease.LeaseInfoSerializer;
+import org.apache.ignite.internal.util.io.IgniteDataInput;
+import org.apache.ignite.internal.util.io.IgniteDataOutput;
+import org.apache.ignite.internal.versioned.VersionedSerializer;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Serializer implementation for {@link PartitionSnapshotInfo}.
+ */
+public class PartitionSnapshotInfoSerializer extends 
VersionedSerializer<PartitionSnapshotInfo> {
+    /** Serializer instance. */
+    public static final PartitionSnapshotInfoSerializer INSTANCE = new 
PartitionSnapshotInfoSerializer();
+
+    @Override
+    protected void writeExternalData(PartitionSnapshotInfo snapshotInfo, 
IgniteDataOutput out) throws IOException {
+        out.writeLong(snapshotInfo.lastAppliedIndex());
+        out.writeLong(snapshotInfo.lastAppliedTerm());
+
+        writeNullableObject(snapshotInfo.leaseInfo(), 
LeaseInfoSerializer.INSTANCE, out);
+
+        writeByteArray(snapshotInfo.configuration(), out);
+
+        writeVarIntSet(snapshotInfo.tableIds(), out);
+    }
+
+    @Override
+    protected PartitionSnapshotInfo readExternalData(byte protoVer, 
IgniteDataInput in) throws IOException {
+        long lastAppliedIndex = in.readLong();
+        long lastAppliedTerm = in.readLong();
+
+        LeaseInfo leaseInfo = readNullableObject(LeaseInfoSerializer.INSTANCE, 
in);
+
+        byte[] configuration = readByteArray(in);
+
+        Set<Integer> tableIds = readVarIntSet(in);
+
+        return new PartitionSnapshotInfo(lastAppliedIndex, lastAppliedTerm, 
leaseInfo, configuration, tableIds);
+    }
+
+    private static void writeByteArray(byte[] array, IgniteDataOutput out) 
throws IOException {
+        out.writeVarInt(array.length);
+        out.writeByteArray(array);
+    }
+
+    private static <T> void writeNullableObject(
+            @Nullable T object,
+            VersionedSerializer<T> serializer,
+            IgniteDataOutput out
+    ) throws IOException {
+        if (object == null) {
+            out.writeBoolean(false);
+        } else {
+            out.writeBoolean(true);
+            serializer.writeExternal(object, out);
+        }
+    }
+
+    private static byte[] readByteArray(IgniteDataInput in) throws IOException 
{
+        int length = in.readVarIntAsInt();
+
+        return in.readByteArray(length);
+    }
+
+    private static <T> @Nullable T readNullableObject(VersionedSerializer<T> 
serializer, IgniteDataInput in) throws IOException {

Review Comment:
   Looks like a common helper method like `writeVarIntSet`.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/PartitionSnapshotInfo.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.partition.replicator.raft;
+
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.Set;
+import org.apache.ignite.internal.storage.lease.LeaseInfo;
+import org.apache.ignite.internal.tostring.S;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Class containing information about the last performed Raft snapshot.
+ */
+public class PartitionSnapshotInfo {
+    private final long lastAppliedIndex;
+
+    private final long lastAppliedTerm;
+
+    @Nullable
+    private final LeaseInfo leaseInfo;
+
+    private final byte[] configuration;
+
+    private final Set<Integer> tableIds;
+
+    /**
+     * Constructor.
+     *
+     * @param lastAppliedIndex Applied index at the moment when the snapshot 
was taken.
+     * @param lastAppliedTerm Applied term at the moment when the snapshot was 
taken.
+     * @param leaseInfo Lease information.

Review Comment:
   Please indicate when it can be `null`.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/PartitionSnapshotInfoSerializer.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.partition.replicator.raft;
+
+import java.io.IOException;
+import java.util.Set;
+import org.apache.ignite.internal.storage.lease.LeaseInfo;
+import org.apache.ignite.internal.storage.lease.LeaseInfoSerializer;
+import org.apache.ignite.internal.util.io.IgniteDataInput;
+import org.apache.ignite.internal.util.io.IgniteDataOutput;
+import org.apache.ignite.internal.versioned.VersionedSerializer;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Serializer implementation for {@link PartitionSnapshotInfo}.
+ */
+public class PartitionSnapshotInfoSerializer extends 
VersionedSerializer<PartitionSnapshotInfo> {
+    /** Serializer instance. */
+    public static final PartitionSnapshotInfoSerializer INSTANCE = new 
PartitionSnapshotInfoSerializer();
+
+    @Override
+    protected void writeExternalData(PartitionSnapshotInfo snapshotInfo, 
IgniteDataOutput out) throws IOException {
+        out.writeLong(snapshotInfo.lastAppliedIndex());
+        out.writeLong(snapshotInfo.lastAppliedTerm());
+
+        writeNullableObject(snapshotInfo.leaseInfo(), 
LeaseInfoSerializer.INSTANCE, out);
+
+        writeByteArray(snapshotInfo.configuration(), out);
+
+        writeVarIntSet(snapshotInfo.tableIds(), out);
+    }
+
+    @Override
+    protected PartitionSnapshotInfo readExternalData(byte protoVer, 
IgniteDataInput in) throws IOException {
+        long lastAppliedIndex = in.readLong();
+        long lastAppliedTerm = in.readLong();
+
+        LeaseInfo leaseInfo = readNullableObject(LeaseInfoSerializer.INSTANCE, 
in);
+
+        byte[] configuration = readByteArray(in);
+
+        Set<Integer> tableIds = readVarIntSet(in);
+
+        return new PartitionSnapshotInfo(lastAppliedIndex, lastAppliedTerm, 
leaseInfo, configuration, tableIds);
+    }
+
+    private static void writeByteArray(byte[] array, IgniteDataOutput out) 
throws IOException {
+        out.writeVarInt(array.length);
+        out.writeByteArray(array);
+    }
+
+    private static <T> void writeNullableObject(
+            @Nullable T object,
+            VersionedSerializer<T> serializer,
+            IgniteDataOutput out
+    ) throws IOException {
+        if (object == null) {
+            out.writeBoolean(false);
+        } else {
+            out.writeBoolean(true);
+            serializer.writeExternal(object, out);
+        }
+    }
+
+    private static byte[] readByteArray(IgniteDataInput in) throws IOException 
{

Review Comment:
   Looks like a common helper method like `writeVarIntSet`.



##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/engine/MvPartitionMeta.java:
##########
@@ -26,20 +27,50 @@
 public class MvPartitionMeta extends PrimitivePartitionMeta {
     private final byte[] groupConfig;
 
+    private final byte[] snapshotInfo;
+
     /** Constructor. */
     public MvPartitionMeta(
             long lastAppliedIndex,
             long lastAppliedTerm,
             byte[] groupConfig,
-            @Nullable LeaseInfo leaseInfo
+            @Nullable LeaseInfo leaseInfo,
+            byte[] snapshotInfo
     ) {
         super(lastAppliedIndex, lastAppliedTerm, leaseInfo);
 
         this.groupConfig = groupConfig;
+        this.snapshotInfo = snapshotInfo;
     }
 
     /** Returns replication group config as bytes. */
     public byte[] groupConfig() {
         return groupConfig;
     }
+
+    /** Returns snapshot info as bytes. */
+    public byte[] snapshotInfo() {
+        return snapshotInfo;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        if (!super.equals(o)) {

Review Comment:
   I think this won't work well because the parent class does the equality 
check for classes, not `instanceof`.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/PartitionSnapshotInfoSerializer.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.partition.replicator.raft;
+
+import java.io.IOException;
+import java.util.Set;
+import org.apache.ignite.internal.storage.lease.LeaseInfo;
+import org.apache.ignite.internal.storage.lease.LeaseInfoSerializer;
+import org.apache.ignite.internal.util.io.IgniteDataInput;
+import org.apache.ignite.internal.util.io.IgniteDataOutput;
+import org.apache.ignite.internal.versioned.VersionedSerializer;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Serializer implementation for {@link PartitionSnapshotInfo}.
+ */
+public class PartitionSnapshotInfoSerializer extends 
VersionedSerializer<PartitionSnapshotInfo> {
+    /** Serializer instance. */
+    public static final PartitionSnapshotInfoSerializer INSTANCE = new 
PartitionSnapshotInfoSerializer();
+
+    @Override
+    protected void writeExternalData(PartitionSnapshotInfo snapshotInfo, 
IgniteDataOutput out) throws IOException {
+        out.writeLong(snapshotInfo.lastAppliedIndex());
+        out.writeLong(snapshotInfo.lastAppliedTerm());
+
+        writeNullableObject(snapshotInfo.leaseInfo(), 
LeaseInfoSerializer.INSTANCE, out);
+
+        writeByteArray(snapshotInfo.configuration(), out);
+
+        writeVarIntSet(snapshotInfo.tableIds(), out);
+    }
+
+    @Override
+    protected PartitionSnapshotInfo readExternalData(byte protoVer, 
IgniteDataInput in) throws IOException {
+        long lastAppliedIndex = in.readLong();
+        long lastAppliedTerm = in.readLong();
+
+        LeaseInfo leaseInfo = readNullableObject(LeaseInfoSerializer.INSTANCE, 
in);
+
+        byte[] configuration = readByteArray(in);
+
+        Set<Integer> tableIds = readVarIntSet(in);
+
+        return new PartitionSnapshotInfo(lastAppliedIndex, lastAppliedTerm, 
leaseInfo, configuration, tableIds);
+    }
+
+    private static void writeByteArray(byte[] array, IgniteDataOutput out) 
throws IOException {
+        out.writeVarInt(array.length);
+        out.writeByteArray(array);
+    }
+
+    private static <T> void writeNullableObject(

Review Comment:
   Looks like a common helper method like `writeVarIntSet`.



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