You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "MinLancer (via GitHub)" <gi...@apache.org> on 2026/07/14 02:04:54 UTC

[I] Cluster mode fails on restart: "Global tag is not allowed" for DruidDataSource proxyFilters serialized to ZooKeeper [shardingsphere]

MinLancer opened a new issue, #39090:
URL: https://github.com/apache/shardingsphere/issues/39090

   ## Description
   
   When using ShardingSphere JDBC 5.5.3 in Cluster mode with ZooKeeper as the persistence repository, the application starts successfully on the first run, but fails on every subsequent restart with:
   
   ```
   Global tag is not allowed: tag:yaml.org,2002:com.alibaba.druid.filter.stat.StatFilter
   ```
   
   ## Root Cause Analysis
   
   On the first startup, ShardingSphere serializes the entire `DruidDataSource` runtime state to the ZooKeeper node at `/{namespace}/metadata/{dbname}/data_sources/units/{master,slave,slave2}/versions/0`. The `proxyFilters` field is serialized using SnakeYAML global tags:
   
   ```yaml
   proxyFilters:
   - !!com.alibaba.druid.filter.stat.StatFilter
     ...
   - !!com.alibaba.druid.filter.logging.Log4j2Filter
     ...
   - !!<custom-filter-class>
     ...
   ```
   
   On the next startup, `ShardingSphereYamlConstructor` (in `shardingsphere-infra-util`) rejects these global tags because the Druid filter classes are not registered as YAML shortcuts via SPI. The constructor only allows classes registered through `ShardingSphereYamlShortcuts` SPI.
   
   ## Environment
   
   - ShardingSphere JDBC: 5.5.3 (latest release as of report)
   - Java: 1.8
   - Spring Boot: 2.7.18
   - ZooKeeper: 3.9.5
   - DataSource: Alibaba Druid 1.2.28 (with `StatFilter`, `Log4j2Filter`, and a custom wall filter configured via `ds.setFilters("stat,log4j2,wall")`)
   
   ## Reproduction Steps
   
   1. Configure ShardingSphere JDBC 5.5.3 in Cluster mode with ZooKeeper
   2. Create DataSource via Java API:
      ```java
      DataSource shardingDataSource = ShardingSphereDataSourceFactory.createDataSource(
          "mydb", modeConfig, dataSourceMap, ruleConfigs, props);
      ```
      where `dataSourceMap` contains `DruidDataSource` instances with `proxyFilters` set (via `ds.setFilters("stat,log4j2,wall")`)
   3. Start the application -> succeeds, ZK metadata written
   4. Restart the application -> fails with `Global tag is not allowed`
   
   ## Expected Behavior
   
   Either:
   - (Preferred) ShardingSphere should serialize only DataSource **configuration** (URL, username, etc.) to ZK, not the runtime instance state including `proxyFilters`. The runtime DataSource should be re-created from configuration on each startup.
   - Or: `ShardingSphereYamlConstructor` should allow global tags for classes already on the classpath (with appropriate security controls).
   
   ## Actual Behavior
   
   First startup writes Druid filter instances with global tags to ZK; subsequent startups fail to deserialize them.
   
   ## Workaround
   
   - Use Standalone mode (no ZK persistence) - works fine
   - Or: clear the namespace node in ZK before each restart - not viable for production
   
   ## ZK Node Content (evidence)
   
   Path: `/{namespace}/metadata/{dbname}/data_sources/units/master/versions/0`
   
   Excerpt showing the problematic global tags:
   ```yaml
   proxyFilters:
   - !!com.alibaba.druid.filter.stat.StatFilter
     ...
   - !!com.alibaba.druid.filter.logging.Log4j2Filter
     ...
   ```
   
   ## Stack Trace
   
   ```
   Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingSphereDataSource' ...: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'shardingSphereDataSource' threw exception; nested exception is Global tag is not allowed: tag:yaml.org,2002:com.alibaba.druid.filter.stat.StatFilter
   Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'shardingSphereDataSource' threw exception; nested exception is Global tag is not allowed: tag:yaml.org,2002:com.alibaba.druid.filter.stat.StatFilter
   Caused by: org.yaml.snakeyaml.composer.ComposerException: Global tag is not allowed: tag:yaml.org,2002:com.alibaba.druid.filter.stat.StatFilter
   	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:77)
   	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:65)
   	at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:95)
   ```


