sashapolo commented on code in PR #4582: URL: https://github.com/apache/ignite-3/pull/4582#discussion_r1804717814
########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryRequestSerializer.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.table.distributed.disaster; + +import static java.util.function.Function.identity; +import static java.util.stream.Collectors.toMap; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Map; +import org.apache.ignite.internal.util.io.IgniteDataInput; +import org.apache.ignite.internal.util.io.IgniteDataOutput; +import org.apache.ignite.internal.versioned.VersionedSerializer; + +/** + * {@link VersionedSerializer} for {@link DisasterRecoveryRequest} instances. + */ +class DisasterRecoveryRequestSerializer extends VersionedSerializer<DisasterRecoveryRequest> { + static final DisasterRecoveryRequestSerializer INSTANCE = new DisasterRecoveryRequestSerializer(); + + @Override + protected void writeExternalData(DisasterRecoveryRequest request, IgniteDataOutput out) throws IOException { + Operation operation = Operation.findByRequest(request); + + out.writeVarInt(operation.code); + operation.serialize(request, out); + } + + @Override + protected DisasterRecoveryRequest readExternalData(byte protoVer, IgniteDataInput in) throws IOException { + int operationCode = in.readVarIntAsInt(); + Operation operation = Operation.findByCode(operationCode); + + return operation.deserialize(in); + } + + private enum Operation { + MANUAL_GROUP_UPDATE(0, ManualGroupUpdateRequestSerializer.INSTANCE), + MANUAL_GROUP_RESTART(1, ManualGroupRestartRequestSerializer.INSTANCE); + + private static final Map<Integer, Operation> valuesByCode = Arrays.stream(values()).collect(toMap(op -> op.code, identity())); Review Comment: I would suggest using `toImmutableMap` ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/ManualGroupRestartRequestSerializer.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.table.distributed.disaster; + +import static org.apache.ignite.internal.table.distributed.disaster.DisasterRecoveryRequestsSerialization.readVarIntSet; +import static org.apache.ignite.internal.table.distributed.disaster.DisasterRecoveryRequestsSerialization.writeVarIntSet; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import org.apache.ignite.internal.util.io.IgniteDataInput; +import org.apache.ignite.internal.util.io.IgniteDataOutput; +import org.apache.ignite.internal.versioned.VersionedSerializer; + +/** + * {@link VersionedSerializer} for {@link ManualGroupRestartRequest} instances. + */ +class ManualGroupRestartRequestSerializer extends VersionedSerializer<ManualGroupRestartRequest> { + /** Serializer instance. */ + static final ManualGroupRestartRequestSerializer INSTANCE = new ManualGroupRestartRequestSerializer(); + + @Override + protected void writeExternalData(ManualGroupRestartRequest request, IgniteDataOutput out) throws IOException { + out.writeUuid(request.operationId()); + out.writeVarInt(request.zoneId()); + out.writeVarInt(request.tableId()); + writeVarIntSet(request.partitionIds(), out); + + out.writeVarInt(request.nodeNames().size()); + for (String nodeName : request.nodeNames()) { + out.writeUTF(nodeName); + } + + // Writing long and not a varlong as the latter requires 9 bytes for hybrid timestamps. + out.writeLong(request.assignmentsTimestamp()); + } + + @Override + protected ManualGroupRestartRequest readExternalData(byte protoVer, IgniteDataInput in) throws IOException { + UUID operationId = in.readUuid(); + int zoneId = in.readVarIntAsInt(); + int tableId = in.readVarIntAsInt(); + Set<Integer> partitionIds = readVarIntSet(in); + Set<String> nodeNames = readStringSet(in); + long assignmentsTimestamp = in.readLong(); + + return new ManualGroupRestartRequest(operationId, zoneId, tableId, partitionIds, nodeNames, assignmentsTimestamp); + } + + private static Set<String> readStringSet(IgniteDataInput in) throws IOException { + int size = in.readVarIntAsInt(); + + Set<String> result = new HashSet<>(size); Review Comment: same as usual, please make sure you always use the `IgniteUtils.capacity` method -- 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