From 007c6d5d5fc3b79ecfcc8039ddba8e78c852654e Mon Sep 17 00:00:00 2001 From: HTHou Date: Mon, 15 Jun 2026 20:46:57 +0800 Subject: [PATCH 1/7] Update thrift to 0.23.0 --- LICENSE-binary | 2 +- .../jdbc/src/main/feature/feature.xml | 2 +- .../rpc/TNonblockingTransportWrapper.java | 4 ++-- .../org/apache/iotdb/rpc/TSocketWrapper.java | 4 ++-- pom.xml | 20 +++++++++++-------- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/LICENSE-binary b/LICENSE-binary index a55f398724945..d21627d28eeae 100644 --- a/LICENSE-binary +++ b/LICENSE-binary @@ -241,7 +241,7 @@ org.eclipse.jetty.ee10:jetty-ee10-servlet:12.0.36 org.eclipse.jetty:jetty-util:12.0.36 com.google.code.findbugs:jsr305:3.0.2 com.librato.metrics:librato-java:2.1.0 -org.apache.thrift:libthrift:0.14.1 +org.apache.thrift:libthrift:0.23.0 io.dropwizard.metrics:metrics-core:4.2.19 io.dropwizard.metrics:metrics-jvm:3.2.2 com.librato.metrics:metrics-librato:5.1.0 diff --git a/iotdb-client/jdbc/src/main/feature/feature.xml b/iotdb-client/jdbc/src/main/feature/feature.xml index 033fe46d47c6c..bfd53ac808f2a 100644 --- a/iotdb-client/jdbc/src/main/feature/feature.xml +++ b/iotdb-client/jdbc/src/main/feature/feature.xml @@ -27,7 +27,7 @@ mvn:org.apache.iotdb/service-rpc/${project.version} mvn:org.apache.iotdb/iotdb-thrift/${project.version} mvn:org.apache.iotdb/hadoop-tsfile/${project.version} - mvn:org.apache.thrift/libthrift/0.14.1 + mvn:org.apache.thrift/libthrift/${thrift.version} mvn:org.xerial.snappy/snappy-java/1.1.8.4 mvn:commons-io/commons-io/2.5 wrap:mvn:org.apache.hadoop/hadoop-core/1.2.1 diff --git a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TNonblockingTransportWrapper.java b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TNonblockingTransportWrapper.java index 8a044f1e5cc8c..5ed51f9a90253 100644 --- a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TNonblockingTransportWrapper.java +++ b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TNonblockingTransportWrapper.java @@ -27,8 +27,8 @@ import java.nio.channels.SocketChannel; /** - * In Thrift 0.14.1, TNonblockingSocket's constructor throws a never-happened exception. So, we - * screen the exception https://issues.apache.org/jira/browse/THRIFT-5412 + * TNonblockingSocket's constructor throws a never-happened exception. So, we screen the exception + * https://issues.apache.org/jira/browse/THRIFT-5412 */ public class TNonblockingTransportWrapper { diff --git a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TSocketWrapper.java b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TSocketWrapper.java index df25d503e4365..b383283084a44 100644 --- a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TSocketWrapper.java +++ b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TSocketWrapper.java @@ -24,8 +24,8 @@ import org.apache.thrift.transport.TTransportException; /** - * In Thrift 0.14.1, TSocket's constructor throws a never-happened exception. So, we screen the - * exception https://issues.apache.org/jira/browse/THRIFT-5412 + * TSocket's constructor throws a never-happened exception. So, we screen the exception + * https://issues.apache.org/jira/browse/THRIFT-5412 */ public class TSocketWrapper { diff --git a/pom.xml b/pom.xml index c577243cb0ac2..d09f5fd1d07a4 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,16 @@ jitpack.io https://jitpack.io + + apache-iotdb-1191 + https://repository.apache.org/content/repositories/orgapacheiotdb-1191/ + + true + + + false + + org.apache @@ -88,7 +98,7 @@ This is the version of the thrift binary, that we release separately from here: https://github.com/apache/iotdb-bin-resources/tree/main/iotdb-tools-thrift --> - 0.14.1.0 + 0.23.0.0 2.18.6 3.0.0 6.0.0 @@ -142,13 +152,7 @@ 2.2.50 chmod - - 0.14.1 + 0.23.0 1.9 1.5.6-3 2.3.2-260608-SNAPSHOT From a2dc5440f0e7860347f99b3e84c2b94a011c57c0 Mon Sep 17 00:00:00 2001 From: HTHou Date: Mon, 15 Jun 2026 20:51:46 +0800 Subject: [PATCH 2/7] Exclude thrift httpcomponents5 dependencies --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index d09f5fd1d07a4..59cdf3678bec1 100644 --- a/pom.xml +++ b/pom.xml @@ -202,6 +202,18 @@ org.apache.httpcomponents httpcore + + org.apache.httpcomponents.client5 + httpclient5 + + + org.apache.httpcomponents.core5 + httpcore5 + + + org.apache.httpcomponents.core5 + httpcore5-h2 + From fef4b9bbcb21cbcae9a801308258c5e9ec443fce Mon Sep 17 00:00:00 2001 From: HTHou Date: Mon, 15 Jun 2026 20:58:40 +0800 Subject: [PATCH 3/7] Replace paths-filter action in client workflows --- .github/workflows/client-cpp-package.yml | 34 ++++++--- .github/workflows/multi-language-client.yml | 79 +++++++++++++-------- 2 files changed, 73 insertions(+), 40 deletions(-) diff --git a/.github/workflows/client-cpp-package.yml b/.github/workflows/client-cpp-package.yml index 4eb889b013619..3c8c2b2844f7b 100644 --- a/.github/workflows/client-cpp-package.yml +++ b/.github/workflows/client-cpp-package.yml @@ -46,18 +46,32 @@ jobs: steps: - uses: actions/checkout@v5 if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/rc/') - - uses: dorny/paths-filter@v3 + with: + fetch-depth: 0 + - name: Detect C++ package changes id: filter if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/rc/') - with: - filters: | - cpp: - - 'iotdb-client/client-cpp/**' - - 'iotdb-client/pom.xml' - - 'iotdb-protocol/thrift-datanode/src/main/thrift/client.thrift' - - 'iotdb-protocol/thrift-commons/src/main/thrift/common.thrift' - - '.github/workflows/client-cpp-package.yml' - - '.github/scripts/package-client-cpp-*.sh' + shell: bash + run: | + set -euo pipefail + + BASE="${{ github.event.before }}" + HEAD="${{ github.sha }}" + if [[ "$BASE" =~ ^0+$ ]]; then + BASE="$(git hash-object -t tree /dev/null)" + fi + + cpp=false + while IFS= read -r file; do + case "$file" in + iotdb-client/client-cpp/*|iotdb-client/pom.xml|iotdb-protocol/thrift-datanode/src/main/thrift/client.thrift|iotdb-protocol/thrift-commons/src/main/thrift/common.thrift|.github/workflows/client-cpp-package.yml|.github/scripts/package-client-cpp-*.sh) + cpp=true + break + ;; + esac + done < <(git diff --name-only "$BASE" "$HEAD") + + echo "cpp=${cpp}" >> "$GITHUB_OUTPUT" - id: result shell: bash run: | diff --git a/.github/workflows/multi-language-client.yml b/.github/workflows/multi-language-client.yml index 50840ca75ec4d..16c6d93ae2d28 100644 --- a/.github/workflows/multi-language-client.yml +++ b/.github/workflows/multi-language-client.yml @@ -1,4 +1,4 @@ -# Shared client CI: run only affected language jobs via paths-filter. +# Shared client CI: run only affected language jobs via changed path detection. name: Multi-Language Client on: push: @@ -50,36 +50,55 @@ jobs: go: ${{ steps.filter.outputs.go }} steps: - uses: actions/checkout@v5 - - uses: dorny/paths-filter@v3 - id: filter with: - filters: | - cpp: - - 'iotdb-client/pom.xml' - - 'iotdb-client/client-cpp/**' - - 'iotdb-protocol/thrift-datanode/src/main/thrift/client.thrift' - - 'iotdb-protocol/thrift-commons/src/main/thrift/common.thrift' - - '.github/workflows/multi-language-client.yml' - - '.github/workflows/client-cpp-package.yml' - - '.github/scripts/package-client-cpp-*.sh' - python: - - 'pom.xml' - - 'iotdb-client/pom.xml' - - 'iotdb-client/client-py/**' - - 'docker/src/main/Dockerfile-1c1d' - - '.github/workflows/multi-language-client.yml' - go: - - 'pom.xml' - - 'iotdb-core/**' - - 'iotdb-api/**' - - 'iotdb-protocol/**' - - 'distribution/**' - - 'integration-test/**' - - 'iotdb-client/session/**' - - 'iotdb-client/jdbc/**' - - 'iotdb-client/cli/**' - - 'iotdb-client/service-rpc/**' - - '.github/workflows/multi-language-client.yml' + fetch-depth: 0 + - name: Detect changed client paths + id: filter + shell: bash + run: | + set -euo pipefail + + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + BASE="${{ github.event.pull_request.base.sha }}" + HEAD="${{ github.sha }}" + elif [[ "${{ github.event_name }}" == "push" ]]; then + BASE="${{ github.event.before }}" + HEAD="${{ github.sha }}" + else + echo "cpp=true" >> "$GITHUB_OUTPUT" + echo "python=true" >> "$GITHUB_OUTPUT" + echo "go=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + + if [[ "$BASE" =~ ^0+$ ]]; then + BASE="$(git hash-object -t tree /dev/null)" + fi + + cpp=false + python=false + go=false + while IFS= read -r file; do + case "$file" in + iotdb-client/pom.xml|iotdb-client/client-cpp/*|iotdb-protocol/thrift-datanode/src/main/thrift/client.thrift|iotdb-protocol/thrift-commons/src/main/thrift/common.thrift|.github/workflows/multi-language-client.yml|.github/workflows/client-cpp-package.yml|.github/scripts/package-client-cpp-*.sh) + cpp=true + ;; + esac + case "$file" in + pom.xml|iotdb-client/pom.xml|iotdb-client/client-py/*|docker/src/main/Dockerfile-1c1d|.github/workflows/multi-language-client.yml) + python=true + ;; + esac + case "$file" in + pom.xml|iotdb-core/*|iotdb-api/*|iotdb-protocol/*|distribution/*|integration-test/*|iotdb-client/session/*|iotdb-client/jdbc/*|iotdb-client/cli/*|iotdb-client/service-rpc/*|.github/workflows/multi-language-client.yml) + go=true + ;; + esac + done < <(git diff --name-only "$BASE" "$HEAD") + + echo "cpp=${cpp}" >> "$GITHUB_OUTPUT" + echo "python=${python}" >> "$GITHUB_OUTPUT" + echo "go=${go}" >> "$GITHUB_OUTPUT" cpp: needs: changes From 6fa4195a7930c1dc6fc9bc1b71eefe56704233ad Mon Sep 17 00:00:00 2001 From: HTHou Date: Mon, 15 Jun 2026 21:22:06 +0800 Subject: [PATCH 4/7] Handle null thrift server contexts --- .../service/AbstractThriftServiceThread.java | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractThriftServiceThread.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractThriftServiceThread.java index 84361727a32e0..579c9d20d98ad 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractThriftServiceThread.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractThriftServiceThread.java @@ -29,7 +29,9 @@ import org.apache.thrift.TProcessor; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TCompactProtocol; +import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.protocol.TProtocolFactory; +import org.apache.thrift.server.ServerContext; import org.apache.thrift.server.THsHaServer; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TServerEventHandler; @@ -40,6 +42,7 @@ import org.apache.thrift.transport.TSSLTransportFactory; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TServerTransport; +import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransportException; import org.apache.thrift.transport.TTransportFactory; import org.slf4j.Logger; @@ -74,6 +77,18 @@ public abstract class AbstractThriftServiceThread extends Thread { // currently, we can reuse the ProtocolFactory instance. private static TCompactProtocol.Factory compactProtocolFactory = new TCompactProtocol.Factory(); private static TBinaryProtocol.Factory binaryProtocolFactory = new TBinaryProtocol.Factory(); + private static final ServerContext NOOP_SERVER_CONTEXT = + new ServerContext() { + @Override + public T unwrap(Class iface) { + return iface.isInstance(this) ? iface.cast(this) : null; + } + + @Override + public boolean isWrapperFor(Class iface) { + return iface.isInstance(this); + } + }; private void initProtocolFactory(boolean compress) { protocolFactory = getProtocolFactory(compress); @@ -155,7 +170,7 @@ protected AbstractThriftServiceThread( default: logger.error(ServiceMessages.UNEXPECTED_SERVER_TYPE, serverType); } - poolServer.setServerEventHandler(serverEventHandler); + poolServer.setServerEventHandler(wrapServerEventHandler(serverEventHandler)); } catch (TTransportException e) { catchFailedInitialization(e); } @@ -200,7 +215,7 @@ protected AbstractThriftServiceThread( TThreadPoolServer.Args poolArgs = initSyncedPoolArgs(processor, threadsName, maxWorkerThreads, timeoutSecond); poolServer = new TThreadPoolServer(poolArgs); - poolServer.setServerEventHandler(serverEventHandler); + poolServer.setServerEventHandler(wrapServerEventHandler(serverEventHandler)); } catch (TTransportException e) { catchFailedInitialization(e); } @@ -262,7 +277,7 @@ protected AbstractThriftServiceThread( TThreadPoolServer.Args poolArgs = initSyncedPoolArgs(processor, threadsName, maxWorkerThreads, timeoutSecond); poolServer = new TThreadPoolServer(poolArgs); - poolServer.setServerEventHandler(serverEventHandler); + poolServer.setServerEventHandler(wrapServerEventHandler(serverEventHandler)); } catch (TTransportException e) { catchFailedInitialization(e); } @@ -280,6 +295,36 @@ private TThreadPoolServer.Args initSyncedPoolArgs( return poolArgs; } + private static TServerEventHandler wrapServerEventHandler( + TServerEventHandler serverEventHandler) { + if (serverEventHandler == null) { + return null; + } + return new TServerEventHandler() { + @Override + public void preServe() { + serverEventHandler.preServe(); + } + + @Override + public ServerContext createContext(TProtocol input, TProtocol output) { + ServerContext serverContext = serverEventHandler.createContext(input, output); + return serverContext == null ? NOOP_SERVER_CONTEXT : serverContext; + } + + @Override + public void deleteContext(ServerContext serverContext, TProtocol input, TProtocol output) { + serverEventHandler.deleteContext(serverContext, input, output); + } + + @Override + public void processContext( + ServerContext serverContext, TTransport inputTransport, TTransport outputTransport) { + serverEventHandler.processContext(serverContext, inputTransport, outputTransport); + } + }; + } + private TThreadedSelectorServer.Args initAsyncedSelectorPoolArgs( TBaseAsyncProcessor processor, String threadsName, From eb52a26f263c4c842834947ebea69be501c80b19 Mon Sep 17 00:00:00 2001 From: HTHou Date: Wed, 17 Jun 2026 10:17:14 +0800 Subject: [PATCH 5/7] Improve thrift server context handling --- .../thrift/ConfigNodeRPCServiceHandler.java | 3 +- .../IoTConsensusRPCServiceHandler.java | 4 +- .../IoTConsensusV2RPCServiceHandler.java | 4 +- .../handler/BaseServerContextHandler.java | 7 +-- .../handler/InternalServiceThriftHandler.java | 3 +- .../MPPDataExchangeServiceThriftHandler.java | 3 +- .../service/AbstractThriftServiceThread.java | 51 ++----------------- .../commons/service/NoopServerContext.java | 39 ++++++++++++++ .../client/mock/MockInternalRPCService.java | 7 ++- .../service/NoopServerContextTest.java | 43 ++++++++++++++++ pom.xml | 24 ++------- 11 files changed, 112 insertions(+), 76 deletions(-) create mode 100644 iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/NoopServerContext.java create mode 100644 iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/service/NoopServerContextTest.java diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceHandler.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceHandler.java index abe4c03f861e3..c373dba5a3f6e 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceHandler.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceHandler.java @@ -17,6 +17,7 @@ package org.apache.iotdb.confignode.service.thrift; +import org.apache.iotdb.commons.service.NoopServerContext; import org.apache.iotdb.commons.service.metric.MetricService; import org.apache.thrift.protocol.TProtocol; @@ -37,7 +38,7 @@ public ConfigNodeRPCServiceHandler() { @Override public ServerContext createContext(TProtocol input, TProtocol output) { thriftConnectionNumber.incrementAndGet(); - return null; + return NoopServerContext.INSTANCE; } @Override diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/service/IoTConsensusRPCServiceHandler.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/service/IoTConsensusRPCServiceHandler.java index 621f887de3b1b..5e9f5c1b2bb9f 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/service/IoTConsensusRPCServiceHandler.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/service/IoTConsensusRPCServiceHandler.java @@ -19,6 +19,8 @@ package org.apache.iotdb.consensus.iot.service; +import org.apache.iotdb.commons.service.NoopServerContext; + import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.server.ServerContext; import org.apache.thrift.server.TServerEventHandler; @@ -37,7 +39,7 @@ public void preServe() {} @Override public ServerContext createContext(TProtocol input, TProtocol output) { - return null; + return NoopServerContext.INSTANCE; } @Override diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/pipe/service/IoTConsensusV2RPCServiceHandler.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/pipe/service/IoTConsensusV2RPCServiceHandler.java index dd4b9dfa73d62..001ba31008790 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/pipe/service/IoTConsensusV2RPCServiceHandler.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/pipe/service/IoTConsensusV2RPCServiceHandler.java @@ -19,6 +19,8 @@ package org.apache.iotdb.consensus.pipe.service; +import org.apache.iotdb.commons.service.NoopServerContext; + import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.server.ServerContext; import org.apache.thrift.server.TServerEventHandler; @@ -37,7 +39,7 @@ public void preServe() {} @Override public ServerContext createContext(TProtocol input, TProtocol output) { - return null; + return NoopServerContext.INSTANCE; } @Override diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/BaseServerContextHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/BaseServerContextHandler.java index e5489d0a185f1..111f6e08d276f 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/BaseServerContextHandler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/BaseServerContextHandler.java @@ -19,6 +19,7 @@ package org.apache.iotdb.db.protocol.thrift.handler; +import org.apache.iotdb.commons.service.NoopServerContext; import org.apache.iotdb.db.i18n.DataNodeMiscMessages; import org.apache.iotdb.db.protocol.session.ClientSession; import org.apache.iotdb.db.protocol.session.SessionManager; @@ -63,17 +64,17 @@ public ServerContext createContext(TProtocol in, TProtocol out) { getSessionManager().registerSession(new ClientSession(socket)); if (factory != null) { context = factory.newServerContext(out, socket); - if (!context.whenConnect()) { + if (context != null && !context.whenConnect()) { return context; } } - return context; + return context == null ? NoopServerContext.INSTANCE : context; } public void deleteContext(ServerContext context, TProtocol in, TProtocol out) { getSessionManager().removeCurrSession(); - if (context != null && factory != null) { + if (context instanceof JudgableServerContext) { ((JudgableServerContext) context).whenDisconnect(); } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/InternalServiceThriftHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/InternalServiceThriftHandler.java index d53d312650267..58130eb91cc58 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/InternalServiceThriftHandler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/InternalServiceThriftHandler.java @@ -19,6 +19,7 @@ package org.apache.iotdb.db.protocol.thrift.handler; +import org.apache.iotdb.commons.service.NoopServerContext; import org.apache.iotdb.commons.service.metric.MetricService; import org.apache.thrift.protocol.TProtocol; @@ -45,7 +46,7 @@ public void preServe() { @Override public ServerContext createContext(TProtocol tProtocol, TProtocol tProtocol1) { thriftConnectionNumber.incrementAndGet(); - return null; + return NoopServerContext.INSTANCE; } @Override diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/exchange/MPPDataExchangeServiceThriftHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/exchange/MPPDataExchangeServiceThriftHandler.java index 2c3d358759aa0..999ad37d7aed1 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/exchange/MPPDataExchangeServiceThriftHandler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/exchange/MPPDataExchangeServiceThriftHandler.java @@ -19,6 +19,7 @@ package org.apache.iotdb.db.queryengine.execution.exchange; +import org.apache.iotdb.commons.service.NoopServerContext; import org.apache.iotdb.commons.service.metric.MetricService; import org.apache.thrift.protocol.TProtocol; @@ -44,7 +45,7 @@ public void preServe() { @Override public ServerContext createContext(TProtocol input, TProtocol output) { thriftConnectionNumber.incrementAndGet(); - return null; + return NoopServerContext.INSTANCE; } @Override diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractThriftServiceThread.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractThriftServiceThread.java index 579c9d20d98ad..84361727a32e0 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractThriftServiceThread.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractThriftServiceThread.java @@ -29,9 +29,7 @@ import org.apache.thrift.TProcessor; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TCompactProtocol; -import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.protocol.TProtocolFactory; -import org.apache.thrift.server.ServerContext; import org.apache.thrift.server.THsHaServer; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TServerEventHandler; @@ -42,7 +40,6 @@ import org.apache.thrift.transport.TSSLTransportFactory; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TServerTransport; -import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransportException; import org.apache.thrift.transport.TTransportFactory; import org.slf4j.Logger; @@ -77,18 +74,6 @@ public abstract class AbstractThriftServiceThread extends Thread { // currently, we can reuse the ProtocolFactory instance. private static TCompactProtocol.Factory compactProtocolFactory = new TCompactProtocol.Factory(); private static TBinaryProtocol.Factory binaryProtocolFactory = new TBinaryProtocol.Factory(); - private static final ServerContext NOOP_SERVER_CONTEXT = - new ServerContext() { - @Override - public T unwrap(Class iface) { - return iface.isInstance(this) ? iface.cast(this) : null; - } - - @Override - public boolean isWrapperFor(Class iface) { - return iface.isInstance(this); - } - }; private void initProtocolFactory(boolean compress) { protocolFactory = getProtocolFactory(compress); @@ -170,7 +155,7 @@ protected AbstractThriftServiceThread( default: logger.error(ServiceMessages.UNEXPECTED_SERVER_TYPE, serverType); } - poolServer.setServerEventHandler(wrapServerEventHandler(serverEventHandler)); + poolServer.setServerEventHandler(serverEventHandler); } catch (TTransportException e) { catchFailedInitialization(e); } @@ -215,7 +200,7 @@ protected AbstractThriftServiceThread( TThreadPoolServer.Args poolArgs = initSyncedPoolArgs(processor, threadsName, maxWorkerThreads, timeoutSecond); poolServer = new TThreadPoolServer(poolArgs); - poolServer.setServerEventHandler(wrapServerEventHandler(serverEventHandler)); + poolServer.setServerEventHandler(serverEventHandler); } catch (TTransportException e) { catchFailedInitialization(e); } @@ -277,7 +262,7 @@ protected AbstractThriftServiceThread( TThreadPoolServer.Args poolArgs = initSyncedPoolArgs(processor, threadsName, maxWorkerThreads, timeoutSecond); poolServer = new TThreadPoolServer(poolArgs); - poolServer.setServerEventHandler(wrapServerEventHandler(serverEventHandler)); + poolServer.setServerEventHandler(serverEventHandler); } catch (TTransportException e) { catchFailedInitialization(e); } @@ -295,36 +280,6 @@ private TThreadPoolServer.Args initSyncedPoolArgs( return poolArgs; } - private static TServerEventHandler wrapServerEventHandler( - TServerEventHandler serverEventHandler) { - if (serverEventHandler == null) { - return null; - } - return new TServerEventHandler() { - @Override - public void preServe() { - serverEventHandler.preServe(); - } - - @Override - public ServerContext createContext(TProtocol input, TProtocol output) { - ServerContext serverContext = serverEventHandler.createContext(input, output); - return serverContext == null ? NOOP_SERVER_CONTEXT : serverContext; - } - - @Override - public void deleteContext(ServerContext serverContext, TProtocol input, TProtocol output) { - serverEventHandler.deleteContext(serverContext, input, output); - } - - @Override - public void processContext( - ServerContext serverContext, TTransport inputTransport, TTransport outputTransport) { - serverEventHandler.processContext(serverContext, inputTransport, outputTransport); - } - }; - } - private TThreadedSelectorServer.Args initAsyncedSelectorPoolArgs( TBaseAsyncProcessor processor, String threadsName, diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/NoopServerContext.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/NoopServerContext.java new file mode 100644 index 0000000000000..621f9d0e2a3db --- /dev/null +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/NoopServerContext.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.iotdb.commons.service; + +import org.apache.thrift.server.ServerContext; + +public final class NoopServerContext implements ServerContext { + + public static final NoopServerContext INSTANCE = new NoopServerContext(); + + private NoopServerContext() {} + + @Override + public T unwrap(Class iface) { + return iface.isInstance(this) ? iface.cast(this) : null; + } + + @Override + public boolean isWrapperFor(Class iface) { + return iface.isInstance(this); + } +} diff --git a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/client/mock/MockInternalRPCService.java b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/client/mock/MockInternalRPCService.java index 386a212436fe0..0b5b57c4930e2 100644 --- a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/client/mock/MockInternalRPCService.java +++ b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/client/mock/MockInternalRPCService.java @@ -22,6 +22,7 @@ import org.apache.iotdb.common.rpc.thrift.TEndPoint; import org.apache.iotdb.commons.concurrent.ThreadName; import org.apache.iotdb.commons.exception.runtime.RPCServiceException; +import org.apache.iotdb.commons.service.NoopServerContext; import org.apache.iotdb.commons.service.ServiceType; import org.apache.iotdb.commons.service.ThriftService; import org.apache.iotdb.commons.service.ThriftServiceThread; @@ -30,7 +31,9 @@ import org.apache.thrift.server.TServerEventHandler; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class MockInternalRPCService extends ThriftService implements MockInternalRPCServiceMBean { @@ -60,6 +63,8 @@ public void initTProcessor() { @Override public void initThriftServiceThread() throws IllegalAccessException { try { + TServerEventHandler serverEventHandler = mock(TServerEventHandler.class); + when(serverEventHandler.createContext(any(), any())).thenReturn(NoopServerContext.INSTANCE); thriftServiceThread = new ThriftServiceThread( processor, @@ -69,7 +74,7 @@ public void initThriftServiceThread() throws IllegalAccessException { getBindPort(), 65535, 60, - mock(TServerEventHandler.class), + serverEventHandler, false, DeepCopyRpcTransportFactory.INSTANCE); } catch (RPCServiceException e) { diff --git a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/service/NoopServerContextTest.java b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/service/NoopServerContextTest.java new file mode 100644 index 0000000000000..b8a7555c14f58 --- /dev/null +++ b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/service/NoopServerContextTest.java @@ -0,0 +1,43 @@ +/* + * 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.iotdb.commons.service; + +import org.apache.thrift.server.ServerContext; +import org.junit.Assert; +import org.junit.Test; + +public class NoopServerContextTest { + + @Test + public void testUnwrap() { + Assert.assertSame( + NoopServerContext.INSTANCE, NoopServerContext.INSTANCE.unwrap(NoopServerContext.class)); + Assert.assertSame( + NoopServerContext.INSTANCE, NoopServerContext.INSTANCE.unwrap(ServerContext.class)); + Assert.assertNull(NoopServerContext.INSTANCE.unwrap(String.class)); + } + + @Test + public void testIsWrapperFor() { + Assert.assertTrue(NoopServerContext.INSTANCE.isWrapperFor(NoopServerContext.class)); + Assert.assertTrue(NoopServerContext.INSTANCE.isWrapperFor(ServerContext.class)); + Assert.assertFalse(NoopServerContext.INSTANCE.isWrapperFor(String.class)); + } +} diff --git a/pom.xml b/pom.xml index 59cdf3678bec1..d3fc46910cba9 100644 --- a/pom.xml +++ b/pom.xml @@ -183,25 +183,7 @@ libthrift ${thrift.version} - - - org.apache.tomcat.embed - tomcat-embed-core - - - - javax.annotation - javax.annotation-api - - - - org.apache.httpcomponents - httpclient - - - org.apache.httpcomponents - httpcore - + org.apache.httpcomponents.client5 httpclient5 @@ -214,6 +196,10 @@ org.apache.httpcomponents.core5 httpcore5-h2 + + jakarta.servlet + jakarta.servlet-api + From 89b74de8e638b0ab320266d8a4f0e9089d63bcdd Mon Sep 17 00:00:00 2001 From: HTHou Date: Wed, 17 Jun 2026 10:24:58 +0800 Subject: [PATCH 6/7] Add javadocs for no-op thrift context --- .../apache/iotdb/commons/service/NoopServerContext.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/NoopServerContext.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/NoopServerContext.java index 621f9d0e2a3db..70ea8afef03e2 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/NoopServerContext.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/NoopServerContext.java @@ -21,8 +21,17 @@ import org.apache.thrift.server.ServerContext; +/** + * Shared {@link ServerContext} implementation for Thrift handlers that do not need per-connection + * state. + * + *

Thrift 0.23 server implementations expect {@code createContext} to return a non-null context, + * even when the event handler only uses connection lifecycle callbacks. This no-op implementation + * keeps those handlers explicit without adding a custom context object for each connection. + */ public final class NoopServerContext implements ServerContext { + /** Singleton instance reused by handlers that do not attach state to the connection. */ public static final NoopServerContext INSTANCE = new NoopServerContext(); private NoopServerContext() {} From f5e7ec5bc2d8487621b33deebb8270557b6cdc4d Mon Sep 17 00:00:00 2001 From: Haonan Date: Thu, 18 Jun 2026 21:27:00 +0800 Subject: [PATCH 7/7] Remove obsolete repository from pom.xml Removed obsolete repository configuration for apache-iotdb-1191. --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index d3fc46910cba9..09ac9c458d5e2 100644 --- a/pom.xml +++ b/pom.xml @@ -27,16 +27,6 @@ jitpack.io https://jitpack.io - - apache-iotdb-1191 - https://repository.apache.org/content/repositories/orgapacheiotdb-1191/ - - true - - - false - - org.apache