apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
19.96k stars 6.74k forks source link

Use sharding-jdbc ;when I create partition table automatically more than 5 ,my project get stuck! #1476

Closed LuckyJokers closed 6 years ago

LuckyJokers commented 6 years ago

1.version and my properties:

shading jdbc 2.0.0M1

 spring.jpa.properties.hibernate.hbm2ddl.auto=create
 spring.aop.auto=true
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
 sharding.jdbc.datasource.names=ds_0,ds_1,ds_2

 sharding.jdbc.datasource.ds_0.type=org.apache.commons.dbcp.BasicDataSource
 sharding.jdbc.datasource.ds_0.driverClassName=org.postgresql.Driver
 sharding.jdbc.datasource.ds_0.url=jdbc:postgresql://localhost:5432/d_s_0
 sharding.jdbc.datasource.ds_0.username=postgres
 sharding.jdbc.datasource.ds_0.password=postgres

 sharding.jdbc.datasource.ds_1.type=org.apache.commons.dbcp.BasicDataSource
 sharding.jdbc.datasource.ds_1.driverClassName=org.postgresql.Driver
 sharding.jdbc.datasource.ds_1.url=jdbc:postgresql://localhost:5432/d_s_1
 sharding.jdbc.datasource.ds_1.username=postgres
 sharding.jdbc.datasource.ds_1.password=postgres

 sharding.jdbc.datasource.ds_2.type=org.apache.commons.dbcp.BasicDataSource
 sharding.jdbc.datasource.ds_2.driverClassName=org.postgresql.Driver
 sharding.jdbc.datasource.ds_2.url=jdbc:postgresql://localhost:5432/d_s_2
 sharding.jdbc.datasource.ds_2.username=postgres
 sharding.jdbc.datasource.ds_2.password=postgres

 sharding.jdbc.config.sharding.tables.t_order.databaseStrategy.inline.sharding-column=order_id
 sharding.jdbc.config.sharding.tables.t_order.databaseStrategy.inline.algorithm-inline-expression=ds_${Math.abs(order_id.hashCode() % 3)}

 sharding.jdbc.config.sharding.tables.t_order.tableStrategy.inline.shardingColumn=order_id
 sharding.jdbc.config.sharding.tables.t_order.tableStrategy.inline.algorithmInlineExpression=t_order_${Math.abs(order_id.hashCode() % 5)}
 sharding.jdbc.config.sharding.tables.t_order.actualDataNodes=ds_${0..2}.t_order_${0..4}
 sharding.jdbc.config.sharding.tables.t_order.keyGeneratorColumnName=order_id

2.Expected behavior

spring.jpa.properties.hibernate.hbm2ddl.auto=create set hibernate.hbm2ddl.auto “create”, then executable program,it will create five partition table automatically.

3.The test program:

public void insert() {
       List<Long> orderIds = new ArrayList<>(10);
       for (int i = 0; i < 100; i++) {
           Order order = new Order();
           order.setUserId(i);
           order.setStatus("INSERT_TEST" + i);
           long orderId = orderRepository.save(order).getOrderId();
           orderIds.add(orderId);
            System.out.println(i+1+".Insert-------"+orderId+":::::::"+Math.abs(String .valueOf(orderId).hashCode() % 3)+"-"+Math.abs(String .valueOf(orderId).hashCode() % 5));
       }
       System.out.println(orderIds);
   }

4.Actual behavior of console:

