You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ibessonov (via GitHub)" <gi...@apache.org> on 2023/07/10 08:17:41 UTC

[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2283: IGNITE-19903 Fix recovery descriptor race condition

ibessonov commented on code in PR #2283:
URL: https://github.com/apache/ignite-3/pull/2283#discussion_r1257868088


##########
modules/network/src/main/java/org/apache/ignite/internal/network/netty/ChannelCreationListener.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.network.netty;
+
+import java.util.concurrent.CompletableFuture;
+
+/** Channel creation listener. */

Review Comment:
   Very informative :+1: 



##########
modules/network/src/main/java/org/apache/ignite/internal/network/netty/ChannelCreationListener.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.network.netty;
+
+import java.util.concurrent.CompletableFuture;
+
+/** Channel creation listener. */
+public interface ChannelCreationListener {
+    /**
+     * Notifies of creation of a new channel before the handshake.
+     *
+     * @param consistentId Remote node's consistent id.
+     * @param channelId Channel id.
+     * @return A future which is completed when listener's action is done.
+     */
+    CompletableFuture<Void> notifyInboundChannelCreation(String consistentId, short channelId);
+
+    /**
+     * Notifies of the handshake's finish.
+     *
+     * @param channel Opened channel.
+     */
+    void handshakeFinished(NettySender channel);

Review Comment:
   Off-topic: name "sender" is very confusing, don't you think so?



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryClientHandshakeManager.java:
##########
@@ -136,14 +162,29 @@ public void onMessage(NetworkMessage message) {
             this.remoteLaunchId = msg.launchId();
             this.remoteConsistentId = msg.consistentId();
 
-            this.recoveryDescriptor = recoveryDescriptorProvider.getRecoveryDescriptor(
-                    remoteConsistentId,
-                    remoteLaunchId,
-                    connectionId,
-                    false
-            );
+            channelCreationListener.notifyInboundChannelCreation(this.remoteConsistentId, this.connectionId)

Review Comment:
   Maybe all of this should be extracted to `onHandshakeStartMessage` instead of being inside of a single big method



##########
modules/network/src/main/java/org/apache/ignite/internal/network/netty/ChannelCreationListener.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.network.netty;
+
+import java.util.concurrent.CompletableFuture;
+
+/** Channel creation listener. */
+public interface ChannelCreationListener {
+    /**
+     * Notifies of creation of a new channel before the handshake.
+     *
+     * @param consistentId Remote node's consistent id.
+     * @param channelId Channel id.
+     * @return A future which is completed when listener's action is done.
+     */
+    CompletableFuture<Void> notifyInboundChannelCreation(String consistentId, short channelId);

Review Comment:
   I don't see a unique launch ID. Is it not available yet?
   If it's not available, then how do you know node's consistent ID?
   Or maybe it's not required here. You see, it's hard to understand your intentions with this interface.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/LeaseTracker.java:
##########
@@ -214,7 +214,6 @@ public CompletableFuture<LeaseMeta> getPrimaryReplica(ReplicationGroupId replica
                 return completedFuture(lease);
             }
 
-            // TODO: https://issues.apache.org/jira/browse/IGNITE-19532 Race between meta storage safe time publication and listeners.

Review Comment:
   Did you fix it? Or it was here by mistake?



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryClientHandshakeManager.java:
##########
@@ -136,14 +162,29 @@ public void onMessage(NetworkMessage message) {
             this.remoteLaunchId = msg.launchId();
             this.remoteConsistentId = msg.consistentId();
 
-            this.recoveryDescriptor = recoveryDescriptorProvider.getRecoveryDescriptor(
-                    remoteConsistentId,
-                    remoteLaunchId,
-                    connectionId,
-                    false
-            );
+            channelCreationListener.notifyInboundChannelCreation(this.remoteConsistentId, this.connectionId)
+                    .whenCompleteAsync((unused, throwable) -> {
+                        RecoveryDescriptor descriptor = recoveryDescriptorProvider.getRecoveryDescriptor(
+                                remoteConsistentId,
+                                remoteLaunchId,
+                                connectionId,
+                                false
+                        );
+
+                        if (!descriptor.acquire(ctx)) {
+                            String err = "Failed to acquire recovery descriptor during handshake, it is held by: " + descriptor.holder();
+
+                            LOG.warn(err);
+
+                            handshakeCompleteFuture.completeExceptionally(new HandshakeException(err));

Review Comment:
   Maybe you should also close the connection or send some response, like "already opened"



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryDescriptor.java:
##########
@@ -124,4 +127,30 @@ public long onReceive() {
     public String toString() {
         return S.toString(RecoveryDescriptor.class, this);
     }
+
+    private final AtomicReference<Channel> ctxHolder = new AtomicReference<>();
+
+    /**
+     * Release this descriptor.
+     *
+     * @param ctx Channel handler context.
+     */
+    public void release(ChannelHandlerContext ctx) {
+        boolean result = ctxHolder.compareAndSet(ctx.channel(), null);
+
+        assert result : "Failed to release descriptor: " + ctx;
+    }
+
+    /**
+     * Acquire this descriptor.
+     *
+     * @param ctx Channel handler context.
+     */
+    public boolean acquire(ChannelHandlerContext ctx) {
+        return ctxHolder.compareAndSet(null, ctx.channel());
+    }
+
+    public String holder() {
+        return ctxHolder.get().toString();
+    }

Review Comment:
   I'm sorry, but what is this?



##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryServerHandshakeManager.java:
##########
@@ -148,24 +174,55 @@ public void onMessage(NetworkMessage message) {
         if (message instanceof HandshakeStartResponseMessage) {
             HandshakeStartResponseMessage msg = (HandshakeStartResponseMessage) message;
 
-            if (staleIdDetector.isIdStale(msg.launchId().toString())) {
+            UUID remoteLaunchId = msg.launchId();
+            String remoteConsistentId = msg.consistentId();
+            long remoteReceivedCount = msg.receivedCount();
+            short remoteChannelId = msg.connectionId();
+
+            if (staleIdDetector.isIdStale(remoteLaunchId.toString())) {
                 handleStaleClientId(msg);
 
                 return;
             }
 
-            this.remoteLaunchId = msg.launchId();
-            this.remoteConsistentId = msg.consistentId();
-            this.receivedCount = msg.receivedCount();
-            this.remoteChannelId = msg.connectionId();
+            this.remoteLaunchId = remoteLaunchId;
+            this.remoteConsistentId = remoteConsistentId;
+            this.receivedCount = remoteReceivedCount;
+            this.remoteChannelId = remoteChannelId;
+
+            channelCreationListener.notifyInboundChannelCreation(this.remoteConsistentId, this.remoteChannelId)

Review Comment:
   This looks copy-pasted. Also, both Client and Server notify that inbound channel is created. Which cannot be true, maybe that method needs to be renamed.



-- 
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-unsubscribe@ignite.apache.org

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