tkalkirill commented on code in PR #7156: URL: https://github.com/apache/ignite-3/pull/7156#discussion_r2591614352
########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/MetaStorageKeys.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.nio.charset.StandardCharsets.UTF_8; +import static org.apache.ignite.internal.util.ByteUtils.uuidToBytes; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.UUID; +import org.apache.ignite.internal.lang.ByteArray; + +public class MetaStorageKeys { + /** Single key for writing disaster recovery requests into meta-storage. */ + static final ByteArray RECOVERY_TRIGGER_KEY = new ByteArray("disaster.recovery.trigger"); + + /** + * Metastorage key prefix to store the per zone revision of logical event, which start the recovery process. + * It's needed to skip the stale recovery triggers. + */ + private static final String RECOVERY_TRIGGER_REVISION_KEY_PREFIX = "disaster.recovery.trigger.revision."; + + /** Prefix for local operations statuses. */ + static final byte[] LOCAL_OPERATIONS_PREFIX = "disaster.recovery.local.".getBytes(UTF_8); + + static final byte[] IN_PROGRESS_BYTES = "IN_PROGRESS".getBytes(UTF_8); + + static final byte[] COMPLETED_BYTES = "COMPLETED".getBytes(UTF_8); + + private static final ByteOrder BYTE_UTILS_BYTE_ORDER = ByteOrder.BIG_ENDIAN; + + static ByteArray zoneRecoveryTriggerRevisionKey(int zoneId) { + return new ByteArray(RECOVERY_TRIGGER_REVISION_KEY_PREFIX + zoneId); + } + + /** disaster.recovery.requests.{operationId}.{nodeName} */ + static ByteArray ongoingOperationsKey(UUID operationId, String nodeName) { + byte[] array = ByteBuffer.allocate(LOCAL_OPERATIONS_PREFIX.length + uuidToBytes(operationId).length + 1 + nodeName.length()) + .order(BYTE_UTILS_BYTE_ORDER) + .put(LOCAL_OPERATIONS_PREFIX) + .put(uuidToBytes(operationId)) + .put((byte) '.') + .put(nodeName.getBytes(UTF_8)) + .array(); + + return new ByteArray(array); + } + + /** disaster.recovery.requests.{operationId}. */ + static ByteArray operationPrefix(UUID operationId) { + byte[] array = ByteBuffer.allocate(LOCAL_OPERATIONS_PREFIX.length + uuidToBytes(operationId).length + 1) + .order(BYTE_UTILS_BYTE_ORDER) + .put(LOCAL_OPERATIONS_PREFIX) + .put(uuidToBytes(operationId)) + .put((byte) '.') Review Comment: Why is there a '.' at the end? ########## modules/api/src/main/java/org/apache/ignite/lang/ErrorGroups.java: ########## @@ -747,6 +747,9 @@ public static class DisasterRecovery { /** Error when forwarding disaster recovery request to another node failed. */ public static final int REQUEST_FORWARD_ERR = RECOVERY_ERR_GROUP.registerErrorCode((short) 7); + + /** Error when multi node operation fails on any node. */ Review Comment: The javadoc is a bit unclear, the name contains LOCAL, but the javadoc says "any". ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/RecoveryWatch.java: ########## @@ -0,0 +1,124 @@ +/* + * 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.MetaStorageKeys.COMPLETED_BYTES; +import static org.apache.ignite.internal.table.distributed.disaster.MetaStorageKeys.IN_PROGRESS_BYTES; +import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; +import static org.apache.ignite.internal.util.IgniteUtils.inBusyLock; +import static org.apache.ignite.internal.util.StringUtils.toStringWithoutPrefix; +import static org.apache.ignite.lang.ErrorGroups.DisasterRecovery.LOCAL_NODE_ERR; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.internal.cluster.management.topology.api.LogicalNode; +import org.apache.ignite.internal.cluster.management.topology.api.LogicalTopologyEventListener; +import org.apache.ignite.internal.cluster.management.topology.api.LogicalTopologySnapshot; +import org.apache.ignite.internal.lang.ByteArray; +import org.apache.ignite.internal.metastorage.Entry; +import org.apache.ignite.internal.metastorage.EntryEvent; +import org.apache.ignite.internal.metastorage.WatchEvent; +import org.apache.ignite.internal.metastorage.WatchListener; +import org.apache.ignite.internal.table.distributed.disaster.exceptions.DisasterRecoveryException; +import org.apache.ignite.internal.table.distributed.disaster.exceptions.LocalProcessingDisasterRecoveryException; +import org.apache.ignite.internal.util.CollectionUtils; +import org.apache.ignite.internal.util.IgniteSpinBusyLock; + +/** Watch for tracking MULTI_NODE disaster recovery process. */ +class RecoveryWatch implements WatchListener, LogicalTopologyEventListener { Review Comment: The name is too short for me, maybe add "Disaster" as prefix? ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryRequest.java: ########## @@ -38,12 +39,14 @@ interface DisasterRecoveryRequest { /** Returns request type. */ DisasterRecoveryRequestType type(); + Set<String> nodeNames(); Review Comment: I see that heirs can be saved in metastorage as a byte array. Will this cause any issues with backward compatibility? ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/MetaStorageKeys.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.nio.charset.StandardCharsets.UTF_8; +import static org.apache.ignite.internal.util.ByteUtils.uuidToBytes; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.UUID; +import org.apache.ignite.internal.lang.ByteArray; + +public class MetaStorageKeys { + /** Single key for writing disaster recovery requests into meta-storage. */ + static final ByteArray RECOVERY_TRIGGER_KEY = new ByteArray("disaster.recovery.trigger"); + + /** + * Metastorage key prefix to store the per zone revision of logical event, which start the recovery process. + * It's needed to skip the stale recovery triggers. + */ + private static final String RECOVERY_TRIGGER_REVISION_KEY_PREFIX = "disaster.recovery.trigger.revision."; + + /** Prefix for local operations statuses. */ + static final byte[] LOCAL_OPERATIONS_PREFIX = "disaster.recovery.local.".getBytes(UTF_8); + + static final byte[] IN_PROGRESS_BYTES = "IN_PROGRESS".getBytes(UTF_8); + + static final byte[] COMPLETED_BYTES = "COMPLETED".getBytes(UTF_8); + + private static final ByteOrder BYTE_UTILS_BYTE_ORDER = ByteOrder.BIG_ENDIAN; + + static ByteArray zoneRecoveryTriggerRevisionKey(int zoneId) { + return new ByteArray(RECOVERY_TRIGGER_REVISION_KEY_PREFIX + zoneId); + } + + /** disaster.recovery.requests.{operationId}.{nodeName} */ + static ByteArray ongoingOperationsKey(UUID operationId, String nodeName) { + byte[] array = ByteBuffer.allocate(LOCAL_OPERATIONS_PREFIX.length + uuidToBytes(operationId).length + 1 + nodeName.length()) + .order(BYTE_UTILS_BYTE_ORDER) + .put(LOCAL_OPERATIONS_PREFIX) + .put(uuidToBytes(operationId)) + .put((byte) '.') Review Comment: Why is there a '.' at the end? ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/exceptions/LocalProcessingDisasterRecoveryException.java: ########## @@ -15,25 +15,19 @@ * limitations under the License. */ -package org.apache.ignite.internal.storage.pagememory.mv; +package org.apache.ignite.internal.table.distributed.disaster.exceptions; -/** - * Links to the neighbors of a {@link RowVersion} (which is a write intent) in the write intents list. - */ -class WriteIntentLinks { - private final long nextWriteIntentLink; - private final long prevWriteIntentLink; +import org.apache.ignite.lang.ErrorGroups.DisasterRecovery; - WriteIntentLinks(long nextWriteIntentLink, long prevWriteIntentLink) { - this.nextWriteIntentLink = nextWriteIntentLink; - this.prevWriteIntentLink = prevWriteIntentLink; - } +/** Exception is thrown when local node encounters an error during disaster recovery processing. */ +public class LocalProcessingDisasterRecoveryException extends DisasterRecoveryException { + private static final long serialVersionUID = 1L; - long nextWriteIntentLink() { - return nextWriteIntentLink; + public LocalProcessingDisasterRecoveryException(String message, String nodeName) { + super(DisasterRecovery.LOCAL_NODE_ERR, formatMessage(message, nodeName)); } - long prevWriteIntentLink() { - return prevWriteIntentLink; + private static String formatMessage(String message, String nodeName) { Review Comment: It looks like an optional method, it can be placed on one line, maybe we should get rid of it? ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/MetaStorageKeys.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.nio.charset.StandardCharsets.UTF_8; +import static org.apache.ignite.internal.util.ByteUtils.uuidToBytes; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.UUID; +import org.apache.ignite.internal.lang.ByteArray; + +public class MetaStorageKeys { + /** Single key for writing disaster recovery requests into meta-storage. */ + static final ByteArray RECOVERY_TRIGGER_KEY = new ByteArray("disaster.recovery.trigger"); + + /** + * Metastorage key prefix to store the per zone revision of logical event, which start the recovery process. + * It's needed to skip the stale recovery triggers. + */ + private static final String RECOVERY_TRIGGER_REVISION_KEY_PREFIX = "disaster.recovery.trigger.revision."; + + /** Prefix for local operations statuses. */ + static final byte[] LOCAL_OPERATIONS_PREFIX = "disaster.recovery.local.".getBytes(UTF_8); Review Comment: Let's add postfix `_BYTES`. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
