Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e5a2715
Add database-scoped tablet insertion for table sessions
shuwenwei Nov 12, 2026
7ab0db7
Fix table model redirect cache across databases
shuwenwei Nov 12, 2026
e8a15c6
Fix missing table model device ID import
shuwenwei Nov 12, 2026
2f49f14
Preserve ISession flat route cache API
shuwenwei Nov 12, 2026
b092a12
Expose database-aware session route cache open API
shuwenwei Nov 12, 2026
f53ab9a
Fix nested route cache test compilation
shuwenwei Nov 12, 2026
88d429d
Validate and normalize table database routing
shuwenwei Nov 16, 2026
44ae923
Merge branch 'iotdb_master' into feature/table-session-db-insert
shuwenwei Nov 16, 2026
cfabbfb
Share table database name validation
shuwenwei Nov 16, 2026
ba47a19
Negotiate database-scoped tablet support
shuwenwei Nov 16, 2026
69eda01
spotless
shuwenwei Nov 16, 2026
9d174a5
Validate table-model database names on the client
shuwenwei Nov 16, 2026
1ee2923
Merge branch 'iotdb_master' into feature/table-session-db-insert
shuwenwei Nov 16, 2026
aa78bae
Avoid allocating empty table route caches
shuwenwei Nov 16, 2026
937d9e7
Simplify empty table route cache handling
shuwenwei Nov 16, 2026
01acf6e
Merge branch 'iotdb_master' into feature/table-session-db-insert
shuwenwei Nov 16, 2026
65d261e
Add coverage for database-scoped tablet insertion
shuwenwei Nov 16, 2026
b8d9b79
Fix database-scoped tablet test compilation
shuwenwei Nov 16, 2026
d5b81c0
Align pooled insert failure test with database overload
shuwenwei Nov 17, 2026
0964da8
Merge branch 'iotdb_master' into feature/table-session-db-insert
shuwenwei Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ public void testTabletInsertRedirectsToInternalLeaderEndpoint() throws Exception
session.insert(createTablet(2L));

final Session underlyingSession = InternalSessionITUtils.getUnderlyingSession(session);
final Map<?, TEndPoint> tableModelDeviceIdToEndpoint =
final Map<?, Map<?, TEndPoint>> tableModelDeviceIdToEndpointByDatabase =
InternalSessionITUtils.getSessionField(underlyingSession, "tableModelDeviceIdToEndpoint");
assertEquals(1, tableModelDeviceIdToEndpointByDatabase.size());
final Map<?, TEndPoint> tableModelDeviceIdToEndpoint =
tableModelDeviceIdToEndpointByDatabase.values().iterator().next();
assertEquals(1, tableModelDeviceIdToEndpoint.size());
assertTrue(leaderEndPoints.contains(tableModelDeviceIdToEndpoint.values().iterator().next()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,68 @@ public static void main(String[] args)
}
}

