tkalkirill commented on code in PR #4147:
URL: https://github.com/apache/ignite-3/pull/4147#discussion_r1692986488
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -179,6 +182,31 @@ public ClusterManagementGroupManager(
scheduledExecutor = Executors.newSingleThreadScheduledExecutor(
NamedThreadFactory.create(clusterService.nodeName(),
"cmg-manager", LOG)
);
+
+ var messageCallback = new CmgMessageCallback() {
Review Comment:
Let's put it in a separate method so as not to bloat the constructor?
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -179,6 +182,31 @@ public ClusterManagementGroupManager(
scheduledExecutor = Executors.newSingleThreadScheduledExecutor(
NamedThreadFactory.create(clusterService.nodeName(),
"cmg-manager", LOG)
);
+
+ var messageCallback = new CmgMessageCallback() {
+ @Override
+ public void onClusterStateMessageReceived(ClusterStateMessage
message, ClusterNode sender, @Nullable Long correlationId) {
+ assert correlationId != null;
+
+ handleClusterState(message, sender, correlationId);
+ }
+
+ @Override
+ public void onCancelInitMessageReceived(CancelInitMessage message,
ClusterNode sender, @Nullable Long correlationId) {
+ handleCancelInit(message);
+ }
+
+ @Override
+ public void onCmgInitMessageReceived(CmgInitMessage message,
ClusterNode sender, @Nullable Long correlationId) {
+ assert correlationId != null;
Review Comment:
```suggestion
assert correlationId != null : sender;
```
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -179,6 +182,31 @@ public ClusterManagementGroupManager(
scheduledExecutor = Executors.newSingleThreadScheduledExecutor(
NamedThreadFactory.create(clusterService.nodeName(),
"cmg-manager", LOG)
);
+
+ var messageCallback = new CmgMessageCallback() {
+ @Override
+ public void onClusterStateMessageReceived(ClusterStateMessage
message, ClusterNode sender, @Nullable Long correlationId) {
+ assert correlationId != null;
Review Comment:
```suggestion
assert correlationId != null : sender;
```
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/network/CmgMessageHandler.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.cluster.management.network;
+
+import java.util.ArrayList;
+import java.util.List;
+import
org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager;
+import
org.apache.ignite.internal.cluster.management.network.messages.CancelInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.ClusterStateMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgMessagesFactory;
+import org.apache.ignite.internal.lang.NodeStoppingException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.network.NetworkMessage;
+import org.apache.ignite.internal.network.NetworkMessageHandler;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Network message handler for CMG messages.
+ *
+ * <p>This handler buffers incoming messages until the parent component
signals that its local recovery has been complete (by calling
+ * {@link #onRecoveryComplete}) after which it passes the buffered messages to
the registered callback and then continues to behave like a
+ * regular message handler.
+ */
+public class CmgMessageHandler implements NetworkMessageHandler {
+ private static final IgniteLogger LOG =
Loggers.forClass(ClusterManagementGroupManager.class);
+
+ private final IgniteSpinBusyLock busyLock;
+
+ private final CmgMessagesFactory msgFactory;
+
+ private final ClusterService clusterService;
+
+ private final CmgMessageCallback cmgMessageCallback;
+
+ @Nullable
+ private List<NetworkMessageContext> messageQueue = new ArrayList<>();
Review Comment:
Specify in the documentation when it can be `null`.
And let's protect it with a mutex.
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/network/CmgMessageHandler.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.cluster.management.network;
+
+import java.util.ArrayList;
+import java.util.List;
+import
org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager;
+import
org.apache.ignite.internal.cluster.management.network.messages.CancelInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.ClusterStateMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgMessagesFactory;
+import org.apache.ignite.internal.lang.NodeStoppingException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.network.NetworkMessage;
+import org.apache.ignite.internal.network.NetworkMessageHandler;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Network message handler for CMG messages.
+ *
+ * <p>This handler buffers incoming messages until the parent component
signals that its local recovery has been complete (by calling
+ * {@link #onRecoveryComplete}) after which it passes the buffered messages to
the registered callback and then continues to behave like a
+ * regular message handler.
+ */
+public class CmgMessageHandler implements NetworkMessageHandler {
+ private static final IgniteLogger LOG =
Loggers.forClass(ClusterManagementGroupManager.class);
+
+ private final IgniteSpinBusyLock busyLock;
+
+ private final CmgMessagesFactory msgFactory;
+
+ private final ClusterService clusterService;
+
+ private final CmgMessageCallback cmgMessageCallback;
+
+ @Nullable
+ private List<NetworkMessageContext> messageQueue = new ArrayList<>();
+
+ private boolean isRecoveryComplete = false;
Review Comment:
And let's protect it with a mutex, and say about it in javadoc.
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/network/CmgMessageCallback.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.cluster.management.network;
+
+import
org.apache.ignite.internal.cluster.management.network.messages.CancelInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.ClusterStateMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgInitMessage;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Callback used by the {@link CmgMessageHandler} to notify about incoming
messages.
+ */
+public interface CmgMessageCallback {
+ /**
+ * Notifies about an incoming {@link ClusterStateMessage}.
+ */
Review Comment:
```suggestion
/** Notifies about an incoming {@link ClusterStateMessage}. */
```
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/network/CmgMessageCallback.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.cluster.management.network;
+
+import
org.apache.ignite.internal.cluster.management.network.messages.CancelInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.ClusterStateMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgInitMessage;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Callback used by the {@link CmgMessageHandler} to notify about incoming
messages.
+ */
+public interface CmgMessageCallback {
+ /**
+ * Notifies about an incoming {@link ClusterStateMessage}.
+ */
+ void onClusterStateMessageReceived(ClusterStateMessage message,
ClusterNode sender, @Nullable Long correlationId);
+
+ /**
+ * Notifies about an incoming {@link CancelInitMessage}.
+ */
+ void onCancelInitMessageReceived(CancelInitMessage message, ClusterNode
sender, @Nullable Long correlationId);
+
+ /**
+ * Notifies about an incoming {@link CmgInitMessage}.
+ */
Review Comment:
```suggestion
/** Notifies about an incoming {@link CmgInitMessage}. */
```
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/network/CmgMessageHandler.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.cluster.management.network;
+
+import java.util.ArrayList;
+import java.util.List;
+import
org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager;
+import
org.apache.ignite.internal.cluster.management.network.messages.CancelInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.ClusterStateMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgMessagesFactory;
+import org.apache.ignite.internal.lang.NodeStoppingException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.network.NetworkMessage;
+import org.apache.ignite.internal.network.NetworkMessageHandler;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Network message handler for CMG messages.
+ *
+ * <p>This handler buffers incoming messages until the parent component
signals that its local recovery has been complete (by calling
+ * {@link #onRecoveryComplete}) after which it passes the buffered messages to
the registered callback and then continues to behave like a
+ * regular message handler.
+ */
+public class CmgMessageHandler implements NetworkMessageHandler {
+ private static final IgniteLogger LOG =
Loggers.forClass(ClusterManagementGroupManager.class);
+
+ private final IgniteSpinBusyLock busyLock;
+
+ private final CmgMessagesFactory msgFactory;
+
+ private final ClusterService clusterService;
+
+ private final CmgMessageCallback cmgMessageCallback;
+
+ @Nullable
+ private List<NetworkMessageContext> messageQueue = new ArrayList<>();
Review Comment:
```suggestion
private @Nullable List<NetworkMessageContext> messageQueue = new
ArrayList<>();
```
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/network/CmgMessageCallback.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.cluster.management.network;
+
+import
org.apache.ignite.internal.cluster.management.network.messages.CancelInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.ClusterStateMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgInitMessage;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Callback used by the {@link CmgMessageHandler} to notify about incoming
messages.
+ */
+public interface CmgMessageCallback {
+ /**
+ * Notifies about an incoming {@link ClusterStateMessage}.
+ */
+ void onClusterStateMessageReceived(ClusterStateMessage message,
ClusterNode sender, @Nullable Long correlationId);
+
+ /**
+ * Notifies about an incoming {@link CancelInitMessage}.
+ */
Review Comment:
```suggestion
/** Notifies about an incoming {@link CancelInitMessage}. */
```
##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/network/CmgMessageHandler.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.cluster.management.network;
+
+import java.util.ArrayList;
+import java.util.List;
+import
org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager;
+import
org.apache.ignite.internal.cluster.management.network.messages.CancelInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.ClusterStateMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgInitMessage;
+import
org.apache.ignite.internal.cluster.management.network.messages.CmgMessagesFactory;
+import org.apache.ignite.internal.lang.NodeStoppingException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.network.NetworkMessage;
+import org.apache.ignite.internal.network.NetworkMessageHandler;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Network message handler for CMG messages.
+ *
+ * <p>This handler buffers incoming messages until the parent component
signals that its local recovery has been complete (by calling
+ * {@link #onRecoveryComplete}) after which it passes the buffered messages to
the registered callback and then continues to behave like a
+ * regular message handler.
+ */
+public class CmgMessageHandler implements NetworkMessageHandler {
+ private static final IgniteLogger LOG =
Loggers.forClass(ClusterManagementGroupManager.class);
+
+ private final IgniteSpinBusyLock busyLock;
+
+ private final CmgMessagesFactory msgFactory;
+
+ private final ClusterService clusterService;
+
+ private final CmgMessageCallback cmgMessageCallback;
+
+ @Nullable
+ private List<NetworkMessageContext> messageQueue = new ArrayList<>();
+
+ private boolean isRecoveryComplete = false;
+
+ private static class NetworkMessageContext {
+ final NetworkMessage message;
+
+ final ClusterNode sender;
+
+ @Nullable
+ final Long correlationId;
Review Comment:
```suggestion
final @Nullable Long correlationId;
```
--
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]