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
a69631a
Defer meta data refresh to transaction end for PostgreSQL table DDL
rishi-rana Sep 21, 2026
a9fb443
Limit transactional DDL support to routed storage and reconcile table…
rishi-rana Sep 25, 2026
5b53acf
Fix deferred table metadata reconciliation and declaration order
rishi-rana Oct 2, 2026
a5f0a6b
Exclude BASE from deferred refresh and fix speculative route leak on …
rishi-rana Oct 5, 2026
44f4640
Revert final on DeferredMetaDataRefreshContextTest for new checkstyle…
rishi-rana Oct 5, 2026
41255ea
Preserve SINGLE config refresh on drop and resolve schema per table
rishi-rana Oct 10, 2026
d6c5555
Resolve each table's schema from binder-resolved bound info
rishi-rana Oct 17, 2026
9963edf
Resolve rename destination schema from source table and reconcile met…
rishi-rana Oct 19, 2026
6f1b572
Exclude SET SCHEMA from deferred DDL, fix pool exhaustion and config …
rishi-rana Oct 28, 2026
feef506
Fix connection release regression, align contract docs, fix line wrap
rishi-rana Oct 30, 2026
a19dce6
Fix NPE on removed database, propagate close errors, align XA docs
rishi-rana Oct 31, 2026
1f17062
Exclude non-transactional-DDL protocols, fix DUAL rename and index re…
rishi-rana Nov 7, 2026
3ce07a8
Exclude FK-referenced tables from deferral, keep latest revision cand…
rishi-rana Nov 7, 2026
f5cb1c7
Describe PostgreSQL rename support accurately, fix helper declaration…
rishi-rana Nov 18, 2026
7492fc3
Merge remote-tracking branch 'upstream/master' into defer-metadata-re…
rishi-rana Nov 18, 2026
01ef8ba
Remove unreachable index-payload plumbing from deferred refresh
rishi-rana Nov 19, 2026
2f3ca9b
Address review: trim Javadocs, restore CreateTable refresher, join sh…
rishi-rana Nov 28, 2026
8ef0445
Use required table attribute and tolerate query errors while polling …
rishi-rana Dec 1, 2026
330c260
Remove unused standalone rename deferral path and re-wrap fluent chain
rishi-rana Dec 2, 2026
e0b1b18
Annotate per-transaction paths as high frequency and document visibil…
rishi-rana Dec 4, 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
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
1. Proxy: Preserve the SQL error code in Firebird invalid batch message length responses - [#40408](https://github.com/apache/shardingsphere/issues/40408)
1. Proxy: Fix startup failure when storage units set `dataSourceClassName` to `com.zaxxer.hikari.HikariDataSource` - [#40303](https://github.com/apache/shardingsphere/issues/40303)
1. Proxy: Fix Firebird system table schemas: add missing tables and columns and correct column types - [#40254](https://github.com/apache/shardingsphere/issues/40254)
1. Proxy: Defer meta data refresh to commit for table DDL executed in a PostgreSQL transaction - [#39882](https://github.com/apache/shardingsphere/pull/39882)
1. JDBC & Proxy: Remove default MySQL prepared statement query properties when creating data sources - [#38593](https://github.com/apache/shardingsphere/pull/38593)
1. JDBC & Proxy: Reject ordinary pushdown SELECT statements routed to different storage database types - [#40385](https://github.com/apache/shardingsphere/pull/40385)
1. JDBC & Proxy: Reject ordinary pushdown DAL statements routed to different storage database types - [#40465](https://github.com/apache/shardingsphere/pull/40465)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ default DialectConnectionOption getConnectionOption() {
* @return transaction option
*/
default DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, false, true, false, false, Collections.emptyList());
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, false, true, false, false, false, Collections.emptyList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public final class DialectTransactionOption {

private final boolean isAllowCommitAndRollbackOnlyWhenTransactionFailed;

private final boolean isSupportTransactionalDDL;

private final Collection<String> xaDriverClassNames;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public DialectSchemaOption getSchemaOption() {

@Override
public DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(false, DDLCommitPolicy.COMMIT_CURRENT_TRANSACTION, false, false, true, false, true, Collections.singleton("org.firebirdsql.ds.FBXADataSource"));
return new DialectTransactionOption(false, DDLCommitPolicy.COMMIT_CURRENT_TRANSACTION, false, false, true, false, true, false, Collections.singleton("org.firebirdsql.ds.FBXADataSource"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public NullsOrderType getDefaultNullsOrderType() {

@Override
public DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, false, true, false, false, Collections.singleton("org.h2.jdbcx.JdbcDataSource"));
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, false, true, false, false, false, Collections.singleton("org.h2.jdbcx.JdbcDataSource"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public MariaDBDatabaseMetaData() {

@Override
public DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, true, false, true, false, false,
Collections.singleton("org.mariadb.jdbc.MariaDbDataSource"));
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, true, false, true, false, false, false, Collections.singleton("org.mariadb.jdbc.MariaDbDataSource"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public DialectConnectionOption getConnectionOption() {

@Override
public DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, true, false, true, false, false,
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, true, false, true, false, false, false,
Arrays.asList("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource", "com.mysql.cj.jdbc.MysqlXADataSource"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public DialectFunctionOption getFunctionOption() {

@Override
public DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(true, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, true, false, true, true,
Collections.singleton("org.opengauss.xa.PGXADataSource"));
return new DialectTransactionOption(true, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, true, false, true, true, false, Collections.singleton("org.opengauss.xa.PGXADataSource"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public DialectConnectionOption getConnectionOption() {

@Override
public DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, false, true, false, false,
Collections.singleton("oracle.jdbc.xa.client.OracleXADataSource"));
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, false, true, false, false, false, Collections.singleton("oracle.jdbc.xa.client.OracleXADataSource"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public DialectFunctionOption getFunctionOption() {

@Override
public DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, true, false, true, true,
Collections.singleton("org.postgresql.xa.PGXADataSource"));
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, true, false, true, true, true, Collections.singleton("org.postgresql.xa.PGXADataSource"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void assertGetTransactionOption() {
assertFalse(actual.isSupportMetaDataRefreshInTransaction());
assertTrue(actual.isReturnRollbackStatementWhenCommitFailed());
assertTrue(actual.isAllowCommitAndRollbackOnlyWhenTransactionFailed());
assertTrue(actual.isSupportTransactionalDDL());
assertThat(actual.getXaDriverClassNames().size(), is(1));
assertTrue(actual.getXaDriverClassNames().contains("org.postgresql.xa.PGXADataSource"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DialectSchemaOption getSchemaOption() {

@Override
public DialectTransactionOption getTransactionOption() {
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, false, true, false, false,
return new DialectTransactionOption(false, DDLCommitPolicy.NO_ADDITIONAL_COMMIT, false, false, true, false, false, false,
Collections.singleton("com.microsoft.sqlserver.jdbc.SQLServerXADataSource"));
}

Expand Down
3 changes: 2 additions & 1 deletion docs/document/content/features/transaction/appendix.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ weight = 3
不支持的 SQL:

- 事务中使用 DistSQL 里的 RAL、RDL 操作;
- XA 事务中的 DDL 支持取决于数据库方言;PostgreSQL 和 openGauss 仅支持不改变元数据的 DDL 语句。
- XA 事务中的 DDL 支持取决于数据库方言;openGauss 仅支持不改变元数据的 DDL 语句。
PostgreSQL 还支持 `CREATE TABLE`、`ALTER TABLE`(包括 `RENAME TO`)和 `DROP TABLE`,其元数据刷新延迟到事务结束后执行(详见使用限制)。

XA 事务所需的权限:

Expand Down
3 changes: 2 additions & 1 deletion docs/document/content/features/transaction/appendix.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ weight = 3
Unsupported SQL:

- RAL and RDL operations of DistSQL that are used in transactions.
- DDL support in XA transactions depends on the database dialect. PostgreSQL and openGauss permit only DDL statements that do not change metadata.
- DDL support in XA transactions depends on the database dialect. openGauss permits only DDL statements that do not change metadata.
PostgreSQL additionally permits `CREATE TABLE`, `ALTER TABLE` (including `RENAME TO`) and `DROP TABLE`, whose metadata refresh is deferred until the transaction ends (see Limitations).

Privileges required for XA transactions:

Expand Down
15 changes: 12 additions & 3 deletions docs/document/content/features/transaction/limitations.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ Apache ShardingSphere 希望能够将分布式事务的选择权交给使用者
### 不支持项

* 不支持因网络、硬件异常导致的跨库事务。例如:同一事务中,跨两个库更新,更新完毕后、未提交之前,第一个库宕机,则只有第二个库数据提交,且无法回滚。
* ShardingSphere-Proxy 使用 PostgreSQL 或 openGauss 时,不支持在事务中执行会改变元数据的 DDL 语句(如 `CREATE`、`ALTER` 和 `DROP`)。
此类语句会在执行前以 SQLSTATE `0A000` 拒绝,避免事务回滚后存储数据库与 ShardingSphere 元数据不一致。
* ShardingSphere-Proxy 使用 PostgreSQL 时,事务中执行 `ALTER TABLE` 改变的表,其元数据会在事务结束后刷新,而不会因为元数据刷新另用一条无法看到未提交事务的连接而刷新失败。
`CREATE TABLE`、`DROP TABLE` 和 `ALTER TABLE ... RENAME TO` 使用同一套延迟刷新机制改变元数据,因此基于同样的原因受支持,而非另行扩展支持的语句集合。
其余会改变元数据的 DDL 语句仍不支持,包括 schema、视图和索引语句。ShardingSphere-Proxy 使用 openGauss 时,事务中不支持任何会改变元数据的 DDL 语句。
不支持的语句会在执行前以 SQLSTATE `0A000` 拒绝,避免事务回滚后存储数据库与 ShardingSphere 元数据不一致。
* 事务中不支持 `ALTER TABLE ... SET SCHEMA`,即便其它 `ALTER TABLE` 形式都受支持,因为目前无法在提交后解析出目标 schema。
* 同一事务中,后续语句无法使用该事务内 DDL 已变更的结构,例如新建的表、已有表新增的列或重命名后的表,因为这些结构的元数据只在事务结束时才生效。
例如 `BEGIN; CREATE TABLE t (...); ALTER TABLE t ...;` 以及 `BEGIN; ALTER TABLE t ADD COLUMN c INT; INSERT INTO t (id, c) VALUES (1, 1);` 都会在第二条语句上失败。
* 上述表 DDL 支持仅在语句路由到的每个存储单元都将 DDL 纳入事务时生效。
PostgreSQL 协议的会话若路由到隐式提交 DDL 的存储库(如 MySQL),仍保留该限制,因为存储库会立即提交语句,而 ShardingSphere 元数据仍处于延迟刷新状态。

## XA 事务

Expand All @@ -21,10 +28,12 @@ Apache ShardingSphere 希望能够将分布式事务的选择权交给使用者
* 服务宕机后,在其它机器上恢复提交/回滚中的数据;
* MySQL 事务块内,SQL 执行出现异常,执行 `Commit`,数据保持一致;
* 配置 XA 事务后,存储单元名称最大长度不超过45个字符。
* PostgreSQL 和 openGauss 同样受 LOCAL 事务中所述的元数据变更 DDL 限制。
* PostgreSQL 和 openGauss 的元数据变更 DDL 支持范围与限制,与 LOCAL 事务中所述一致。

## BASE 事务

### 不支持项

* 不支持隔离级别。
* PostgreSQL 和 openGauss 在事务中不支持会改变元数据的 DDL 语句。
LOCAL 和 XA 事务所支持的表 DDL,在 BASE 事务中不支持。
15 changes: 12 additions & 3 deletions docs/document/content/features/transaction/limitations.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ The Apache ShardingSphere community chose instead to give the users the ability
### Unsupported

* Does not support the cross-database transactions caused by network or hardware crash. For example, when updating two databases in transaction, if one database crashes before commit, then only the data of the other database can commit.
* When ShardingSphere-Proxy uses PostgreSQL or openGauss, metadata-changing DDL statements such as `CREATE`, `ALTER`, and `DROP` are not supported in transactions.
Such statements are rejected before execution with SQLSTATE `0A000` to prevent inconsistencies between storage and ShardingSphere metadata after a transaction rollback.
* When ShardingSphere-Proxy uses PostgreSQL, a table changed by `ALTER TABLE` inside a transaction has its metadata refreshed when the transaction ends, instead of failing to see the change because metadata refresh otherwise uses a separate connection that cannot see the still-open transaction.
`CREATE TABLE`, `DROP TABLE` and `ALTER TABLE ... RENAME TO` change metadata through that same deferred-refresh mechanism and are supported for the same reason, not as a separately extended set of statements.
Every other metadata-changing DDL statement, including schema, view and index statements, is still not supported. When ShardingSphere-Proxy uses openGauss, no metadata-changing DDL statement is supported in transactions.
Unsupported statements are rejected before execution with SQLSTATE `0A000` to prevent inconsistencies between storage and ShardingSphere metadata after a transaction rollback.
* `ALTER TABLE ... SET SCHEMA` is not supported in transactions, even though other `ALTER TABLE` forms are, because the destination schema cannot currently be resolved after commit.
* A statement cannot use a structure that DDL changed earlier in the same transaction, such as a newly created table, a column added to an existing table or a renamed table, because the meta data of that structure is only applied when the transaction ends.
For example `BEGIN; CREATE TABLE t (...); ALTER TABLE t ...;` and `BEGIN; ALTER TABLE t ADD COLUMN c INT; INSERT INTO t (id, c) VALUES (1, 1);` fail on the second statement.
* The table DDL support above applies only when every storage unit the statement is routed to keeps DDL transactional.
A PostgreSQL-protocol session routed to storage that commits DDL implicitly, such as MySQL, keeps the restriction, because the storage would commit the statement while ShardingSphere metadata is still deferred.

## XA Transaction

Expand All @@ -22,10 +29,12 @@ The Apache ShardingSphere community chose instead to give the users the ability
* Recover committing and rolling back in other machines after the service is down.
* MySQL, in the transaction block, the SQL execution is abnormal, and run `Commit`, and data remains consistent.
* After XA transactions are configured, the maximum length of the storage unit name cannot exceed 45 characters.
* PostgreSQL and openGauss have the same metadata-changing DDL restriction described for LOCAL transactions.
* PostgreSQL and openGauss have the same metadata-changing DDL support and restrictions described for LOCAL transactions.

## BASE Transaction

### Unsupported

* Does not support isolation level.
* Metadata-changing DDL statements are not supported in transactions for PostgreSQL and openGauss.
The table DDL that LOCAL and XA transactions support is not supported in BASE transactions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@
import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial;
import org.apache.shardingsphere.infra.metadata.database.schema.manager.GenericSchemaManager;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
import org.apache.shardingsphere.infra.metadata.statistics.builder.ShardingSphereStatisticsFactory;
import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute;
import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder;
import org.apache.shardingsphere.mode.exclusive.ExclusiveOperatorEngine;
import org.apache.shardingsphere.mode.manager.listener.ContextManagerLifecycleListenerFactory;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.factory.MetaDataContextsFactory;
import org.apache.shardingsphere.mode.metadata.manager.MetaDataContextManager;
import org.apache.shardingsphere.mode.metadata.manager.resource.SwitchingResource;
import org.apache.shardingsphere.mode.metadata.refresher.pushdown.type.table.TableMetaDataRefresherLoader;
import org.apache.shardingsphere.mode.metadata.refresher.util.TableRefreshUtils;
import org.apache.shardingsphere.mode.persist.PersistServiceFacade;
import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
import org.apache.shardingsphere.mode.state.StateContext;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
Expand Down Expand Up @@ -281,6 +286,39 @@ private void persistTable(final ShardingSphereDatabase database, final String sc
}
}

/**
* Reconcile table meta data against the committed state of the table.
*
* @param database database
* @param schemaName schema name
* @param logicDataSourceName logic data source name the table is routed to
* @param tableName to be reconciled table name
*/
public void reconcileTable(final ShardingSphereDatabase database, final String schemaName, final String logicDataSourceName, final IdentifierValue tableName) {
MetaDataManagerPersistService metaDataManagerPersistService = persistServiceFacade.getModeFacade().getMetaDataManagerService();
try {
String candidateTableName = TableRefreshUtils.getTableLoadCandidateName(database, tableName);
boolean wasAlreadyRouted = database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).stream()
.anyMatch(each -> each.findTableDataNode(schemaName, candidateTableName).isPresent());
ShardingSphereTable loadedTable = new TableMetaDataRefresherLoader().loadCreatedTable(database, logicDataSourceName, schemaName, tableName, metaDataContexts.getMetaData().getProps(),
database.getAllSchemas());
if (null == loadedTable) {
if (!wasAlreadyRouted) {
database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.remove(schemaName, candidateTableName));
}
metaDataManagerPersistService.dropTables(database, schemaName, Collections.singleton(candidateTableName));
} else if (database.containsSchema(schemaName) && database.getSchema(schemaName).containsTable(tableName)) {
metaDataManagerPersistService.alterTables(database, schemaName, Collections.singleton(loadedTable));
} else {
metaDataManagerPersistService.createTable(database, schemaName, loadedTable);
}
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
log.error("Reconcile table: {} meta data of database: {} schema: {} failed", tableName.getValue(), database.getName(), schemaName, ex);
}
}

/**
* Get pre-selected database name.
*
Expand Down
Loading
Loading