@Test
public void testInsertTabletIntoSpecifiedDatabase()
throws IoTDBConnectionException, StatementExecutionException {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
session.executeNonQueryStatement(
"CREATE TABLE db1.tablet_database (tag1 STRING TAG, m1 DOUBLE FIELD)");
session.executeNonQueryStatement(
"CREATE TABLE db2.tablet_database (tag1 STRING TAG, m1 DOUBLE FIELD)");

List<String> columnNames = Arrays.asList("tag1", "m1");
List<TSDataType> dataTypes = Arrays.asList(TSDataType.STRING, TSDataType.DOUBLE);
List<ColumnCategory> columnCategories =
Arrays.asList(ColumnCategory.TAG, ColumnCategory.FIELD);
Tablet tablet = new Tablet("tablet_database", columnNames, dataTypes, columnCategories, 2);
for (int row = 0; row < 2; row++) {
tablet.addTimestamp(row, row);
tablet.addValue("tag1", row, "tag:" + row);
tablet.addValue("m1", row, row * 1.0);
}

session.insert(tablet, "db1");
session.executeNonQueryStatement("USE db1");
session.insert(tablet, "db2");
Tablet currentDatabaseTablet =
new Tablet("tablet_database", columnNames, dataTypes, columnCategories, 1);
currentDatabaseTablet.addTimestamp(0, 2);
currentDatabaseTablet.addValue("tag1", 0, "tag:2");
currentDatabaseTablet.addValue("m1", 0, 2.0);
session.insert(currentDatabaseTablet, null);

try (SessionDataSet dataSet =
session.executeQueryStatement("SELECT * FROM db1.tablet_database")) {
assertTrue(dataSet.hasNext());
dataSet.next();
assertTrue(dataSet.hasNext());
dataSet.next();
assertTrue(dataSet.hasNext());
dataSet.next();
assertFalse(dataSet.hasNext());
}
try (SessionDataSet dataSet =
session.executeQueryStatement("SELECT * FROM db2.tablet_database")) {
assertTrue(dataSet.hasNext());
dataSet.next();
assertTrue(dataSet.hasNext());
dataSet.next();
assertFalse(dataSet.hasNext());
}
try (SessionDataSet dataSet = session.executeQueryStatement("SHOW CURRENT_DATABASE")) {
assertTrue(dataSet.hasNext());
assertEquals("db1", dataSet.next().getField(0).getStringValue());
}

for (String invalidDatabase : Arrays.asList("", " ", "a.b", "root.treedb", "ROOT.treedb")) {
StatementExecutionException exception =
assertThrows(
StatementExecutionException.class, () -> session.insert(tablet, invalidDatabase));
assertEquals(TSStatusCode.ILLEGAL_PATH.getStatusCode(), exception.getStatusCode());
}
}
}

private static void insertRelationalTabletPerformanceTest()
throws IoTDBConnectionException, StatementExecutionException {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ public void testInternalPullConsumerPollsAcrossDataNodes() throws Exception {
session.executeNonQueryStatement("flush");

final Session underlyingSession = InternalSessionITUtils.getUnderlyingSession(session);
final Map<?, TEndPoint> deviceToEndpoint =
final Map<?, Map<?, TEndPoint>> deviceToEndpointByDatabase =
InternalSessionITUtils.getSessionField(
underlyingSession, "tableModelDeviceIdToEndpoint");
leaders.addAll(deviceToEndpoint.values());
deviceToEndpointByDatabase
.values()
.forEach(deviceToEndpoint -> leaders.addAll(deviceToEndpoint.values()));
}

Assert.assertTrue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@
boolean enableRPCCompression,
int connectionTimeoutInMs,
Map<String, TEndPoint> deviceIdToEndpoint,
Map<IDeviceID, TEndPoint> tabletModelDeviceIdToEndpoint,
Map<IDeviceID, TEndPoint> tableModelDeviceIdToEndpoint,
INodeSupplier nodeSupplier)
throws IoTDBConnectionException;