-- 
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: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Cluster mode fails on restart: "Global tag is not allowed" for DruidDataSource proxyFilters serialized to ZooKeeper [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #39090:
URL: https://github.com/apache/shardingsphere/issues/39090#issuecomment-5004466458

   Hi @MinLancer, thanks for the detailed report.
   
   This is a valid ShardingSphere-JDBC bug, but it is a recurrence of #21211 and should be classified as a duplicate. Both issues have the same root cause: Druid `proxyFilters` objects are captured as data-source properties, serialized with Java global tags, and then rejected when ShardingSphere reloads the YAML.
   
   This usage is supported. The [5.5.3 Java API documentation](https://shardingsphere.apache.org/document/5.5.3/en/user-manual/shardingsphere-jdbc/java-api/data-source/) states that ShardingSphere-JDBC supports all JDBC drivers and connection pools, while the [mode documentation](https://shardingsphere.apache.org/document/5.5.3/en/user-manual/shardingsphere-jdbc/java-api/mode/) explicitly supports Cluster mode with ZooKeeper. The correct fix is to persist only reconstructible data-source configuration values. We should not relax `ShardingSphereYamlConstructor` to instantiate arbitrary classes available on the classpath.
   
   No merged fixing PR or fixed release was identified for #21211, and the relevant serialization path remains in current master. I suggest reopening #21211 as the canonical bug, adding this 5.5.3 Cluster/ZooKeeper reproduction there, and then labeling #39090 with `type: duplicate` and `in: JDBC` and closing it as duplicate.
   
   The reply above is based on the analysis below; the detailed reasoning is kept here for reference and follow-up contributors.
   
   ### Problem Understanding
   
   - **Issue:** `OBS-1` — ShardingSphere-JDBC 5.5.3 starts successfully with Cluster mode, ZooKeeper, and a Druid data source containing filters, but restart fails on the persisted `!!com.alibaba.druid.filter.stat.StatFilter` tag. Source: #39090.
   - **Topology:** `OBS-1` — `JDBC + Cluster (ZooKeeper)`; the underlying database type is not reported, but the failure occurs while loading repository configuration before SQL execution or database access.
   - **Observed Evidence:** `OBS-2` — The [data-source documentation](https://shardingsphere.apache.org/document/5.5.3/en/user-manual/shardingsphere-jdbc/java-api/data-source/) supports all JDBC drivers and connection pools, and the [mode documentation](https://shardingsphere.apache.org/document/5.5.3/en/user-manual/shardingsphere-jdbc/java-api/mode/) demonstrates the same Java API with Cluster mode and ZooKeeper.
   
   ### Root Cause
   
   - **Observation:** `OBS-3` — `DataSourceProvidedDatabaseConfiguration` converts each supplied `DataSource` into `DataSourcePoolProperties` through `DataSourcePoolPropertiesCreator`: `infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfiguration.java:49` and `:79`.
   - **Observation:** `OBS-4` — `DataSourcePoolReflection` treats `List` and `Collection` getters as persistable properties and records their returned objects: `infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolReflection.java:67` and `:92`. `DataSourcePoolPropertiesCreator` retains all such properties when no pool-specific metadata marks them transient: `infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/creator/DataSourcePoolPropertiesCreator.java:87`.
   - **Observation:** `OBS-5` — `YamlDataSourceConfigurationSwapper` places those properties into the persisted map, while `DataSourceUnitPersistService` marshals that map and later unmarshals it as `Map.class`: `infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/resource/YamlDataSourceConfigurationSwapper.java:105`; `mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/database/DataSourceUnitPersistService.java:76` and `:95`.
   - **Observation:** `OBS-6` — The 5.5.3 YAML constructor accepts only the requested root class when resolving a class tag: `infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructor.java:115`. SnakeYAML therefore rejects Druid filter global tags while loading a `Map`.
   - **Inference:** `INF-1` (from `OBS-3`–`OBS-6`) — ShardingSphere is not literally serializing the complete `DruidDataSource` object. It reflectively snapshots getter values with selected declared types, but this still captures runtime state and object-valued collections such as `proxyFilters`. The persistence format then becomes impossible to load through the intentionally restricted YAML constructor.
   - **Inference:** `INF-2` (from `OBS-6`) — Allowing arbitrary classpath global tags would weaken the YAML class boundary and persist nonportable runtime instances. The fix belongs at the data-source property extraction/persistence boundary: retain reconstructible configuration values and exclude runtime object graphs.
   - **Confidence:** High.
   
   ### Problem Analysis
   
   - **Issue Type:** Duplicate; the underlying behavior remains a Bug.
   - **Evidence:** `OBS-7` — #21211 reports the same `DruidDataSource.setProxyFilters(...)` trigger and the same `StatFilter` global-tag rejection. Its discussion also records that #21048 did not resolve the Druid case.
   - **Prior-Fix Check:** `OBS-8` — #21211 has no linked fixing PR. Comparing tag `5.5.3` (`8d35894433416ef249ebb6ea21f8a8749648e9b6`) with current `apache/master` (`5c0e8aac13e35850b71bac61832de1e8881844cb`) shows that the relevant `DataSourcePoolReflection` and `DataSourceUnitPersistService` behavior remains unchanged.
   - **Negative Scenario:** `OBS-9` — #28480 is also Druid-related but concerns nondeterministic selection between overloaded setter methods. It has a different trigger and root-cause chain, so it is not the duplicate relationship used here.
   - **Fix Scope:** `INF-2` — Preserve the YAML class restriction and prevent object-valued runtime properties from entering persisted data-source configuration. Regression coverage should include a configuration round trip and a JDBC Cluster restart sentinel with an object-valued filter list.
   - **Label Recommendation:** `type: duplicate`, `in: JDBC`.
   
   ### Problem Conclusion
   
   - **Evidence Confidence:** High (`OBS-1`–`OBS-9`, `INF-1`, `INF-2`)
   - **Impact Scope:** ShardingSphere-JDBC Cluster persistence with Druid filters; potentially other reflection-adapted pools exposing object-valued collection getters (`OBS-1`, `OBS-4`, `INF-1`)
   - **Topology:** `JDBC + Cluster (ZooKeeper)` (`OBS-1`)
   - **Issue Type:** Duplicate; underlying defect is Bug (`OBS-7`, `INF-1`)
   - **Duplicate Of:** #21211 (`OBS-7`)
   - **Fix PR:** None identified; #21048 does not fix this root cause (`OBS-7`, `OBS-8`)
   - **Merged In:** N/A (`OBS-8`)
   - **Recommended Labels:** `type: duplicate`, `in: JDBC` (`OBS-1`, `OBS-7`)
   - **Next Action:** Reopen #21211 as the canonical unresolved bug, attach the current 5.5.3 Cluster/ZooKeeper evidence, track the fix and regression tests there, then close #39090 as duplicate (`OBS-7`, `OBS-8`, `INF-2`)


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Cluster mode fails on restart: "Global tag is not allowed" for DruidDataSource proxyFilters serialized to ZooKeeper [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #39090: Cluster mode fails on restart: "Global tag is not allowed" for DruidDataSource proxyFilters serialized to ZooKeeper
URL: https://github.com/apache/shardingsphere/issues/39090


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org