This is an automated email from the ASF dual-hosted git repository.
vldpyatkov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new f2ec36f7e16 IGNITE-29299 [Thin client] Expose server connection ID in
handshake and monitoring events (#13836)
f2ec36f7e16 is described below
commit f2ec36f7e166ca311cbf37c67dd9e14000c64709
Author: Vladislav Pyatkov <[email protected]>
AuthorDate: Wed Nov 18 14:28:12 2026 +0300
IGNITE-29299 [Thin client] Expose server connection ID in handshake and
monitoring events (#13836)
---
.../platform/client/ClientBitmaskFeature.java | 5 +-
.../platform/client/ClientRequestHandler.java | 4 +
.../IgniteClientConnectionEventListenerTest.java | 16 +-
.../thin/events/IgniteClientConnectionIdTest.java | 246 +++++++++++++++++++++
.../org/apache/ignite/client/ClientTestSuite.java | 2 +
.../client/events/ConnectionDescription.java | 17 +-
.../client/thin/ProtocolBitmaskFeature.java | 5 +-
.../internal/client/thin/TcpClientChannel.java | 30 ++-
8 files changed, 311 insertions(+), 14 deletions(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
index 8562155e347..2f400946a8f 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
@@ -115,7 +115,10 @@ public enum ClientBitmaskFeature implements
ThinProtocolFeature {
QRY_INITIATOR_ID(23),
/** Cache affinity configuration. */
- CACHE_AFFINITY_CFG(24);
+ CACHE_AFFINITY_CFG(24),
+
+ /** Server-assigned connection ID in the handshake response. */
+ CONNECTION_ID(25);
/** */
private static final EnumSet<ClientBitmaskFeature>
ALL_FEATURES_AS_ENUM_SET =
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
index 85298183728..8a2cb69b2fc 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
@@ -41,6 +41,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.plugin.security.SecurityException;
import static
org.apache.ignite.IgniteSystemProperties.IGNITE_THIN_CLIENT_ASYNC_REQUESTS_WAIT_TIMEOUT;
+import static
org.apache.ignite.internal.processors.platform.client.ClientBitmaskFeature.CONNECTION_ID;
import static
org.apache.ignite.internal.processors.platform.client.ClientProtocolVersionFeature.BITMAP_FEATURES;
import static
org.apache.ignite.internal.processors.platform.client.ClientProtocolVersionFeature.PARTITION_AWARENESS;
@@ -176,6 +177,9 @@ public class ClientRequestHandler implements
ClientListenerRequestHandler {
if (protocolCtx.isFeatureSupported(PARTITION_AWARENESS))
writer.writeUuid(ctx.kernalContext().localNodeId());
+
+ if (protocolCtx.isFeatureSupported(CONNECTION_ID))
+ writer.writeLong(ctx.connectionId());
}
/** {@inheritDoc} */
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/events/IgniteClientConnectionEventListenerTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/events/IgniteClientConnectionEventListenerTest.java
index 91ed01bf3fa..4040987d422 100644
---
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/events/IgniteClientConnectionEventListenerTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/events/IgniteClientConnectionEventListenerTest.java
@@ -65,7 +65,17 @@ public class IgniteClientConnectionEventListenerTest extends
GridCommonAbstractT
/** */
@Test
public void testBasic() throws Exception {
- ProtocolVersion srvVer = ProtocolVersion.V1_6_0;
+ testBasic(ProtocolVersion.V1_6_0);
+ }
+
+ /** Tests a server with feature negotiation but without connection ID
support. */
+ @Test
+ public void testWithoutConnectionIdFeature() throws Exception {
+ testBasic(ProtocolVersion.V1_7_0);
+ }
+
+ /** @param srvVer Server protocol version. */
+ private void testBasic(ProtocolVersion srvVer) throws Exception {
try (FakeIgniteServer srv = new FakeIgniteServer(LOCALHOST, SRV_PORT,
log(), srvVer)) {
srv.start();
@@ -95,6 +105,7 @@ public class IgniteClientConnectionEventListenerTest extends
GridCommonAbstractT
assertEquals(SRV_PORT,
hsStartEv.connectionDescription().remoteAddress().getPort());
assertEquals(LOCALHOST,
hsStartEv.connectionDescription().localAddress().getAddress());
assertEquals(null,
hsStartEv.connectionDescription().serverNodeId());
+ assertNull(hsStartEv.connectionDescription().connectionId());
HandshakeSuccessEvent hsSuccEv =
(HandshakeSuccessEvent)evSet.get(HandshakeSuccessEvent.class);
@@ -103,6 +114,7 @@ public class IgniteClientConnectionEventListenerTest
extends GridCommonAbstractT
assertEquals(SRV_PORT,
hsSuccEv.connectionDescription().remoteAddress().getPort());
assertEquals(LOCALHOST,
hsSuccEv.connectionDescription().localAddress().getAddress());
assertEquals(srv.nodeId(),
hsSuccEv.connectionDescription().serverNodeId());
+ assertNull(hsSuccEv.connectionDescription().connectionId());
assertTrue(System.nanoTime() - startNano >=
hsSuccEv.elapsedTime(TimeUnit.NANOSECONDS));
}
@@ -115,6 +127,7 @@ public class IgniteClientConnectionEventListenerTest
extends GridCommonAbstractT
assertEquals(SRV_PORT,
closedEv.connectionDescription().remoteAddress().getPort());
assertEquals(LOCALHOST,
closedEv.connectionDescription().localAddress().getAddress());
assertEquals(srv.nodeId(),
closedEv.connectionDescription().serverNodeId());
+ assertNull(closedEv.connectionDescription().connectionId());
}
}
@@ -213,6 +226,7 @@ public class IgniteClientConnectionEventListenerTest
extends GridCommonAbstractT
Event failEv = (Event)evSet.get(eventCls);
assertNotNull(failEv);
+ assertNull(failEv.connectionDescription().connectionId());
assertEquals(failEv.connectionDescription().protocol(),
"ProtocolContext [version=" + ProtocolVersion.V1_7_0
+ ", features=[]]");
assertEquals(LOCALHOST,
failEv.connectionDescription().remoteAddress().getAddress());
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/events/IgniteClientConnectionIdTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/events/IgniteClientConnectionIdTest.java
new file mode 100644
index 00000000000..8a291342439
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/events/IgniteClientConnectionIdTest.java
@@ -0,0 +1,246 @@
+/*
+ * 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.client.thin.events;
+
+import java.io.DataInputStream;
+import java.net.Socket;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.IgniteClientFuture;
+import org.apache.ignite.client.events.ConnectionClosedEvent;
+import org.apache.ignite.client.events.ConnectionDescription;
+import org.apache.ignite.client.events.ConnectionEventListener;
+import org.apache.ignite.client.events.HandshakeStartEvent;
+import org.apache.ignite.client.events.HandshakeSuccessEvent;
+import org.apache.ignite.client.events.RequestEvent;
+import org.apache.ignite.client.events.RequestEventListener;
+import org.apache.ignite.client.events.RequestFailEvent;
+import org.apache.ignite.client.events.RequestStartEvent;
+import org.apache.ignite.client.events.RequestSuccessEvent;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.internal.binary.BinaryReaderEx;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.BinaryWriterEx;
+import org.apache.ignite.internal.binary.streams.BinaryStreams;
+import org.apache.ignite.internal.client.thin.AbstractThinClientTest;
+import org.apache.ignite.internal.processors.odbc.ClientListenerProcessor;
+import org.apache.ignite.mxbean.ClientProcessorMXBean;
+import org.apache.ignite.spi.systemview.view.ClientConnectionView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.junit.Test;
+
+import static
org.apache.ignite.internal.client.thin.ProtocolVersion.LATEST_VER;
+import static
org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLI_CONN_VIEW;
+import static org.apache.ignite.internal.util.CommonUtils.HANDSHAKE;
+import static org.apache.ignite.internal.util.CommonUtils.THIN_CLIENT;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotEquals;
+
+/** Tests server-assigned connection IDs in thin client events and
diagnostics. */
+public class IgniteClientConnectionIdTest extends AbstractThinClientTest {
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ startGrid(0);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /** Tests IDs in events, including an asynchronous failure delivered after
reconnection. */
+ @Test
+ public void testConnectionIdAfterReconnect() throws Exception {
+ List<ConnectionDescription> starts = new CopyOnWriteArrayList<>();
+ List<ConnectionDescription> connections = new CopyOnWriteArrayList<>();
+ List<ConnectionDescription> closed = new CopyOnWriteArrayList<>();
+ List<RequestEvent> requests = new CopyOnWriteArrayList<>();
+ List<String> msgs = new CopyOnWriteArrayList<>();
+ BlockingQueue<Runnable> completions = new LinkedBlockingQueue<>();
+ ListeningTestLogger clientLog = new
ListeningTestLogger(getClientConfiguration().getLogger());
+
+ clientLog.registerListener(msgs::add);
+
+ ClientConfiguration cfg = getClientConfiguration(grid(0))
+ .setPartitionAwarenessEnabled(false)
+ .setClusterDiscoveryEnabled(false)
+ .setLogger(clientLog)
+ .setAsyncContinuationExecutor(completions::add)
+ .setEventListeners(new ConnectionEventListener() {
+ @Override public void onHandshakeStart(HandshakeStartEvent
event) {
+ starts.add(event.connectionDescription());
+ }
+
+ @Override public void onHandshakeSuccess(HandshakeSuccessEvent
event) {
+ connections.add(event.connectionDescription());
+ }
+
+ @Override public void onConnectionClosed(ConnectionClosedEvent
event) {
+ closed.add(event.connectionDescription());
+ }
+ }, new RequestEventListener() {
+ @Override public void onRequestStart(RequestStartEvent event) {
+ requests.add(event);
+ }
+
+ @Override public void onRequestSuccess(RequestSuccessEvent
event) {
+ requests.add(event);
+ }
+
+ @Override public void onRequestFail(RequestFailEvent event) {
+ requests.add(event);
+ }
+ });
+
+ try (IgniteClient client = Ignition.startClient(cfg)) {
+ assertEquals(1, connections.size());
+
+ ConnectionDescription oldConn = connections.get(0);
+ Long oldId = oldConn.connectionId();
+
+ assertConnectionId(oldConn);
+ assertTrue(msgs.stream().anyMatch(msg -> msg.startsWith("Handshake
succeeded")
+ && msg.contains("connectionId=" + oldId)));
+
+ requests.clear();
+
+ client.cacheNames();
+
+ assertEquals(2, requests.size());
+ assertTrue(requests.get(0) instanceof RequestStartEvent);
+ assertTrue(requests.get(1) instanceof RequestSuccessEvent);
+ assertEquals(requests.get(0).requestId(),
requests.get(1).requestId());
+
+ for (RequestEvent evt : requests)
+ assertEquals(oldId,
evt.connectionDescription().connectionId());
+
+ IgniteClientFuture<Void> failed =
client.cache("non-existent").putAsync(1, 1);
+ Runnable completion = completions.poll(10, TimeUnit.SECONDS);
+
+ assertNotNull(completion);
+ assertFalse(failed.isDone());
+
+ RequestEvent failedStart = requests.get(requests.size() - 1);
+
+ assertTrue(failedStart instanceof RequestStartEvent);
+
+ ClientProcessorMXBean mxBean = getMxBean(grid(0).name(), "Clients",
+ ClientListenerProcessor.class, ClientProcessorMXBean.class);
+
+ assertTrue(mxBean.dropConnection(oldId));
+ assertTrue(GridTestUtils.waitForCondition(() -> closed.size() ==
1, 10_000));
+ assertEquals(oldId, closed.get(0).connectionId());
+
+ client.cacheNames();
+
+ assertEquals(2, connections.size());
+
+ ConnectionDescription newConn = connections.get(1);
+
+ assertConnectionId(newConn);
+ assertNotEquals(oldId, newConn.connectionId());
+ assertEquals(newConn.connectionId(), requests.get(requests.size()
- 1).connectionDescription().connectionId());
+
+ completion.run();
+
+ GridTestUtils.assertThrowsAnyCause(log, failed::get,
ClientException.class, null);
+
+ RequestEvent failedEvt = requests.get(requests.size() - 1);
+
+ assertTrue(failedEvt instanceof RequestFailEvent);
+ assertEquals(failedStart.requestId(), failedEvt.requestId());
+ assertEquals(oldId,
failedEvt.connectionDescription().connectionId());
+ assertEquals(oldId, oldConn.connectionId());
+ assertEquals(oldId, closed.get(0).connectionId());
+ assertTrue(msgs.stream().anyMatch(msg -> msg.startsWith("Client
disconnected")
+ && msg.contains("connectionId=" + oldId)));
+ assertTrue(msgs.stream().anyMatch(msg -> msg.startsWith("Failed to
process response")
+ && msg.contains("connectionId=" + oldId) &&
msg.contains("requestId=" + failedStart.requestId())));
+ }
+
+ assertEquals(2, closed.size());
+ assertEquals(connections.get(1).connectionId(),
closed.get(1).connectionId());
+ assertEquals(2, starts.size());
+
+ for (ConnectionDescription start : starts)
+ assertNull(start.connectionId());
+ }
+
+ /** Tests that a client not advertising the feature receives the original
handshake response. */
+ @Test
+ public void testHandshakeWithoutConnectionIdFeature() throws Exception {
+ try (Socket sock = new Socket(clientHost(grid(0).localNode()),
clientPort(grid(0).localNode()))) {
+ sock.setSoTimeout(10_000);
+
+ try (BinaryWriterEx writer = BinaryUtils.writerWithoutSchema(null,
BinaryStreams.outputStream(32))) {
+ writer.writeInt(0);
+ writer.writeByte((byte)HANDSHAKE);
+ writer.writeShort(LATEST_VER.major());
+ writer.writeShort(LATEST_VER.minor());
+ writer.writeShort(LATEST_VER.patch());
+ writer.writeByte(THIN_CLIENT);
+ writer.writeByteArray(new byte[0]);
+ writer.out().writeInt(0, writer.out().position() - 4);
+
+ sock.getOutputStream().write(writer.out().arrayCopy());
+ }
+
+ DataInputStream in = new DataInputStream(sock.getInputStream());
+ byte[] res = new byte[Integer.reverseBytes(in.readInt())];
+
+ in.readFully(res);
+
+ try (BinaryReaderEx reader = BinaryUtils.reader(null,
BinaryStreams.inputStream(res), null, true, true)) {
+ assertTrue(reader.readBoolean());
+ assertArrayEquals(new byte[0], reader.readByteArray());
+ assertEquals(grid(0).localNode().id(), reader.readUuid());
+ assertEquals(0, reader.available());
+ }
+ }
+ }
+
+ /** @param conn Connection description to compare with the server system
view. */
+ private void assertConnectionId(ConnectionDescription conn) {
+ assertNotNull(conn.connectionId());
+ assertEquals(grid(0).localNode().id(), conn.serverNodeId());
+
+ SystemView<ClientConnectionView> view =
grid(0).context().systemView().view(CLI_CONN_VIEW);
+
+ for (ClientConnectionView row : view) {
+ if (row.remoteAddress().equals(conn.localAddress())) {
+ assertEquals(Long.valueOf(row.connectionId()),
conn.connectionId());
+
+ return;
+ }
+ }
+
+ fail("Connection is missing from SYS.CLIENT_CONNECTIONS: " +
conn.connectionId());
+ }
+}
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/client/ClientTestSuite.java
b/modules/indexing/src/test/java/org/apache/ignite/client/ClientTestSuite.java
index fc035b35b2c..bda1d629471 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/client/ClientTestSuite.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/client/ClientTestSuite.java
@@ -55,6 +55,7 @@ import
org.apache.ignite.internal.client.thin.ThinClientPartitionAwarenessUnstab
import
org.apache.ignite.internal.client.thin.ThinClientPutAllConflictKeepBinaryTest;
import org.apache.ignite.internal.client.thin.TimeoutTest;
import
org.apache.ignite.internal.client.thin.events.IgniteClientConnectionEventListenerTest;
+import
org.apache.ignite.internal.client.thin.events.IgniteClientConnectionIdTest;
import
org.apache.ignite.internal.client.thin.events.IgniteClientLifecycleEventListenerTest;
import
org.apache.ignite.internal.client.thin.events.IgniteClientRequestEventListenerTest;
import org.junit.runner.RunWith;
@@ -105,6 +106,7 @@ import org.junit.runners.Suite;
ThinClientPutAllConflictKeepBinaryTest.class,
MetadataRegistrationTest.class,
IgniteClientConnectionEventListenerTest.class,
+ IgniteClientConnectionIdTest.class,
IgniteClientRequestEventListenerTest.class,
IgniteClientLifecycleEventListenerTest.class,
ThinClientEnpointsDiscoveryTest.class,
diff --git
a/modules/thin-client/api/src/main/java/org/apache/ignite/client/events/ConnectionDescription.java
b/modules/thin-client/api/src/main/java/org/apache/ignite/client/events/ConnectionDescription.java
index 672ba735f5b..ed16e542c7d 100644
---
a/modules/thin-client/api/src/main/java/org/apache/ignite/client/events/ConnectionDescription.java
+++
b/modules/thin-client/api/src/main/java/org/apache/ignite/client/events/ConnectionDescription.java
@@ -32,6 +32,9 @@ public class ConnectionDescription {
/** Server node id. */
private final UUID srvNodeId;
+ /** Server-assigned connection ID. */
+ private final @Nullable Long connId;
+
/** */
private final String protocol;
@@ -40,12 +43,15 @@ public class ConnectionDescription {
* @param rmtAddr Remote connection address.
* @param protocol String representation of a connection protocol details.
* @param srvNodeId Server node id.
+ * @param connId Server-assigned connection ID, or {@code null} if
unavailable.
*/
- public ConnectionDescription(InetSocketAddress locAddr, InetSocketAddress
rmtAddr, String protocol, UUID srvNodeId) {
+ public ConnectionDescription(InetSocketAddress locAddr, InetSocketAddress
rmtAddr, String protocol, UUID srvNodeId,
+ @Nullable Long connId) {
this.locAddr = locAddr;
this.rmtAddr = rmtAddr;
this.protocol = protocol;
this.srvNodeId = srvNodeId;
+ this.connId = connId;
}
/**
@@ -73,6 +79,15 @@ public class ConnectionDescription {
return srvNodeId;
}
+ /**
+ * Returns the server-assigned connection ID, matching {@code
SYS.CLIENT_CONNECTIONS}.
+ *
+ * @return Connection ID, or {@code null} before a successful handshake or
if unsupported by the server.
+ */
+ @Nullable public Long connectionId() {
+ return connId;
+ }
+
/**
* @return String representation of connection protocol.
*/
diff --git
a/modules/thin-client/api/src/main/java/org/apache/ignite/internal/client/thin/ProtocolBitmaskFeature.java
b/modules/thin-client/api/src/main/java/org/apache/ignite/internal/client/thin/ProtocolBitmaskFeature.java
index b3287169a2e..1f72f9432e0 100644
---
a/modules/thin-client/api/src/main/java/org/apache/ignite/internal/client/thin/ProtocolBitmaskFeature.java
+++
b/modules/thin-client/api/src/main/java/org/apache/ignite/internal/client/thin/ProtocolBitmaskFeature.java
@@ -112,7 +112,10 @@ public enum ProtocolBitmaskFeature {
QRY_INITIATOR_ID(23),
/** Cache affinity configuration. */
- CACHE_AFFINITY_CFG(24);
+ CACHE_AFFINITY_CFG(24),
+
+ /** Server-assigned connection ID in the handshake response. */
+ CONNECTION_ID(25);
/** */
private static final EnumSet<ProtocolBitmaskFeature>
ALL_FEATURES_AS_ENUM_SET =
diff --git
a/modules/thin-client/impl/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
b/modules/thin-client/impl/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
index a90fbd3437b..55cf5ed48ed 100644
---
a/modules/thin-client/impl/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
+++
b/modules/thin-client/impl/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
@@ -77,6 +77,7 @@ import org.jetbrains.annotations.Nullable;
import static
org.apache.ignite.internal.client.thin.ClientUtils.awaitFutureResult;
import static
org.apache.ignite.internal.client.thin.ClientUtils.createClientConnectionException;
+import static
org.apache.ignite.internal.client.thin.ProtocolBitmaskFeature.CONNECTION_ID;
import static
org.apache.ignite.internal.client.thin.ProtocolBitmaskFeature.HEARTBEAT;
import static
org.apache.ignite.internal.client.thin.ProtocolBitmaskFeature.USER_ATTRIBUTES;
import static
org.apache.ignite.internal.client.thin.ProtocolVersion.LATEST_VER;
@@ -124,6 +125,9 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
/** Server node ID. */
private volatile UUID srvNodeId;
+ /** Server-assigned connection ID. */
+ private volatile @Nullable Long connId;
+
/** Server topology version. */
private volatile AffinityTopologyVersion srvTopVer;
@@ -253,7 +257,7 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
assert protocolCtx != null : "Protocol context after handshake is
null";
- connDesc = new ConnectionDescription(sock.localAddress(),
sock.remoteAddress(), protocolCtx.toString(), srvNodeId);
+ connDesc = new ConnectionDescription(sock.localAddress(),
sock.remoteAddress(), protocolCtx.toString(), srvNodeId, connId);
heartbeatTimer = protocolCtx.isFeatureSupported(HEARTBEAT) &&
cfg.getHeartbeatEnabled()
? initHeartbeat(cfg.getHeartbeatInterval())
@@ -273,9 +277,9 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
/** {@inheritDoc} */
@Override public void onDisconnected(@Nullable Exception e) {
if (e == null)
- log.info("Client disconnected");
+ log.info("Client disconnected [srvNodeId=" + srvNodeId + ",
connectionId=" + connId + ']');
else
- log.warning("Client disconnected: " + e.getMessage(), e);
+ log.warning("Client disconnected [srvNodeId=" + srvNodeId + ",
connectionId=" + connId + "]: " + e.getMessage(), e);
close(e);
}
@@ -437,7 +441,8 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
return res;
}
catch (IgniteCheckedException e) {
- log.warning("Failed to process response: " + e.getMessage(), e);
+ log.warning("Failed to process response [srvNodeId=" + srvNodeId +
", connectionId=" + connId
+ + ", requestId=" + reqId + "]: " + e.getMessage(), e);
RuntimeException err = convertException(e);
@@ -473,7 +478,8 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
fut.complete(res);
}
catch (Throwable t) {
- log.warning("Failed to process response: " + t.getMessage(),
t);
+ log.warning("Failed to process response [srvNodeId=" +
srvNodeId + ", connectionId=" + connId
+ + ", requestId=" + reqId + "]: " + t.getMessage(), t);
RuntimeException err = convertException(t);
@@ -738,7 +744,7 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
}
eventListener.onHandshakeStart(new
ConnectionDescription(sock.localAddress(), sock.remoteAddress(),
- new ProtocolContext(ver).toString(), null));
+ new ProtocolContext(ver).toString(), null, null));
handshakeReq(ver, user, pwd, userAttrs);
@@ -763,11 +769,15 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
srvNodeId = reader.readUuid();
}
+ if (protocolCtx.isFeatureSupported(CONNECTION_ID))
+ connId = reader.readLong();
+
if (log.isDebugEnabled())
- log.debug("Handshake succeeded [protocolVersion="
+ protocolCtx.version() + ", srvNodeId=" + srvNodeId + ']');
+ log.debug("Handshake succeeded [protocolVersion="
+ protocolCtx.version() + ", srvNodeId=" + srvNodeId
+ + ", connectionId=" + connId + ']');
eventListener.onHandshakeSuccess(
- new ConnectionDescription(sock.localAddress(),
sock.remoteAddress(), protocolCtx.toString(), srvNodeId),
+ new ConnectionDescription(sock.localAddress(),
sock.remoteAddress(), protocolCtx.toString(), srvNodeId, connId),
System.nanoTime() - startTime
);
@@ -806,7 +816,7 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
if (resultErr != null) {
ConnectionDescription connDesc = new
ConnectionDescription(sock.localAddress(), sock.remoteAddress(),
- new ProtocolContext(ver).toString(), null);
+ new ProtocolContext(ver).toString(), null,
null);
long elapsedNanos = System.nanoTime() - startTime;
@@ -832,7 +842,7 @@ class TcpClientChannel implements ClientChannel,
ClientMessageHandler, ClientCon
err = createClientConnectionException(e,
sock.remoteAddress());
eventListener.onHandshakeFail(
- new ConnectionDescription(sock.localAddress(),
sock.remoteAddress(), new ProtocolContext(ver).toString(), null),
+ new ConnectionDescription(sock.localAddress(),
sock.remoteAddress(), new ProtocolContext(ver).toString(), null, null),
System.nanoTime() - startTime,
err
);