JackieTien97 commented on code in PR #19125: URL: https://github.com/apache/iotdb/pull/19125#discussion_r4501190170
########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/internal/subscription/InternalSubscriptionTablePullConsumer.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.client.internal.subscription; + +import org.apache.iotdb.common.rpc.thrift.TEndPoint; +import org.apache.iotdb.isession.INodeSupplier; +import org.apache.iotdb.rpc.RpcServiceConstants; +import org.apache.iotdb.session.subscription.consumer.base.AbstractSubscriptionProvider; +import org.apache.iotdb.session.subscription.consumer.table.SubscriptionTablePullConsumer; +import org.apache.iotdb.session.subscription.consumer.table.SubscriptionTablePullConsumerBuilder; + +final class InternalSubscriptionTablePullConsumer extends SubscriptionTablePullConsumer { + + private final INodeSupplier nodeSupplier; + + InternalSubscriptionTablePullConsumer( + final SubscriptionTablePullConsumerBuilder builder, final INodeSupplier nodeSupplier) { + super(builder); + this.nodeSupplier = nodeSupplier; + } + + @Override + protected INodeSupplier getInternalNodeSupplier() { + return nodeSupplier; + } + + @Override + protected String getRpcServiceName() { + return RpcServiceConstants.INTERNAL_CLIENT_RPC_SERVICE; + } + + @Override + protected AbstractSubscriptionProvider constructSubscriptionProvider( + final TEndPoint endPoint, + final String username, + final String password, + final String encryptedPassword, + final String consumerId, + final String consumerGroupId, + final String ownerId, + final Long ownerEpoch, + final int thriftMaxFrameSize, + final long heartbeatIntervalMs, + final int connectionTimeoutInMs) { + return super.constructSubscriptionProvider( + endPoint, + username, + "", Review Comment: The empty password breaks `subscribe()` for topics in the default `initial` mode (and `snapshot`). - `AbstractSubscriptionProvider.handshake` puts `password=""` into the `ConsumerConfig`. TsFile's `readString` decodes a zero-length string as `""`, not `null`, so it reaches the ConfigNode as `""`. - `CreateSubscriptionProcedure` passes `consumerMeta.getSubscriptionAuthPassword()` (`""`) to `TopicMeta.generateExtractorAttributes`, which adds `password=""` because it is non-null. - `CreatePipeProcedureV2.checkAndEnrichSourceAuthentication` then fails both `login(username, "", true)` and `login4Pipe(username, "")` and throws `PipeException(AUTHENTICATION_FAILED)`. Only `incremental` topics skip pipe creation, so they are not affected. Passing `null` here, and leaving null values out of the handshake attributes, avoids this: `login4Pipe(username, null)` returns the stored hash. ########## integration-test/src/test/java/org/apache/iotdb/relational/it/session/InternalTableSessionRedirectIT.java: ########## @@ -0,0 +1,140 @@ +/* + * 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.relational.it.session; + +import org.apache.iotdb.common.rpc.thrift.TEndPoint; +import org.apache.iotdb.commons.client.internal.session.InternalTableSessionBuilder; +import org.apache.iotdb.consensus.ConsensusFactory; +import org.apache.iotdb.isession.INodeSupplier; +import org.apache.iotdb.isession.ITableSession; +import org.apache.iotdb.isession.SessionConfig; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.it.utils.InternalSessionITUtils; +import org.apache.iotdb.itbase.category.TableClusterIT; +import org.apache.iotdb.session.Session; + +import org.apache.tsfile.enums.ColumnCategory; +import org.apache.tsfile.enums.TSDataType; +import org.apache.tsfile.write.record.Tablet; +import org.apache.tsfile.write.schema.IMeasurementSchema; +import org.apache.tsfile.write.schema.MeasurementSchema; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(IoTDBTestRunner.class) +@Category(TableClusterIT.class) +public class InternalTableSessionRedirectIT { + + private static final String DATABASE = "internal_table_session_redirect_it"; + private static final String TABLE = "t"; + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setSchemaReplicationFactor(1) + .setDataReplicationFactor(1) + .setDataRegionGroupExtensionPolicy("CUSTOM") + .setDefaultDataRegionGroupNumPerDatabase(1) + .setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS) + .setDataRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS); + EnvFactory.getEnv().initClusterEnvironment(1, 3); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testTabletInsertRedirectsToInternalLeaderEndpoint() throws Exception { + final INodeSupplier nodeSupplier = InternalSessionITUtils.createInternalNodeSupplier(); + final TEndPoint initialEndPoint = InternalSessionITUtils.getInternalEndPoints().get(0); + final Set<TEndPoint> leaderEndPoints; + + try (ITableSession setupSession = + new InternalTableSessionBuilder(nodeSupplier) + .nodeUrls( + Collections.singletonList(InternalSessionITUtils.getEndPointUrl(initialEndPoint))) + .username(SessionConfig.DEFAULT_USER) + .password(SessionConfig.DEFAULT_PASSWORD) + .build()) { + setupSession.executeNonQueryStatement("CREATE DATABASE " + DATABASE); + setupSession.executeNonQueryStatement( + "CREATE TABLE " + DATABASE + "." + TABLE + " (tag1 STRING TAG, value INT64 FIELD)"); + // DataRegionGroups are allocated on the first data write, not when the database is created. + setupSession.insert(createTablet(1L)); Review Comment: This line makes the IT fail on the current head. CI run 42206759906 (Table Cluster IT - 1C3D) reports `StatementExecutionException: 701: database is not specified` here. `setupSession` runs `CREATE DATABASE` and a fully qualified `CREATE TABLE` but never selects the database, so the table-model `insert(Tablet)` has no database. Running `USE <database>` on `setupSession` before the insert should fix it. ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/InternalClientRPCServiceImpl.java: ########## @@ -0,0 +1,29 @@ +/* + * 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.db.protocol.thrift.impl; + +/** Client RPC handler exposed through the multiplexed internal endpoint. */ +public class InternalClientRPCServiceImpl extends ClientRPCServiceImpl { + + @Override + protected boolean useInternalSessionLogin() { + return true; Review Comment: This enables passwordless login on every DataNode, with no switch. Without internal SSL (`CommonConfig.isEnableInternalSSL()`), anything that can reach `dn_internal_port` can open a session as `root` using a regular `Session` wrapped in `TMultiplexedProtocol("IClientRPCService")`, which bypasses the password check and the login lock. In this repo `AccessControlImpl.allowUserToLogin` always returns `SUCCEED`, so the login-policy check amounts to "the user exists", and operation-level authorization does not restrict `root`. THREAT_MODEL.md ยง4 treats direct access to `dn_internal_port` as out of model, so this is a design decision rather than an in-model vulnerability. It still lowers the bar from crafting internal RPCs to running a stock client. Could this sit behind a switch that is off by default, or require internal SSL? In either case, THREAT_MODEL.md should note that the internal endpoint now serves client sessions too. ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/internal/subscription/InternalSubscriptionTablePullConsumerBuilder.java: ########## @@ -0,0 +1,55 @@ +/* + * 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.client.internal.subscription; + +import org.apache.iotdb.isession.INodeSupplier; +import org.apache.iotdb.session.i18n.SessionMessages; +import org.apache.iotdb.session.subscription.consumer.ISubscriptionTablePullConsumer; +import org.apache.iotdb.session.subscription.consumer.table.SubscriptionTablePullConsumerBuilder; + +import java.util.Objects; + +/** + * Server-side builder for table subscription pull consumers. + * + * <p>Callers sharing an external {@link INodeSupplier} must return {@code true} from {@link + * INodeSupplier#isExternalLifeCycleNodeSupplier()}. + */ +public class InternalSubscriptionTablePullConsumerBuilder + extends SubscriptionTablePullConsumerBuilder { + + private final INodeSupplier nodeSupplier; + + public InternalSubscriptionTablePullConsumerBuilder() { Review Comment: With this constructor `nodeSupplier` is null, so `getInternalNodeSupplier()` returns null and the consumer falls back to server-side discovery. - The heartbeat's `getEndPoints()` returns client RPC endpoints: `SubscriptionReceiverV1` builds them from `getRpcAddresss()` / `getRpcPort()`. - The providers still send the `IClientRPCService:` prefix, so every handshake to another DataNode fails on the client port with `Invalid method name`. - `openProviders` and `syncInternal` only log the failure and move on. On a multi-DataNode cluster the consumer stays connected to the seed node only and never polls events produced on the other nodes. The internal session builders reject the equivalent configuration in `createSession()`. This builder should require a supplier, or reject the no-arg path the same way. ########## iotdb-client/subscription/src/main/java/org/apache/iotdb/session/subscription/consumer/base/AbstractSubscriptionProviders.java: ########## @@ -567,6 +583,96 @@ private void syncInternal(final AbstractSubscriptionConsumer consumer) { } } + /** Reconciles providers against a complete endpoint list without server-side discovery. */ + private void syncInternalProviders(final AbstractSubscriptionConsumer consumer) { + final Set<TEndPoint> endpoints = + consumer.getInternalNodeSupplier().get().stream() + .map(TEndPoint::deepCopy) + .collect(Collectors.toCollection(LinkedHashSet::new)); + + for (final AbstractSubscriptionProvider provider : getAllProviders()) { + if (!provider.isAvailable() || !endpoints.contains(provider.getEndPoint())) { Review Comment: If the supplier returns an empty or partial list for one round, for example while a dynamic supplier refreshes, this closes every provider that isn't listed and then throws `SubscriptionConnectionException`. Polls have no provider until the next sync. The discovery path can't shrink to empty like this, because a failed fetch throws instead. The bundled `DummyNodesSupplier` is static, so whether this happens depends on the caller's supplier, but skipping the cleanup when the list is empty would be a cheap guard. ########## iotdb-client/subscription/src/main/java/org/apache/iotdb/session/subscription/consumer/base/AbstractSubscriptionProviders.java: ########## @@ -567,6 +583,96 @@ private void syncInternal(final AbstractSubscriptionConsumer consumer) { } } + /** Reconciles providers against a complete endpoint list without server-side discovery. */ + private void syncInternalProviders(final AbstractSubscriptionConsumer consumer) { Review Comment: Nothing in the test sources exercises this method, `InternalSubscriptionTablePullConsumer`, or the rejection paths of `SessionManager.loginInternal`. One end-to-end IT that subscribes and polls through the internal consumer on a multi-DataNode cluster would have caught the problems noted on `InternalSubscriptionTablePullConsumer`, `InternalSubscriptionTablePullConsumerBuilder` and `InternalSubscriptionTableSessionBuilder`. Also, the comment at `InternalSessionRedirectIT.java:97` says the first write only caches the leader endpoint and has to be retried to persist. The redirect is only attached to the result of a successful write, so the first write is persisted. Writing the same row twice in these ITs also can't detect a lost first write. ########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/internal/subscription/InternalSubscriptionTableSessionBuilder.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.client.internal.subscription; + +import org.apache.iotdb.isession.INodeSupplier; +import org.apache.iotdb.session.i18n.SessionMessages; +import org.apache.iotdb.session.subscription.ISubscriptionTableSession; +import org.apache.iotdb.session.subscription.SubscriptionTableSessionBuilder; + +import java.util.List; +import java.util.Objects; + +/** + * Server-side builder for table subscription-management sessions. + * + * <p>Callers sharing an external {@link INodeSupplier} must return {@code true} from {@link + * INodeSupplier#isExternalLifeCycleNodeSupplier()}; otherwise the created session may close it + * during its lifecycle, including when the session is reopened. + */ +public class InternalSubscriptionTableSessionBuilder extends SubscriptionTableSessionBuilder { + + private final INodeSupplier nodeSupplier; + + public InternalSubscriptionTableSessionBuilder() { + this.nodeSupplier = null; + } + + public InternalSubscriptionTableSessionBuilder(final INodeSupplier nodeSupplier) { + this.nodeSupplier = + Objects.requireNonNull( + nodeSupplier, + SessionMessages.EXCEPTION_INTERNAL_NODE_SUPPLIER_MUST_NOT_BE_NULL_C5CAF392); + } + + public InternalSubscriptionTableSessionBuilder nodeUrls(final List<String> nodeUrls) { Review Comment: With `nodeUrls` set, this session can never open: - `Session(AbstractSessionBuilder)` leaves `defaultEndPoint` null when `nodeUrls` is non-null. - `InternalSubscriptionSessionWrapper` treats `builder.nodeUrls != null` as an explicit endpoint, so it doesn't fill `defaultEndPoint` from the supplier either. - `Session.open` then calls `SubscriptionSessionWrapper.constructSessionConnection(this, null, zoneId)`, which throws `SubscriptionParameterNotValidException` ("Subscription session must be configured with an endpoint."). Either drop this method or resolve `defaultEndPoint` from the URLs before opening. No test covers this method. ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java: ########## @@ -235,15 +235,25 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext> private final ISchemaFetcher schemaFetcher; private final IModelFetcher modelFetcher; private final TreeAnalysisMutationJournal mutationJournal; + private final boolean internalRpcSession; Review Comment: This flag is threaded through 40 `new Analysis(internalRpcSession)` call sites here and copied at 10 `new SessionInfo(...)` sites, but it is only read when redirect endpoints are produced, which happens later in `splitByPartition`. Setting it once in `Analyzer.analyze`, or keeping the `TDataNodeLocation`s in the analysis and resolving them in `setRedirectInfo` from the query context, would do the same job. As it stands, a new construction site that forgets the flag still compiles and silently returns client RPC endpoints to internal sessions. Smaller cleanups: - The 3-argument `AnalyzeVisitor` constructor no longer has callers. - `IoTDBInternalLocalReporter` and `DataNodeInternalRPCServiceImpl` (the audit-log `SessionInfo`) still call `setInternalRpcSession(true)` on in-process sessions, which is inconsistent with 1ff0e4f1d0 removing the flag from `InternalClientSession`. ########## iotdb-client/session/src/main/i18n/en/org/apache/iotdb/session/i18n/SessionMessages.java: ########## @@ -21,6 +21,12 @@ public final class SessionMessages { + public static final String EXCEPTION_INTERNAL_NODE_SUPPLIER_MUST_NOT_BE_NULL_C5CAF392 = + "Internal node supplier must not be null"; + + public static final String EXCEPTION_INTERNAL_AUTO_FETCH_REQUIRES_NODE_SUPPLIER_9CB6BA02 = Review Comment: Per the i18n naming rule in AGENTS.md (`<PREFIX>_<NORMALIZED>_<HASH>`, where NORMALIZED is the English value uppercased with non-alphanumeric runs collapsed to `_`), this should be `EXCEPTION_AN_INTERNAL_NODE_SUPPLIER_IS_REQUIRED_WHEN_AUTO_FETCH_IS_ENABLED_9CB6BA02`. The hash is correct but the middle part isn't, so anyone computing the name for this message won't find the existing constant. The zh file needs the same rename. ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/handler/InternalServiceThriftHandler.java: ########## @@ -52,7 +57,15 @@ public ServerContext createContext(TProtocol tProtocol, TProtocol tProtocol1) { @Override public void deleteContext( ServerContext serverContext, TProtocol tProtocol, TProtocol tProtocol1) { - thriftConnectionNumber.decrementAndGet(); + try { + IClientSession session = SessionManager.getInstance().getCurrSession(); + if (session != null) { + eventHandler.handleClientExit(); Review Comment: If `handleClientExit()` throws (it runs `closeSession` plus the pipe and subscription receiver cleanup), the `finally` clears the ThreadLocal session, but the exception still propagates out of `deleteContext`. In libthrift 0.25, `TThreadPoolServer.WorkerProcess` closes the transports only after `deleteContext` returns, so the socket is left open. Before this change, this handler's `deleteContext` could not throw. Catching and logging the exception here would keep the cleanup from leaking connections. ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/InternalClientRPCServiceProcessor.java: ########## @@ -0,0 +1,56 @@ +/* + * 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.db.protocol.thrift; + +import org.apache.iotdb.db.protocol.session.ClientSession; +import org.apache.iotdb.db.protocol.session.SessionManager; +import org.apache.iotdb.db.protocol.thrift.impl.IClientRPCServiceWithHandler; +import org.apache.iotdb.rpc.TElasticFramedTransport; + +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.transport.TSocket; +import org.apache.thrift.transport.TTransport; + +import java.net.Socket; + +/** Registers a client session only for connections using the multiplexed client RPC service. */ +public class InternalClientRPCServiceProcessor extends ProcessorWithMetrics { + + public InternalClientRPCServiceProcessor(IClientRPCServiceWithHandler iface) { + super(iface); + } + + @Override + public void process(TProtocol in, TProtocol out) throws TException { + registerSessionIfNecessary(out); + super.process(in, out); + } + + private void registerSessionIfNecessary(TProtocol protocol) { + if (SessionManager.getInstance().getCurrSession() != null) { + return; + } + + TTransport socketTransport = ((TElasticFramedTransport) protocol.getTransport()).getSocket(); + Socket socket = ((TSocket) socketTransport).getSocket(); + SessionManager.getInstance().registerSession(new ClientSession(socket)); Review Comment: Registering the session here skips the `ServerContextFactory` hook that `BaseServerContextHandler.createContext` runs for client RPC connections (`JudgableServerContext.whenConnect()` and `whenDisconnect()`). A deployment that relies on that SPI for connection admission, for example an IP allow list, won't apply it to SQL sessions opened through the internal port. If that is intended, a comment would help; otherwise the hook should run here as well. ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/session/SessionManager.java: ########## @@ -226,6 +226,80 @@ public BasicOpenSessionResp login( return openSessionResp; } + /** Opens a session without password verification for trusted internal client RPC callers. */ + public BasicOpenSessionResp loginInternal( + final IClientSession session, + final String username, + final String zoneId, + final TSProtocolVersion tsProtocolVersion, + final IoTDBConstant.ClientVersion clientVersion, + final SqlDialect sqlDialect) { + final BasicOpenSessionResp openSessionResp = new BasicOpenSessionResp(); + final long userId = AuthorityChecker.getUserId(username).orElse(-1L); + if (userId == -1) { Review Comment: Unlike `login`, the rejection paths here (user not found, and the login-policy rejection below) return without an audit record. `login` writes `AuditLogFields(..., false)` when a login fails. Because this path takes no password, failed attempts such as username probing leave nothing in the audit log. Please audit failures the same way `login` does. ########## iotdb-client/isession/src/main/java/org/apache/iotdb/isession/INodeSupplier.java: ########## @@ -41,4 +41,12 @@ default List<TEndPoint> getSeedNodes() { default void requestRefresh() { // Suppliers without automatic discovery have nothing to refresh. } + + /** + * Whether this supplier's lifecycle is managed externally and must not be closed by IoTDB + * clients. + */ + default boolean isExternalLifeCycleNodeSupplier() { Review Comment: Supplier ownership is expressed only by this flag and the Javadoc. If a caller passes a regular `NodesSupplier` (which returns `false`) to `InternalSessionBuilder`, reopening that session closes the supplier and then reassigns the closed instance, and `SessionPool.close()` closes it as well. Every other session or pool sharing the supplier loses refresh. It would be safer to track ownership where the supplier is created, so a session closes only suppliers it created, or to check this flag in the internal builders' constructors. Also, overriding this to `true` in `DummyNodesSupplier` has no effect, because its `close()` is a no-op. ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNodeInternalRPCService.java: ########## @@ -121,6 +133,20 @@ public DataNodeInternalRPCServiceImpl getImpl() { return impl.get(); } + static TProcessor createMultiplexedProcessor( + final TProcessor controlProcessor, final TProcessor clientProcessor) { + final TMultiplexedProcessor multiplexedProcessor = new TMultiplexedProcessor(); + multiplexedProcessor.registerProcessor( Review Comment: Client sessions on this port share the internal service's `TThreadPoolServer` with cluster traffic such as heartbeats and fragment dispatch. It uses one worker per connection, capped by `rpcMaxConcurrentClientNum` (default 1000). Until now the number of connections here tracked the cluster size; now it also grows with internal session pools and subscription providers. If they fill the pool, new cluster connections can't get a worker and the node may be marked Unknown. A separate cap, or at least documented sizing guidance, seems worth adding. ########## integration-test/src/test/java/org/apache/iotdb/session/it/InternalSessionIT.java: ########## @@ -0,0 +1,172 @@ +/* + * 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.session.it; + +import org.apache.iotdb.commons.client.internal.session.InternalSessionBuilder; +import org.apache.iotdb.commons.client.internal.session.InternalSessionPoolBuilder; +import org.apache.iotdb.isession.INodeSupplier; +import org.apache.iotdb.isession.SessionConfig; +import org.apache.iotdb.isession.SessionDataSet; +import org.apache.iotdb.isession.pool.SessionDataSetWrapper; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.it.utils.InternalSessionITUtils; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.session.Session; +import org.apache.iotdb.session.pool.SessionPool; + +import org.apache.tsfile.enums.TSDataType; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class InternalSessionIT { + + private static final String DATABASE = "root.internal_session_it"; + + @Before Review Comment: integration-test/AGENTS.md asks to "share cluster startup and teardown across compatible cases within a class or suite whenever possible. Avoid starting and stopping a cluster for each test method". The three methods here, and the three in `InternalTableSessionIT`, use the default configuration and clean up in `finally`, so they can share one cluster through `@BeforeClass` and `@AfterClass`. Across both topologies that is 12 cluster starts instead of 4. -- 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]
