shishkovilja commented on code in PR #12531: URL: https://github.com/apache/ignite/pull/12531#discussion_r2598660627
########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticRequest.java: ########## @@ -0,0 +1,180 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class IgniteDiagnosticRequest implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** Originator node id. */ + @Order(1) + private UUID nodeId; + + /** Infos to send to a remote node. */ + @Order(2) + private @Nullable LinkedHashSet<DiagnosticBaseInfo> infos; + + /** Local message related to remote info. */ + private final Map<Object, List<String>> msgs = new LinkedHashMap<>(); + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticRequest() { + // No-op. + } + + /** + * Creates a diagnostic info holder. + * + * @param nodeId Originator node ID. + */ + IgniteDiagnosticRequest(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * Creates a diagnostic request. + * + * @param futId Future ID. + * @param nodeId Node ID. + * @param infos Diagnostic infos. + */ + public IgniteDiagnosticRequest(long futId, UUID nodeId, @Nullable LinkedHashSet<DiagnosticBaseInfo> infos) { Review Comment: ```suggestion public IgniteDiagnosticRequest(long futId, UUID nodeId, @Nullable Collection<DiagnosticBaseInfo> infos) { ``` ########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticRequest.java: ########## @@ -0,0 +1,180 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class IgniteDiagnosticRequest implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** Originator node id. */ + @Order(1) + private UUID nodeId; + + /** Infos to send to a remote node. */ + @Order(2) + private @Nullable LinkedHashSet<DiagnosticBaseInfo> infos; + + /** Local message related to remote info. */ + private final Map<Object, List<String>> msgs = new LinkedHashMap<>(); + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticRequest() { + // No-op. + } + + /** + * Creates a diagnostic info holder. + * + * @param nodeId Originator node ID. + */ + IgniteDiagnosticRequest(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * Creates a diagnostic request. + * + * @param futId Future ID. + * @param nodeId Node ID. + * @param infos Diagnostic infos. + */ + public IgniteDiagnosticRequest(long futId, UUID nodeId, @Nullable LinkedHashSet<DiagnosticBaseInfo> infos) { + this(nodeId); + + this.futId = futId; + this.infos = infos; Review Comment: ```suggestion this.infos = toLinkedHashSet(infos); ``` (see some details in the below comments) ########## modules/core/src/test/java/org/apache/ignite/internal/managers/IgniteDiagnosticMessagesTest.java: ########## @@ -222,7 +222,7 @@ private CacheConfiguration cacheConfiguration(CacheAtomicityMode atomicityMode) * @throws Exception If failed. */ @Test - public void testSeveralLongRunningTxs() throws Exception { + public void testSeveralLongRunningTxs() throws Exception { Review Comment: Redundant modification. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java: ########## @@ -914,12 +872,15 @@ public IgniteInternalFuture<String> requestDiagnosticInfo(final UUID nodeId, Com /** * @param nodeId Target node ID. - * @param info Compound info. + * @param infos Diagnostic infos to send. * @return Message future. */ - private IgniteInternalFuture<IgniteDiagnosticInfo> sendDiagnosticMessage(UUID nodeId, CompoundInfo info) { + private IgniteInternalFuture<String> sendDiagnosticMessage( + UUID nodeId, + @Nullable LinkedHashSet<IgniteDiagnosticRequest.DiagnosticBaseInfo> infos Review Comment: ```suggestion @Nullable Collection<IgniteDiagnosticRequest.DiagnosticBaseInfo> infos ``` ########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticResponse.java: ########## @@ -0,0 +1,84 @@ +/* + * 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; + +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** */ +public class IgniteDiagnosticResponse implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** */ + @Order(value = 1, method = "responseInfo") + private @Nullable String respInfo; + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticResponse() { + // No-op. + } + + /** + * Creates a diagnostic response. + * + * @param futId Future ID. + * @param resp Diagnostic info result. + */ + public IgniteDiagnosticResponse(long futId, String resp) { Review Comment: ```suggestion public IgniteDiagnosticResponse(long futId, @Nullable String resp) { ``` ########## modules/core/src/main/java/org/apache/ignite/internal/TxEntriesInfo.java: ########## @@ -0,0 +1,139 @@ +/* + * 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; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Objects; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** */ +public final class TxEntriesInfo extends IgniteDiagnosticRequest.DiagnosticBaseInfo { + /** */ + @Order(0) + private int cacheId; + + /** */ + @Order(1) + private Collection<KeyCacheObject> keys; + + /** + * Empty constructor required by {@link GridIoMessageFactory}. + */ + public TxEntriesInfo() { + // No-op. + } + + /** + * @param cacheId Cache ID. + * @param keys Keys. + */ + TxEntriesInfo(int cacheId, Collection<KeyCacheObject> keys) { + this.cacheId = cacheId; + this.keys = new HashSet<>(keys); + } + + /** */ + public int cacheId() { + return cacheId; + } + + /** */ + public void cacheId(int cacheId) { + this.cacheId = cacheId; + } + + /** */ + public Collection<KeyCacheObject> keys() { + return keys; + } + + /** */ + public void keys(Collection<KeyCacheObject> keys) { + this.keys = keys; + } + + /** {@inheritDoc} */ + @Override public short directType() { + return -64; + } + + /** {@inheritDoc} */ + @Override public void appendInfo(StringBuilder sb, GridKernalContext ctx) { + sb.append(U.nl()); + + GridCacheContext<?, ?> cctx = ctx.cache().context().cacheContext(cacheId); + + if (cctx == null) { + sb.append("Failed to find cache with id: ").append(cacheId); + + return; + } + + try { + for (KeyCacheObject key : keys) + key.finishUnmarshal(cctx.cacheObjectContext(), null); + } + catch (IgniteCheckedException e) { + ctx.cluster().diagnosticLog().error("Failed to unmarshal key: " + e, e); + + sb.append("Failed to unmarshal key: ").append(e).append(U.nl()); + } + + sb.append("Cache entries [cacheId=").append(cacheId) + .append(", cacheName=").append(cctx.name()).append("]: "); + + for (KeyCacheObject key : keys) { + GridCacheMapEntry e = (GridCacheMapEntry)cctx.cache().peekEx(key); + + sb.append(U.nl()).append(" Key [key=").append(key).append(", entry=").append(e).append("]"); + } + } + + /** {@inheritDoc} */ + @Override public void merge(IgniteDiagnosticRequest.DiagnosticBaseInfo other) { + TxEntriesInfo other0 = (TxEntriesInfo)other; + + assert other0 != null && cacheId == other0.cacheId : other; + + this.keys.addAll(other0.keys); Review Comment: ```suggestion keys.addAll(other0.keys); ``` ########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticRequest.java: ########## @@ -0,0 +1,180 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class IgniteDiagnosticRequest implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** Originator node id. */ + @Order(1) + private UUID nodeId; + + /** Infos to send to a remote node. */ + @Order(2) + private @Nullable LinkedHashSet<DiagnosticBaseInfo> infos; + + /** Local message related to remote info. */ + private final Map<Object, List<String>> msgs = new LinkedHashMap<>(); + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticRequest() { + // No-op. + } + + /** + * Creates a diagnostic info holder. + * + * @param nodeId Originator node ID. + */ + IgniteDiagnosticRequest(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * Creates a diagnostic request. + * + * @param futId Future ID. + * @param nodeId Node ID. + * @param infos Diagnostic infos. + */ + public IgniteDiagnosticRequest(long futId, UUID nodeId, @Nullable LinkedHashSet<DiagnosticBaseInfo> infos) { + this(nodeId); + + this.futId = futId; + this.infos = infos; + } + + /** + * @return Initial message. + */ + public String message() { + StringBuilder sb = new StringBuilder(); + + for (List<String> msgs0 : msgs.values()) { + for (String msg : msgs0) { + if (sb.length() > 0) + sb.append('\n'); + + sb.append(msg); + } + } + + return sb.toString(); + } + + /** + * @param msg Message. + * @param baseInfo Info or {@code null} if only basic info is needed. + */ + void add(String msg, @Nullable IgniteDiagnosticRequest.DiagnosticBaseInfo baseInfo) { + Object key = baseInfo != null ? baseInfo : getClass(); + + msgs.computeIfAbsent(key, k -> new ArrayList<>()).add(msg); + + if (baseInfo != null) { + if (infos == null) + infos = new LinkedHashSet<>(); + + if (!infos.add(baseInfo) && baseInfo instanceof TxEntriesInfo) { + for (IgniteDiagnosticRequest.DiagnosticBaseInfo baseInfo0 : infos) { + if (baseInfo0.equals(baseInfo)) + baseInfo0.merge(baseInfo); + } + } + } + } + + /** */ + public UUID nodeId() { + return nodeId; + } + + /** */ + public void nodeId(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * @return Future ID. + */ + public long futureId() { + return futId; + } + + /** */ + public void futureId(long futId) { + this.futId = futId; + } + + /** @return Compound diagnostic infos. */ + public @Nullable LinkedHashSet<DiagnosticBaseInfo> infos() { Review Comment: ```suggestion public @Nullable Collection<DiagnosticBaseInfo> infos() { ``` ########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticResponse.java: ########## @@ -0,0 +1,84 @@ +/* + * 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; + +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** */ +public class IgniteDiagnosticResponse implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** */ + @Order(value = 1, method = "responseInfo") + private @Nullable String respInfo; + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticResponse() { + // No-op. + } + + /** + * Creates a diagnostic response. + * + * @param futId Future ID. + * @param resp Diagnostic info result. + */ + public IgniteDiagnosticResponse(long futId, String resp) { + this.futId = futId; + respInfo = resp; + } + + /** + * @return Future ID. + */ + public long futureId() { + return futId; + } + + /** */ + public void futureId(long futId) { + this.futId = futId; + } + + /** */ + public @Nullable String responseInfo() { + return respInfo; + } + + /** */ + public void responseInfo(@Nullable String infoResp) { + this.respInfo = infoResp; Review Comment: ```suggestion this.respInfo = respInfo; ``` ########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticRequest.java: ########## @@ -0,0 +1,180 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class IgniteDiagnosticRequest implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** Originator node id. */ + @Order(1) + private UUID nodeId; + + /** Infos to send to a remote node. */ + @Order(2) + private @Nullable LinkedHashSet<DiagnosticBaseInfo> infos; + + /** Local message related to remote info. */ + private final Map<Object, List<String>> msgs = new LinkedHashMap<>(); + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticRequest() { + // No-op. + } + + /** + * Creates a diagnostic info holder. + * + * @param nodeId Originator node ID. + */ + IgniteDiagnosticRequest(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * Creates a diagnostic request. + * + * @param futId Future ID. + * @param nodeId Node ID. + * @param infos Diagnostic infos. + */ + public IgniteDiagnosticRequest(long futId, UUID nodeId, @Nullable LinkedHashSet<DiagnosticBaseInfo> infos) { + this(nodeId); + + this.futId = futId; + this.infos = infos; + } + + /** + * @return Initial message. + */ + public String message() { + StringBuilder sb = new StringBuilder(); + + for (List<String> msgs0 : msgs.values()) { + for (String msg : msgs0) { + if (sb.length() > 0) + sb.append('\n'); + + sb.append(msg); + } + } + + return sb.toString(); + } + + /** + * @param msg Message. + * @param baseInfo Info or {@code null} if only basic info is needed. + */ + void add(String msg, @Nullable IgniteDiagnosticRequest.DiagnosticBaseInfo baseInfo) { + Object key = baseInfo != null ? baseInfo : getClass(); + + msgs.computeIfAbsent(key, k -> new ArrayList<>()).add(msg); + + if (baseInfo != null) { + if (infos == null) + infos = new LinkedHashSet<>(); + + if (!infos.add(baseInfo) && baseInfo instanceof TxEntriesInfo) { + for (IgniteDiagnosticRequest.DiagnosticBaseInfo baseInfo0 : infos) { + if (baseInfo0.equals(baseInfo)) + baseInfo0.merge(baseInfo); + } + } + } + } + + /** */ + public UUID nodeId() { + return nodeId; + } + + /** */ + public void nodeId(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * @return Future ID. + */ + public long futureId() { + return futId; + } + + /** */ + public void futureId(long futId) { + this.futId = futId; + } + + /** @return Compound diagnostic infos. */ + public @Nullable LinkedHashSet<DiagnosticBaseInfo> infos() { + return infos; + } + + /** */ + public void infos(@Nullable Collection<DiagnosticBaseInfo> infos) { Review Comment: Lets create separate method for such cast, eg.: ``` public void infos(@Nullable Collection<DiagnosticBaseInfo> infos) { // Deserialization supports only `Collection` interface in MessageReader#readCollection. this.infos = toLinkedHashSet(infos); } /** */ private static @Nullable LinkedHashSet<DiagnosticBaseInfo> toLinkedHashSet(@Nullable Collection<DiagnosticBaseInfo> infos) { return infos == null ? null : infos instanceof LinkedHashSet ? (LinkedHashSet<DiagnosticBaseInfo>)infos : new LinkedHashSet<>(infos); } ``` ########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticResponse.java: ########## @@ -0,0 +1,84 @@ +/* + * 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; + +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** */ +public class IgniteDiagnosticResponse implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** */ + @Order(value = 1, method = "responseInfo") + private @Nullable String respInfo; + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticResponse() { + // No-op. + } + + /** + * Creates a diagnostic response. + * + * @param futId Future ID. + * @param resp Diagnostic info result. + */ + public IgniteDiagnosticResponse(long futId, String resp) { + this.futId = futId; + respInfo = resp; + } + + /** + * @return Future ID. + */ + public long futureId() { + return futId; + } + + /** */ + public void futureId(long futId) { + this.futId = futId; + } + + /** */ + public @Nullable String responseInfo() { + return respInfo; + } + + /** */ + public void responseInfo(@Nullable String infoResp) { Review Comment: ```suggestion public void responseInfo(@Nullable String respInfo) { ``` ########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticRequest.java: ########## @@ -0,0 +1,180 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class IgniteDiagnosticRequest implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** Originator node id. */ + @Order(1) + private UUID nodeId; + + /** Infos to send to a remote node. */ + @Order(2) + private @Nullable LinkedHashSet<DiagnosticBaseInfo> infos; + + /** Local message related to remote info. */ + private final Map<Object, List<String>> msgs = new LinkedHashMap<>(); + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticRequest() { + // No-op. + } + + /** + * Creates a diagnostic info holder. + * + * @param nodeId Originator node ID. + */ + IgniteDiagnosticRequest(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * Creates a diagnostic request. + * + * @param futId Future ID. + * @param nodeId Node ID. + * @param infos Diagnostic infos. + */ + public IgniteDiagnosticRequest(long futId, UUID nodeId, @Nullable LinkedHashSet<DiagnosticBaseInfo> infos) { + this(nodeId); + + this.futId = futId; + this.infos = infos; + } + + /** + * @return Initial message. + */ + public String message() { + StringBuilder sb = new StringBuilder(); + + for (List<String> msgs0 : msgs.values()) { + for (String msg : msgs0) { + if (sb.length() > 0) + sb.append('\n'); + + sb.append(msg); + } + } + + return sb.toString(); + } + + /** + * @param msg Message. + * @param baseInfo Info or {@code null} if only basic info is needed. + */ + void add(String msg, @Nullable IgniteDiagnosticRequest.DiagnosticBaseInfo baseInfo) { + Object key = baseInfo != null ? baseInfo : getClass(); + + msgs.computeIfAbsent(key, k -> new ArrayList<>()).add(msg); + + if (baseInfo != null) { + if (infos == null) + infos = new LinkedHashSet<>(); + + if (!infos.add(baseInfo) && baseInfo instanceof TxEntriesInfo) { + for (IgniteDiagnosticRequest.DiagnosticBaseInfo baseInfo0 : infos) { + if (baseInfo0.equals(baseInfo)) + baseInfo0.merge(baseInfo); + } + } + } + } + + /** */ + public UUID nodeId() { + return nodeId; + } + + /** */ + public void nodeId(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * @return Future ID. + */ + public long futureId() { + return futId; + } + + /** */ + public void futureId(long futId) { + this.futId = futId; + } + + /** @return Compound diagnostic infos. */ + public @Nullable LinkedHashSet<DiagnosticBaseInfo> infos() { + return infos; + } + + /** */ Review Comment: ```suggestion /** Sets compound diagnostic infos. */ ``` ########## modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticRequest.java: ########## @@ -0,0 +1,180 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.internal.managers.communication.GridIoMessageFactory; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** + * + */ +public class IgniteDiagnosticRequest implements Message { + /** */ + @Order(value = 0, method = "futureId") + private long futId; + + /** Originator node id. */ + @Order(1) + private UUID nodeId; + + /** Infos to send to a remote node. */ + @Order(2) + private @Nullable LinkedHashSet<DiagnosticBaseInfo> infos; + + /** Local message related to remote info. */ + private final Map<Object, List<String>> msgs = new LinkedHashMap<>(); + + /** + * Default constructor required by {@link GridIoMessageFactory}. + */ + public IgniteDiagnosticRequest() { + // No-op. + } + + /** + * Creates a diagnostic info holder. + * + * @param nodeId Originator node ID. + */ + IgniteDiagnosticRequest(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * Creates a diagnostic request. + * + * @param futId Future ID. + * @param nodeId Node ID. + * @param infos Diagnostic infos. + */ + public IgniteDiagnosticRequest(long futId, UUID nodeId, @Nullable LinkedHashSet<DiagnosticBaseInfo> infos) { + this(nodeId); + + this.futId = futId; + this.infos = infos; + } + + /** + * @return Initial message. + */ + public String message() { + StringBuilder sb = new StringBuilder(); + + for (List<String> msgs0 : msgs.values()) { + for (String msg : msgs0) { + if (sb.length() > 0) + sb.append('\n'); + + sb.append(msg); + } + } + + return sb.toString(); + } + + /** + * @param msg Message. + * @param baseInfo Info or {@code null} if only basic info is needed. + */ + void add(String msg, @Nullable IgniteDiagnosticRequest.DiagnosticBaseInfo baseInfo) { + Object key = baseInfo != null ? baseInfo : getClass(); + + msgs.computeIfAbsent(key, k -> new ArrayList<>()).add(msg); + + if (baseInfo != null) { + if (infos == null) + infos = new LinkedHashSet<>(); + + if (!infos.add(baseInfo) && baseInfo instanceof TxEntriesInfo) { + for (IgniteDiagnosticRequest.DiagnosticBaseInfo baseInfo0 : infos) { + if (baseInfo0.equals(baseInfo)) + baseInfo0.merge(baseInfo); + } + } + } + } + + /** */ + public UUID nodeId() { + return nodeId; + } + + /** */ + public void nodeId(UUID nodeId) { + this.nodeId = nodeId; + } + + /** + * @return Future ID. + */ + public long futureId() { + return futId; + } + + /** */ + public void futureId(long futId) { + this.futId = futId; + } + + /** @return Compound diagnostic infos. */ Review Comment: ```suggestion /** @return Compound diagnostic infos. */ ``` -- 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]