void openWithTableModelDatabaseCache(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds an internal cache-sharing hook to ISession, a public interface that users program against, and its nested-map parameter exposes the cache layout. The only callers are in SessionPool. The method has to be on the interface only because getSession() declares ISession session = queue.poll();. Opening the new connection through a local Session would avoid that:

Session newSession = constructNewSession();
newSession.openWithTableModelDatabaseCache(...);
session = newSession;

tryConstructNewSession() already uses a Session.

Separately, the new abstract methods here and the new ITableSession.insert(Tablet, String) break every third-party implementation of these interfaces at compile time. ISession already uses default methods for this kind of evolution (e.g. isEnableCacheLeader). insert(Tablet, String) could be a default method that delegates to insert(tablet) when database == null and throws UnsupportedOperationException otherwise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR intentionally changes the ISession and ITableSession contracts so that database-scoped tablet insertion is a first-class API. Third-party implementations are expected to implement the new contract when adopting this version; a default implementation that ignores the requested database could silently write data to the wrong database, so we will keep these methods abstract.

boolean enableRPCCompression,

Check warning on line 78 in iotdb-client/isession/src/main/java/org/apache/iotdb/isession/ISession.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Abbreviation in name 'enableRPCCompression' must contain no more than '2' consecutive capital letters.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AaHOv4dKuDHHi52pnTma&open=AaHOv4dKuDHHi52pnTma&pullRequest=19237
int connectionTimeoutInMs,
Map<String, TEndPoint> deviceIdToEndpoint,
Map<String, Map<IDeviceID, TEndPoint>> tableModelDeviceIdToEndpoint,
INodeSupplier nodeSupplier)
throws IoTDBConnectionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public interface ITableSession extends AutoCloseable {
*/
void insert(Tablet tablet) throws StatementExecutionException, IoTDBConnectionException;

/**
* Inserts a {@link Tablet} into the specified database for this invocation only.
*
* <p>The database does not become the current database of this session and subsequent operations
* are unaffected.
*
* @param tablet the tablet containing time-series data to be inserted.
* @param database the target database for this insertion; if null, the current database of this
* session is used.
* @throws StatementExecutionException if an error occurs while executing the statement.
* @throws IoTDBConnectionException if there is an issue with the IoTDB connection.
*/
void insert(Tablet tablet, String database)
throws StatementExecutionException, IoTDBConnectionException;

/**
* Executes a non-query SQL statement, such as a DDL or DML command.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ public class SessionConfig {

public static final String DEFAULT_SSL_PROTOCOL = "TLS";

public static final String SUPPORTS_DATABASE_SCOPED_TABLET = "supports_database_scoped_tablet";

private SessionConfig() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.isession.util;

import java.util.regex.Pattern;

/** Utilities for table-model database names. */
public final class TableModelDatabaseUtils {

private static final Pattern DATABASE_NAME_PATTERN =
Pattern.compile("([a-zA-Z0-9`_\\-\\u2E80-\\u9FFF]+)");

private TableModelDatabaseUtils() {}

Check warning on line 30 in iotdb-client/isession/src/main/java/org/apache/iotdb/isession/util/TableModelDatabaseUtils.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'}' at column 38 should be alone on a line.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AaHjMdy9L4I3xanui4k7&open=AaHjMdy9L4I3xanui4k7&pullRequest=19237

public static boolean isValidDatabaseName(String databaseName, int maxLength) {
return databaseName != null
&& databaseName.length() <= maxLength
&& databaseName.indexOf('.') < 0
&& DATABASE_NAME_PATTERN.matcher(databaseName).matches();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ private SessionMessages() {}
public static final String EXCEPTION_SESSION_CAN_NOT_CONNECT_TO_ARG_226FBA66 =
"Session can not connect to {}";

public static final String EXCEPTION_INVALID_TABLE_MODEL_DATABASE_NAME_ARG_30813145 =
"Invalid table-model database name \"%s\". Expected an identifier of at most 64 characters"
+ " using letters, numbers, Chinese characters, backticks, underscores, or hyphens.";

public static final String
EXCEPTION_SERVER_DOES_NOT_SUPPORT_DATABASE_SCOPED_TABLET_INSERTION_01CFFAF8 =
"The connected server does not support database-scoped Tablet insertion. Upgrade the"
+ " server to use insert(Tablet, String database).";

public static final String
EXCEPTION_ALL_VALUES_ARE_NULL_AND_THIS_SUBMISSION_IS_IGNORED_DEVICEID_IS_ARG_TIME_IS_ARG_MEASUREMENTS_IS_ARG_5524221C =
"All values are null and this submission is ignored,deviceId is [{}],time is"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ private SessionMessages() {}

public static final String EXCEPTION_SESSION_CAN_NOT_CONNECT_TO_ARG_226FBA66 = "Session 无法连接到 {}";

public static final String EXCEPTION_INVALID_TABLE_MODEL_DATABASE_NAME_ARG_30813145 =
"表模型数据库名称“%s”无效。名称长度不得超过 64 个字符,且只能包含字母、数字、中文字符、反引号、下划线或连字符。";

public static final String
EXCEPTION_SERVER_DOES_NOT_SUPPORT_DATABASE_SCOPED_TABLET_INSERTION_01CFFAF8 =
"连接的服务器不支持按 database 写入 Tablet。请升级服务器后使用 insert(Tablet, String database)。";

public static final String
EXCEPTION_ALL_VALUES_ARE_NULL_AND_THIS_SUBMISSION_IS_IGNORED_DEVICEID_IS_ARG_TIME_IS_ARG_MEASUREMENTS_IS_ARG_5524221C =
"所有值均为空,本次提交被忽略,deviceId 为 [{}],time 为 [{}],measurements 为 [{}]";
Expand Down
Loading
Loading