apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.87k stars 6.73k forks source link

Remove read data source from readwrite-split zk config throw exception #11837

Closed terrymanu closed 3 years ago

terrymanu commented 3 years ago

Which version of ShardingSphere did you use?

master

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-Proxy

Expected behavior

Update config successful

Actual behavior

original config in zk

- !READWRITE_SPLITTING
  dataSources:
    pr_ds:
      readDataSourceNames:
      - read_ds_0
      - read_ds_1
      writeDataSourceName: write_ds

changed config in zk

- !READWRITE_SPLITTING
  dataSources:
    pr_ds:
      readDataSourceNames:
      - read_ds_0
      writeDataSourceName: write_ds

exception thrown

严重: Exception thrown by subscriber method renew(org.apache.shardingsphere.governance.core.registry.config.event.rule.RuleConfigurationsChangedEvent) on subscriber org.apache.shardingsphere.governance.context.ClusterContextManager@21d1b321 when dispatching event: org.apache.shardingsphere.governance.core.registry.config.event.rule.RuleConfigurationsChangedEvent@3bdfdb40
java.lang.IllegalStateException: Single table conflict, there are multiple tables `t_order` existed.
    at com.google.common.base.Preconditions.checkState(Preconditions.java:589)
    at org.apache.shardingsphere.infra.rule.single.SingleTableDataNodeLoader.lambda$load$0(SingleTableDataNodeLoader.java:53)
    at java.util.HashMap$KeySet.forEach(HashMap.java:933)
    at org.apache.shardingsphere.infra.rule.single.SingleTableDataNodeLoader.load(SingleTableDataNodeLoader.java:53)
    at org.apache.shardingsphere.infra.rule.single.SingleTableRule.<init>(SingleTableRule.java:55)
    at org.apache.shardingsphere.infra.rule.builder.single.SingleTableRuleBuilder.build(SingleTableRuleBuilder.java:40)
    at org.apache.shardingsphere.infra.rule.builder.single.SingleTableRuleBuilder.build(SingleTableRuleBuilder.java:35)
    at org.apache.shardingsphere.infra.rule.builder.ShardingSphereRulesBuilder.buildSchemaRules(ShardingSphereRulesBuilder.java:72)
    at org.apache.shardingsphere.infra.context.metadata.MetaDataContextsBuilder.build(MetaDataContextsBuilder.java:98)
    at org.apache.shardingsphere.governance.context.ClusterContextManager.getChangedMetaData(ClusterContextManager.java:329)
    at org.apache.shardingsphere.governance.context.ClusterContextManager.renew(ClusterContextManager.java:223)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:87)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:144)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:72)
    at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:67)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:108)
    at com.google.common.eventbus.EventBus.post(EventBus.java:212)
    at java.util.Optional.ifPresent(Optional.java:159)
    at org.apache.shardingsphere.governance.core.registry.GovernanceWatcherFactory.lambda$watch$0(GovernanceWatcherFactory.java:59)
    at org.apache.shardingsphere.governance.repository.zookeeper.CuratorZookeeperRepository.lambda$watch$1(CuratorZookeeperRepository.java:247)
    at org.apache.curator.framework.recipes.cache.CuratorCacheImpl.lambda$putStorage$6(CuratorCacheImpl.java:274)
    at org.apache.curator.framework.listen.MappingListenerManager.lambda$forEach$0(MappingListenerManager.java:92)
    at org.apache.curator.framework.listen.MappingListenerManager.forEach(MappingListenerManager.java:89)
    at org.apache.curator.framework.listen.StandardListenerManager.forEach(StandardListenerManager.java:89)
    at org.apache.curator.framework.recipes.cache.CuratorCacheImpl.lambda$callListeners$10(CuratorCacheImpl.java:293)
    at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1640)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
strongduanmu commented 3 years ago

This exception is caused by the case that the removed read_ds_1 data source and the pr_ds logical data source have the same table. The single table is checked by default when it is loaded.

After discussion, we decided to add an option to the single table conflict check logic, allowing users to decide whether to check or not.