shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Use spring-boot configures MasterSlave with RegistryCenter Zookeeper, the MasterSlave configuration on RegistryCenter is wrong

Open haetao opened this issue 6 years ago • 1 comments

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days 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?

4.0.0-rc3

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

sharding-jdbc

Expected behavior

yaml configuration format: slaveDataSourceNames: - slave_ds_0 - slave_ds_1

Actual behavior

masterDataSourceName: ds_master name: ds_ms slaveDataSourceNames: !!set ds_slave_0: null ds_slave_1: null

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Just run by using spring-boot to configure.

Example codes for reproduce this issue (such as a github link).

haetao avatar Dec 19 '19 11:12 haetao

Spring use StringToCollectionConverter to handle this property. And the type slaveDataSourceNames in YamlMasterSlaveConfiguration is Collection, so spring use HashLinkedSet to save.

public static <E> Collection<E> createCollection(Class<?> collectionType, Class<?> elementType, int capacity) {
        Assert.notNull(collectionType, "Collection type must not be null");
        if (collectionType.isInterface()) {
            if (Set.class != collectionType && Collection.class != collectionType) {
                if (List.class == collectionType) {
                    return new ArrayList(capacity);
                } else if (SortedSet.class != collectionType && NavigableSet.class != collectionType) {
                    throw new IllegalArgumentException("Unsupported Collection interface: " + collectionType.getName());
                } else {
                    return new TreeSet();
                }
            } else {
                return new LinkedHashSet(capacity);
            }
    ...

KomachiSion avatar Dec 20 '19 06:12 KomachiSion