With the message of console I showed,the log of last line is “org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export”. Schema export had get stuck ,And, it had no change for waiting thirty minute.

  18:54:30.930 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:30.934 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
  18:54:30.939 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
  18:54:30.950 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
  18:54:30.960 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest], using SpringBootContextLoader
  18:54:30.963 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]: class path resource [com/rails/dataserver/db4pg/demo/service/DemoServiceTest-context.xml] does not exist
  18:54:30.963 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]: class path resource [com/rails/dataserver/db4pg/demo/service/DemoServiceTestContext.groovy] does not exist
  18:54:30.963 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]: no resource found for suffixes {-context.xml, Context.groovy}.
  18:54:30.964 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]: DemoServiceTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
  18:54:31.003 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
  18:54:31.004 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
  18:54:31.004 [main] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
  18:54:31.012 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved classpath location [com/rails/dataserver/db4pg/demo/service/] to resources [URL [file:/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/service/]]
  18:54:31.013 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Looking for matching resources in directory tree [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/service]
  18:54:31.013 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Searching directory [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/service] for files matching pattern [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/service/*.class]
  18:54:31.015 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved location pattern [classpath*:com/rails/dataserver/db4pg/demo/service/*.class] to resources [file [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/service/DemoService.class], file [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/service/DemoServiceTest.class]]
  18:54:31.030 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved classpath location [com/rails/dataserver/db4pg/demo/] to resources [URL [file:/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/]]
  18:54:31.030 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Looking for matching resources in directory tree [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo]
  18:54:31.031 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Searching directory [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo] for files matching pattern [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/*.class]
  18:54:31.034 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved location pattern [classpath*:com/rails/dataserver/db4pg/demo/*.class] to resources [file [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/SpringBootDataJpaMain.class]]
  18:54:31.060 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver/target/test-classes/com/rails/dataserver/db4pg/demo/SpringBootDataJpaMain.class]
  18:54:31.060 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.rails.dataserver.db4pg.demo.SpringBootDataJpaMain for test class com.rails.dataserver.db4pg.demo.service.DemoServiceTest
  18:54:31.064 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]: using defaults.
  18:54:31.067 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener]
  18:54:31.085 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@146044d7, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1e9e725a, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@15d9bc04, org.springframework.test.context.support.DirtiesContextTestExecutionListener@473b46c3, org.springframework.test.context.transaction.TransactionalTestExecutionListener@516be40f, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@3c0a50da, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@646be2c3, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@797badd3, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@77be656f, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@19dc67c2, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@221af3c0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@62bd765]
  18:54:31.086 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.086 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.087 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.087 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.098 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.098 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.099 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.099 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.099 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.099 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.102 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@62e136d3 testClass = DemoServiceTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@c8e4bb0 testClass = DemoServiceTest, locations = '{}', classes = '{class com.rails.dataserver.db4pg.demo.SpringBootDataJpaMain}', contextInitializerClasses = '[]', activeProfiles = '{local}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@1f36e637, org.springframework.boot.test.context.SpringBootTestContextCustomizer@32709393, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@cd2dae5, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null].
  18:54:31.102 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.102 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.rails.dataserver.db4pg.demo.service.DemoServiceTest]
  18:54:31.155 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
  18:54:31.155 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
  18:54:31.155 [main] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
  18:54:31.156 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [test] PropertySource with highest search precedence
  18:54:31.157 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [inline] PropertySource with highest search precedence
  18:54:31.163 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
  18:54:31.163 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [Inlined Test Properties] PropertySource with highest search precedence

    .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::        (v1.5.3.RELEASE)

  2018-11-14 18:54:31.430  INFO 68526 --- [           main] c.r.d.d.demo.service.DemoServiceTest     : Starting DemoServiceTest on bogon with PID 68526 (started by heyuan in /Users/heyuan/howie/myfileWork/eclipse-workspace/ticket-queue-order/ticket-queue-order-dataserver)
  2018-11-14 18:54:31.430  INFO 68526 --- [           main] c.r.d.d.demo.service.DemoServiceTest     : The following profiles are active: local
  2018-11-14 18:54:31.623  INFO 68526 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Refreshing org.springframework.web.context.support.GenericWebApplicationContext@4d5b6aac: startup date [Wed Nov 14 18:54:31 CST 2018]; root of context hierarchy
  2018-11-14 18:54:32.204  INFO 68526 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
  2018-11-14 18:54:33.329  INFO 68526 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
  2018-11-14 18:54:33.345  INFO 68526 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
  2018-11-14 18:54:33.477  INFO 68526 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
  2018-11-14 18:54:33.478  INFO 68526 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
  2018-11-14 18:54:33.479  INFO 68526 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
  2018-11-14 18:54:33.514  INFO 68526 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  2018-11-14 18:54:33.629  INFO 68526 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
  2018-11-14 18:54:33.762  INFO 68526 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
  2018-11-14 18:54:33.763  INFO 68526 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@17dad32f
  2018-11-14 18:54:34.084  INFO 68526 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export

5.the table structure:

@Entity
@Table(name = "t_order")
 public class Order implements Serializable {
    private static final long serialVersionUID = 661434701950670670L;

   @Id
   @Column(name = "order_id")
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private long orderId;

   @Column(name = "user_id")
   private int userId;

   @Column(name = "status")
   private String status;
  }
terrymanu commented 6 years ago

For English only, other languages will not accept.

xusheng1987 commented 6 years ago

国人开发的项目只允许用英文。。。

LuckyJokers commented 6 years ago

For English only, other languages will not accept.

I have updated the problem ,please reopen it,thank you.