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

   ## Bug Report
   
   **For English only**, other languages will not accept.
   
   Before report a bug, make sure you have:
   
   - Searched open and closed [GitHub 
issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere 
Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more 
details. 
   If no response anymore and we cannot reproduce it on current information, we 
will **close it**.
   
   Please answer these questions before submitting your issue. Thanks!
   
   ### Which version of ShardingSphere did you use?
   
   Version 5.5.2
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-JDBC
   
   ### Expected behavior
   
   Flyway database schema, table and migrations are created and executed across 
all shards.
   
   ### Actual behavior
   
   Spring boot 3.4.11 appication don't run properly because flyway can't be 
initialized.
   The app log shows as a kind of series of attempts to create the schema 
"db_version_control" several times in each shard but finally fails.
   
   ```
   Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.615 [main] [INFO] 
org.flywaydb.core.internal.database.base.Schema TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Creating schema "db_version_control" ...
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.615 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Logic SQL: CREATE SCHEMA "db_version_control"
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.615 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: shard-1 ::: CREATE SCHEMA 
"db_version_control"
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.615 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: shard-2 ::: CREATE SCHEMA 
"db_version_control"
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.615 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: main ::: CREATE SCHEMA 
"db_version_control"
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.621 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Logic SQL: SELECT 
pg_try_advisory_xact_lock(77432790274465)
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.621 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: main ::: SELECT 
pg_try_advisory_xact_lock(77432790274465)
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.623 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Logic SQL: SET ROLE 'postgres'
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.623 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: shard-1 ::: SET ROLE 'postgres'
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.623 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: shard-2 ::: SET ROLE 'postgres'
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.623 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: main ::: SET ROLE 'postgres'
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.666 [main] [INFO] 
org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Creating Schema History table 
"db_version_control"."flyway_schema_history" ...
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.675 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Logic SQL: SET ROLE 'postgres'
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.675 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: shard-1 ::: SET ROLE 'postgres'
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.675 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: shard-2 ::: SET ROLE 'postgres'
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.675 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: main ::: SET ROLE 'postgres'
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.693 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Logic SQL: SELECT set_config('search_path', ?, 
false)
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.693 [main] [INFO] 
ShardingSphere-SQL TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Actual SQL: main ::: SELECT 
set_config('search_path', ?, false) ::: ["$user", public]
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.701 [main] [WARN] 
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
 TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Exception encountered during context 
initialization - cancelling refresh attempt: 
org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'entityManagerFactory' defined in class path resource 
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:
 Failed to initialize dependency 'flywayInitializer' of LoadTimeWeaverAware 
bean 'entityManagerFactory': Error creating bean with name 'flywayInitializer' 
defined in class path resource 
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
 null
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.702 [main] [INFO] 
com.zaxxer.hikari.HikariDataSource TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:HikariPool-1 - Shutdown initiated...
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.706 [main] [INFO] 
com.zaxxer.hikari.HikariDataSource TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:HikariPool-1 - Shutdown completed.
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.730 [main] [INFO] 
org.apache.catalina.core.StandardService TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Stopping service [Tomcat]
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.742 [main] [INFO] 
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLogger 
TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:
   
   Error starting ApplicationContext. To display the condition evaluation 
report re-run your application with 'debug' enabled.
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV -2025-12-23T08:26:15.769 [main] [ERROR] 
org.springframework.boot.SpringApplication TenantId:
                   CorrelationId: App-name:moduleName_IS_UNDEFINED 
App-Version:1.8.0-SNAPSHOT Msg:Application run failed
    Product-name:productName_IS_UNDEFINED 
Product-version:productVersion_IS_UNDEFINED
                   Environment:DEV 
-org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'entityManagerFactory' defined in class path resource 
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:
 Failed to initialize dependency 'flywayInitializer' of LoadTimeWeaverAware 
bean 'entityManagerFactory': Error creating bean with name 'flywayInitializer' 
defined in class path resource 
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
 null
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
        at 
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:973)
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627)
        at 
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
        at 
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
        at 
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
        at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
        at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
        at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
        at 
com.roche.infinity.qcadvancedservice.QcAdvancedServiceApplication.main(QcAdvancedServiceApplication.java:16)
   Caused by: org.springframework.beans.factory.BeanCreationException: Error 
creating bean with name 'flywayInitializer' defined in class path resource 
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
 null
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1826)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:607)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:529)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:339)
        at 
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:373)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
        ... 10 common frames omitted
   Caused by: 
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException:
 null
        at 
org.apache.shardingsphere.single.route.engine.SingleRouteEngine.routeDDLStatementWithExistTable(SingleRouteEngine.java:117)
        at 
org.apache.shardingsphere.single.route.engine.SingleRouteEngine.routeDDLStatement(SingleRouteEngine.java:101)
        at 
org.apache.shardingsphere.single.route.engine.SingleRouteEngine.routeStatement(SingleRouteEngine.java:79)
        at 
org.apache.shardingsphere.single.route.engine.SingleRouteEngine.route(SingleRouteEngine.java:68)
        at 
org.apache.shardingsphere.single.route.SingleSQLRouter.createRouteContext(SingleSQLRouter.java:62)
        at 
org.apache.shardingsphere.single.route.SingleSQLRouter.createRouteContext(SingleSQLRouter.java:47)
        at 
org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:113)
        at 
org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:97)
        at 
org.apache.shardingsphere.infra.connection.kernel.KernelProcessor.route(KernelProcessor.java:68)
        at 
org.apache.shardingsphere.infra.connection.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:51)
        at 
org.apache.shardingsphere.driver.executor.engine.DriverExecuteExecutor.execute(DriverExecuteExecutor.java:113)
        at 
org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacade.execute(DriverExecutorFacade.java:144)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.execute(ShardingSphereStatement.java:251)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.execute(ShardingSphereStatement.java:196)
        at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94)
        at 
com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
        at 
org.flywaydb.core.internal.jdbc.JdbcTemplate.executeStatement(JdbcTemplate.java:210)
        at 
org.flywaydb.core.internal.sqlscript.ParsedSqlStatement.execute(ParsedSqlStatement.java:88)
        at 
org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:212)
        at 
org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.execute(DefaultSqlScriptExecutor.java:137)
        at 
org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory$1$1.call(JdbcTableSchemaHistory.java:123)
        at 
org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate.execute(TransactionalExecutionTemplate.java:59)
        at 
org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory$1.call(JdbcTableSchemaHistory.java:119)
        at 
org.flywaydb.database.postgresql.PostgreSQLAdvisoryLockTemplate.execute(PostgreSQLAdvisoryLockTemplate.java:77)
        at 
org.flywaydb.database.postgresql.PostgreSQLAdvisoryLockTemplate.lambda$execute$0(PostgreSQLAdvisoryLockTemplate.java:60)
        at 
org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate.execute(TransactionalExecutionTemplate.java:59)
        at 
org.flywaydb.database.postgresql.PostgreSQLAdvisoryLockTemplate.execute(PostgreSQLAdvisoryLockTemplate.java:60)
        at 
org.flywaydb.database.postgresql.PostgreSQLConnection.lock(PostgreSQLConnection.java:105)
        at 
org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.create(JdbcTableSchemaHistory.java:109)
        at 
org.flywaydb.core.internal.command.DbSchemas.lambda$create$0(DbSchemas.java:107)
        at 
org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate.execute(TransactionalExecutionTemplate.java:59)
        at 
org.flywaydb.core.internal.command.DbSchemas.create(DbSchemas.java:90)
        at org.flywaydb.core.Flyway.lambda$migrate$0(Flyway.java:182)
        at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:212)
        at org.flywaydb.core.Flyway.migrate(Flyway.java:164)
        at 
org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1873)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1822)
        ... 17 common frames omitted
   ````
   
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   shardingsphere.yml
   ```
   mode:
     type: Standalone
     repository:
       type: JDBC
   dataSources:
     main:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: org.postgresql.Driver
       url: jdbc:postgresql://localhost:5433/postgres?reWriteBatchedInserts=true
       username: postgres
       password: postgres
     shard-1:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: org.postgresql.Driver
       url: jdbc:postgresql://localhost:5434/postgres?reWriteBatchedInserts=true
       username: postgres
       password: postgres
     shard-2:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: org.postgresql.Driver
       url: jdbc:postgresql://localhost:5435/postgres?reWriteBatchedInserts=true
       username: postgres
       password: postgres
   
   rules:
     - !SINGLE
       tables:
         - main.outbox_dm_tables.*
         - main.initial_load_jpa.*
         - main.shardconfig
         #- "*.*.*"
       defaultDataSource: main
   
     - !SHARDING   
       defaultTableStrategy:
         none:
       tables:
         tenant_info:
           actualDataNodes: 
main.tenant_info,shard-1.tenant_info,shard-2.tenant_info
           databaseStrategy:
             standard:
               shardingColumn: tenantId
               shardingAlgorithmName: tenant-to-database
   
         location:
           actualDataNodes: main.location,shard-1.location,shard-2.location
           databaseStrategy:
             standard:
               shardingColumn: tenantId
               shardingAlgorithmName: tenant-to-database
   
         bracket:
           actualDataNodes: main.bracket,shard-1.bracket,shard-2.bracket
           databaseStrategy:
             standard:
               shardingColumn: tenantId
               shardingAlgorithmName: tenant-to-database
   
       shardingAlgorithms:
         tenant-to-database:
           type: CLASS_BASED
           props:
             strategy: STANDARD
             algorithmClassName: 
com.roche.infinity.qcadvancedservice.config.dbsharding.TenantShardingAlgorithm
   props:
     sql-show: true
   ```
   
   application.yaml
    ```
   spring:
     datasource:
       driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
       jdbc-url: jdbc:shardingsphere:classpath:shardingsphere.yml
   
     jpa:
       show-sql: false
       open-in-view: false
       hibernate:
         ddl-auto: none
   
     flyway:
       enabled: true
       baseline-on-migrate: true
       baseline-version: 0
       schemas: db_version_control
       out-of-order: true
       ignore-migration-patterns: "*:missing"
   ```
   
   
   ### Example codes for reproduce this issue (such as a github link).
   


-- 
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