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: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to