ShardingSphere < IV >_ Read write separation

Posted by phpparty on Thu, 23 Dec 2021 11:59:03 +0100

catalogue

1, Read write separation configuration

2, Verify read / write separation

1. Write verification

2. Read verification

3, Force read Master Library

4, References

1, Read write separation configuration

Note that the configuration is database / Table + read / write separation. ShardingSphere version 3 x,4.0. 1,4.1. 1,5.0. There are great configuration differences between 0-alpha, and 4.1.0 is used here 1.

Among them, multi slave load balancing algorithm type, optional value: round_ Robin, RANDOM, WEIGHT.

spring:
  # Sub table and sub database
  shardingsphere:
    datasource:
      # Define data source name
      names: ds1,ds2,ds1-salve,ds2-salve
      # ds1 data source configuration
      ds1:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://${remote.ip}:3307/nomswc_db_1?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
        username: root
        password: 123456
        initialSize: 5
        minIdle: 2
        maxActive: 20
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: SELECT 1 FROM DUAL
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        logSlowSql: true
      # ds2 data source configuration
      ds2:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://${remote.ip}:3307/nomswc_db_2?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
        username: root
        password: 123456
        initialSize: 5
        minIdle: 2
        maxActive: 20
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: SELECT 1 FROM DUAL
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        logSlowSql: true
      ds1-salve:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://${remote.ip}:3308/nomswc_db_1?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
        username: root
        password: 123456
        initialSize: 5
        minIdle: 2
        maxActive: 20
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: SELECT 1 FROM DUAL
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        logSlowSql: true
      ds2-salve:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://${remote.ip}:3308/nomswc_db_2?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
        username: root
        password: 123456
        initialSize: 5
        minIdle: 2
        maxActive: 20
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: SELECT 1 FROM DUAL
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        logSlowSql: true
    sharding:
      # The default data source is the table data storage table without table splitting rules configured
      default-data-source-name: ds1
      # Binding table relationships,
      binding-tables: wc_pendant_tab_detail,wc_pendant_tab_extend
      # Sub warehouse and sub table
      # ds1 ds2: wc_pendant_tab_detail_1 wc_pendant_tab_detail_2
      tables:
        # Corresponding binding tables configuration
        wc_pendant_tab_detail:
          # Table node
          actual-data-nodes: ds$->{1..2}.wc_pendant_tab_detail_$->{1..2}
          # Primary key field and generation strategy (snowflake algorithm)
#          key-generator:
#            column: tab_id
#            type: SNOWFLAKE
          # Sub database rules
          database-strategy:
            inline:
              sharding-column: mgdb_id
              algorithm-expression: ds$->{Long.valueOf(mgdb_id) % 2 + 1}
          # Table rules
          table-strategy:
            inline:
              sharding-column: mgdb_id
              algorithm-expression: wc_pendant_tab_detail_$->{Math.floorDiv(Long.valueOf(mgdb_id),2L) % 2 + 1}
        # Corresponding binding tables configuration
        wc_pendant_tab_extend:
          actual-data-nodes: ds$->{1..2}.wc_pendant_tab_extend_$->{1..2}
          key-generator:
            column: id
            type: SNOWFLAKE
          # Sub database rules
          database-strategy:
            inline:
              sharding-column: mgdb_id
              algorithm-expression: ds$->{Long.valueOf(mgdb_id) % 2 + 1}
          # Table rules
          table-strategy:
            inline:
              sharding-column: mgdb_id
              algorithm-expression: wc_pendant_tab_extend_$->{Math.floorDiv(Long.valueOf(mgdb_id),2L) % 2 + 1}
      # Read write separation
      master-slave-rules:
        ds1:
          # Slave library load balancing algorithm type, optional value: round_ Robin, RANDOM, WEIGHT
          load-balance-algorithm-type: round_robin
          # Master database data source name
          master-data-source-name: ds1
          # From the list of library data source names, multiple commas are separated
          slave-data-source-names: ds1-salve
        ds2:
          load-balance-algorithm-type: round_robin
          master-data-source-name: ds2
          slave-data-source-names: ds2-salve
    # Open sql output log
    props:
      sql:
        show: true

2, Verify read / write separation

1. Write verification

a. SQL statement

// Insert wc_pendant_tab_detail
<insert id="insert">
        insert into wc_pendant_tab_detail(tab_id,mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id)
        values (#{tabId},#{mgdbId}, #{period}, #{tabType}, #{isShow}, #{name}, #{url}, #{descripton}, #{delFalg}, #{createTime}, #{createBy}, #{updateTime}, #{updateBy}, #{appId}, #{terminalId})
</insert>


// Insert wc_pendant_tab_extend
<insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
    insert into wc_pendant_tab_extend(mgdb_id, name, keywords, create_time, create_by, update_time, update_by)
    values (#{mgdbId}, #{name}, #{keywords}, #{createTime}, #{createBy}, #{updateTime}, #{updateBy})
</insert>

b. Service layer

@Transactional
@ShardingTransactionType(TransactionType.XA)
@Override
public void testTransactionXA() {
    // Get distributed primary key
    String tabId = getRedisId();

    // Assembly object
    WcPendantTabDetail wcPendantTabDetail = getWcPendantTabDetail(tabId);
    WcPendantTabExtend wcPendantTabExtend = getWcPendantTabExtend(wcPendantTabDetail);

    // Save DB
    int detail = wcPendantTabDetailDao.insert(wcPendantTabDetail);
    LogUtil.info(String.format("insert wcPendantTabDetail: %s", detail));

    int extend = wcPendantTabExtendDao.insert(wcPendantTabExtend);
    LogUtil.info(String.format("insert wcPendantTabExtend: %s", extend));
}

c. Log printing

It can be seen from the log that the data is inserted into the ds1 data source partition main library.

2021-12-22 11:00:42.853  INFO [,70af00327f162fdf,70af00327f162fdf,true] 8112 --- [nio-9014-exec-3] ShardingSphere-SQL                       : Logic SQL: insert into wc_pendant_tab_detail(tab_id,mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id)
        values (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2021-12-22 11:00:42.854  INFO [,70af00327f162fdf,70af00327f162fdf,true] 8112 --- [nio-9014-exec-3] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@24f79cb4, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@70750d6), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@70750d6, columnNames=[tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id], insertValueContexts=[InsertValueContext(parametersCount=15, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=195, stopIndex=195, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=197, stopIndex=197, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=200, stopIndex=200, parameterMarkerIndex=2), ParameterMarkerExpressionSegment(startIndex=203, stopIndex=203, parameterMarkerIndex=3), ParameterMarkerExpressionSegment(startIndex=206, stopIndex=206, parameterMarkerIndex=4), ParameterMarkerExpressionSegment(startIndex=209, stopIndex=209, parameterMarkerIndex=5), ParameterMarkerExpressionSegment(startIndex=212, stopIndex=212, parameterMarkerIndex=6), ParameterMarkerExpressionSegment(startIndex=215, stopIndex=215, parameterMarkerIndex=7), ParameterMarkerExpressionSegment(startIndex=218, stopIndex=218, parameterMarkerIndex=8), ParameterMarkerExpressionSegment(startIndex=221, stopIndex=221, parameterMarkerIndex=9), ParameterMarkerExpressionSegment(startIndex=224, stopIndex=224, parameterMarkerIndex=10), ParameterMarkerExpressionSegment(startIndex=227, stopIndex=227, parameterMarkerIndex=11), ParameterMarkerExpressionSegment(startIndex=230, stopIndex=230, parameterMarkerIndex=12), ParameterMarkerExpressionSegment(startIndex=233, stopIndex=233, parameterMarkerIndex=13), ParameterMarkerExpressionSegment(startIndex=236, stopIndex=236, parameterMarkerIndex=14)], parameters=[300004407484, 300004407484, 0, ENTERTAINMENT_R_DETAIL, 1, test300004407484, https://assets.alicdn.com/g/tm/login/3.0.2/img/logo.png, Description300004407484, 0, 2021-12-22 11:00:42.657, admin, 2021-12-22 11:00:42.657, admin, 203023, android])], generatedKeyContext=Optional.empty)
2021-12-22 11:00:42.854  INFO [,70af00327f162fdf,70af00327f162fdf,true] 8112 --- [nio-9014-exec-3] ShardingSphere-SQL                       : Actual SQL: ds1 ::: insert into wc_pendant_tab_detail_1(tab_id,mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id)
        values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ::: [300004407484, 300004407484, 0, ENTERTAINMENT_R_DETAIL, 1, test300004407484, https://assets.alicdn.com/g/tm/login/3.0.2/img/logo.png, Description300004407484, 0, 2021-12-22 11:00:42.657, admin, 2021-12-22 11:00:42.657, admin, 203023, android]
2021-12-22 11:00:42.890  WARN [,70af00327f162fdf,70af00327f162fdf,true] 8112 --- [nio-9014-exec-3] c.a.druid.pool.DruidAbstractDataSource   : discard long time none received connection. , jdbcUrl : jdbc:mysql://192.168.151.202:3307/nomswc_db_1?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC, version : 1.2.8, lastPacketReceivedIdleMillis : 1210416
2021-12-22 11:00:42.902  WARN [,70af00327f162fdf,70af00327f162fdf,true] 8112 --- [nio-9014-exec-3] c.a.druid.pool.DruidAbstractDataSource   : discard long time none received connection. , jdbcUrl : jdbc:mysql://192.168.151.202:3307/nomswc_db_1?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC, version : 1.2.8, lastPacketReceivedIdleMillis : 1212220
2021-12-22 11:00:43.136  INFO [,70af00327f162fdf,70af00327f162fdf,true] 8112 --- [nio-9014-exec-3] ShardingSphere-SQL                       : Logic SQL: insert into wc_pendant_tab_extend(mgdb_id, name, keywords, create_time, create_by, update_time, update_by)
        values (?, ?, ?, ?, ?, ?, ?)
2021-12-22 11:00:43.136  INFO [,70af00327f162fdf,70af00327f162fdf,true] 8112 --- [nio-9014-exec-3] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@5339edc4, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@3175358a), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@3175358a, columnNames=[mgdb_id, name, keywords, create_time, create_by, update_time, update_by], insertValueContexts=[InsertValueContext(parametersCount=7, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=123, stopIndex=123, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=126, stopIndex=126, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=129, stopIndex=129, parameterMarkerIndex=2), ParameterMarkerExpressionSegment(startIndex=132, stopIndex=132, parameterMarkerIndex=3), ParameterMarkerExpressionSegment(startIndex=135, stopIndex=135, parameterMarkerIndex=4), ParameterMarkerExpressionSegment(startIndex=138, stopIndex=138, parameterMarkerIndex=5), ParameterMarkerExpressionSegment(startIndex=141, stopIndex=141, parameterMarkerIndex=6), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=7))], parameters=[300004407484, test300004407484, Keywords300004407484, 2021-12-22 11:00:42.657, admin, 2021-12-22 11:00:42.657, admin])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=id, generated=true, generatedValues=[680368298893770752])])
2021-12-22 11:00:43.136  INFO [,70af00327f162fdf,70af00327f162fdf,true] 8112 --- [nio-9014-exec-3] ShardingSphere-SQL                       : Actual SQL: ds1 ::: insert into wc_pendant_tab_extend_1(mgdb_id, name, keywords, create_time, create_by, update_time, update_by, id)
        values (?, ?, ?, ?, ?, ?, ?, ?) ::: [300004407484, test300004407484, Keywords300004407484, 2021-12-22 11:00:42.657, admin, 2021-12-22 11:00:42.657, admin, 680368298893770752]

2. Read verification

a. SQL statement

<select id="queryAllByLimit" resultMap="WcPendantTabDetailMap">
    select
      tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
    from wc_pendant_tab_detail order by tab_id asc
    limit #{offset}, #{limit}
</select>

b. Log printing

It can be seen from the log that the data is read from the library in pieces from the two data sources DS1 slave and DS2 slave.

2021-12-22 11:09:03.652  WARN [,,,] 8112 --- [ngPollService-1] c.c.framework.apollo.util.ConfigUtil     : app.id is not set, please make sure it is set in classpath:/META-INF/app.properties, now apollo will only load public namespace configurations!
2021-12-22 11:09:04.462  INFO [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] ShardingSphere-SQL                       : Logic SQL: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail order by tab_id asc
        limit ?, ?
2021-12-22 11:09:04.462  INFO [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] ShardingSphere-SQL                       : SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@5b549992, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@2ca6de94), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@2ca6de94, projectionsContext=ProjectionsContext(startIndex=17, stopIndex=160, distinctRow=false, projections=[ColumnProjection(owner=null, name=tab_id, alias=Optional.empty), ColumnProjection(owner=null, name=mgdb_id, alias=Optional.empty), ColumnProjection(owner=null, name=period, alias=Optional.empty), ColumnProjection(owner=null, name=tab_type, alias=Optional.empty), ColumnProjection(owner=null, name=is_show, alias=Optional.empty), ColumnProjection(owner=null, name=name, alias=Optional.empty), ColumnProjection(owner=null, name=url, alias=Optional.empty), ColumnProjection(owner=null, name=descripton, alias=Optional.empty), ColumnProjection(owner=null, name=del_falg, alias=Optional.empty), ColumnProjection(owner=null, name=create_time, alias=Optional.empty), ColumnProjection(owner=null, name=create_by, alias=Optional.empty), ColumnProjection(owner=null, name=update_time, alias=Optional.empty), ColumnProjection(owner=null, name=update_by, alias=Optional.empty), ColumnProjection(owner=null, name=app_id, alias=Optional.empty), ColumnProjection(owner=null, name=terminal_id, alias=Optional.empty)]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@22613570, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@265eb5e4, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@635c3f4b, containsSubquery=false)
2021-12-22 11:09:04.462  INFO [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] ShardingSphere-SQL                       : Actual SQL: ds1-salve ::: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail_1 order by tab_id asc
        limit ?, ? ::: [0, 2]
2021-12-22 11:09:04.462  INFO [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] ShardingSphere-SQL                       : Actual SQL: ds1-salve ::: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail_2 order by tab_id asc
        limit ?, ? ::: [0, 2]
2021-12-22 11:09:04.462  INFO [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] ShardingSphere-SQL                       : Actual SQL: ds2-salve ::: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail_1 order by tab_id asc
        limit ?, ? ::: [0, 2]
2021-12-22 11:09:04.462  INFO [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] ShardingSphere-SQL                       : Actual SQL: ds2-salve ::: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail_2 order by tab_id asc
        limit ?, ? ::: [0, 2]
2021-12-22 11:09:04.472  WARN [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] c.a.druid.pool.DruidAbstractDataSource   : discard long time none received connection. , jdbcUrl : jdbc:mysql://192.168.151.202:3308/nomswc_db_1?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC, version : 1.2.8, lastPacketReceivedIdleMillis : 1671641
2021-12-22 11:09:04.481  WARN [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] c.a.druid.pool.DruidAbstractDataSource   : discard long time none received connection. , jdbcUrl : jdbc:mysql://192.168.151.202:3308/nomswc_db_1?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC, version : 1.2.8, lastPacketReceivedIdleMillis : 1713437
2021-12-22 11:09:04.569  WARN [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] c.a.druid.pool.DruidAbstractDataSource   : discard long time none received connection. , jdbcUrl : jdbc:mysql://192.168.151.202:3308/nomswc_db_2?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC, version : 1.2.8, lastPacketReceivedIdleMillis : 1671738
2021-12-22 11:09:04.575  WARN [,a57cdff8de8884d3,a57cdff8de8884d3,true] 8112 --- [nio-9014-exec-5] c.a.druid.pool.DruidAbstractDataSource   : discard long time none received connection. , jdbcUrl : jdbc:mysql://192.168.151.202:3308/nomswc_db_2?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC, version : 1.2.8, lastPacketReceivedIdleMillis : 1713358

3, Force read Master Library

If you need to read the data immediately after writing it (you may not be able to read it), the reason is that Mysql uses asynchronous replication by default, which has a certain delay, and there is no such data in the slave database. At this time, you can force the reading of the master database through Hint.

Shardingsphere JDBC's read-write separation is optimized to avoid the scenario of forced reading of the main library due to synchronization delay. In the same request thread, as long as the database operation is updated first, any access to the database after the operation will be automatically routed to the main database. Therefore, HintManager is not required in the read after write scenario. HintManager can be used only in the read scenario when the primary library needs to be read forcibly.

The following example code demonstrates the use of HintManager to force the reading of the main library. The print log is attached. It can be seen that the data is read from the slice main library of ds1 and ds2 data sources.

@Override
public WcPendantTabDetail testHintManager(){
    // Get distributed primary key
    String tabId = getRedisId();

    // Assembly object
    WcPendantTabDetail wcPendantTabDetail = getWcPendantTabDetail(tabId);
    WcPendantTabExtend wcPendantTabExtend = getWcPendantTabExtend(wcPendantTabDetail);

    // insert data
    wcPendantTabDetailDao.insert(wcPendantTabDetail);
    wcPendantTabExtendDao.insert(wcPendantTabExtend);

    // Force data query from master library
    HintManager.getInstance().setMasterRouteOnly();
    WcPendantTabDetail result = wcPendantTabDetailDao.queryByTabId(tabId);
    return result;
}
2021-12-22 14:38:41.416  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Logic SQL: insert into wc_pendant_tab_detail(tab_id,mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id)
        values (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2021-12-22 14:38:41.416  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@fd54114, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@48a350d6), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@48a350d6, columnNames=[tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id], insertValueContexts=[InsertValueContext(parametersCount=15, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=195, stopIndex=195, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=197, stopIndex=197, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=200, stopIndex=200, parameterMarkerIndex=2), ParameterMarkerExpressionSegment(startIndex=203, stopIndex=203, parameterMarkerIndex=3), ParameterMarkerExpressionSegment(startIndex=206, stopIndex=206, parameterMarkerIndex=4), ParameterMarkerExpressionSegment(startIndex=209, stopIndex=209, parameterMarkerIndex=5), ParameterMarkerExpressionSegment(startIndex=212, stopIndex=212, parameterMarkerIndex=6), ParameterMarkerExpressionSegment(startIndex=215, stopIndex=215, parameterMarkerIndex=7), ParameterMarkerExpressionSegment(startIndex=218, stopIndex=218, parameterMarkerIndex=8), ParameterMarkerExpressionSegment(startIndex=221, stopIndex=221, parameterMarkerIndex=9), ParameterMarkerExpressionSegment(startIndex=224, stopIndex=224, parameterMarkerIndex=10), ParameterMarkerExpressionSegment(startIndex=227, stopIndex=227, parameterMarkerIndex=11), ParameterMarkerExpressionSegment(startIndex=230, stopIndex=230, parameterMarkerIndex=12), ParameterMarkerExpressionSegment(startIndex=233, stopIndex=233, parameterMarkerIndex=13), ParameterMarkerExpressionSegment(startIndex=236, stopIndex=236, parameterMarkerIndex=14)], parameters=[300004407490, 300004407490, 0, ENTERTAINMENT_R_DETAIL, 1, test300004407490, https://assets.alicdn.com/g/tm/login/3.0.2/img/logo.png, Description300004407490, 0, 2021-12-22 14:38:40.111, admin, 2021-12-22 14:38:40.111, admin, 203023, android])], generatedKeyContext=Optional.empty)
2021-12-22 14:38:41.417  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Actual SQL: ds1 ::: insert into wc_pendant_tab_detail_2(tab_id,mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id)
        values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ::: [300004407490, 300004407490, 0, ENTERTAINMENT_R_DETAIL, 1, test300004407490, https://assets.alicdn.com/g/tm/login/3.0.2/img/logo.png, Description300004407490, 0, 2021-12-22 14:38:40.111, admin, 2021-12-22 14:38:40.111, admin, 203023, android]
2021-12-22 14:38:41.566  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Logic SQL: insert into wc_pendant_tab_extend(mgdb_id, name, keywords, create_time, create_by, update_time, update_by)
        values (?, ?, ?, ?, ?, ?, ?)
2021-12-22 14:38:41.566  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@76cc3d5, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@65f08eb7), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@65f08eb7, columnNames=[mgdb_id, name, keywords, create_time, create_by, update_time, update_by], insertValueContexts=[InsertValueContext(parametersCount=7, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=123, stopIndex=123, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=126, stopIndex=126, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=129, stopIndex=129, parameterMarkerIndex=2), ParameterMarkerExpressionSegment(startIndex=132, stopIndex=132, parameterMarkerIndex=3), ParameterMarkerExpressionSegment(startIndex=135, stopIndex=135, parameterMarkerIndex=4), ParameterMarkerExpressionSegment(startIndex=138, stopIndex=138, parameterMarkerIndex=5), ParameterMarkerExpressionSegment(startIndex=141, stopIndex=141, parameterMarkerIndex=6), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=7))], parameters=[300004407490, test300004407490, Keywords300004407490, 2021-12-22 14:38:40.111, admin, 2021-12-22 14:38:40.111, admin])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=id, generated=true, generatedValues=[680423153981194240])])
2021-12-22 14:38:41.803  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Actual SQL: ds1 ::: insert into wc_pendant_tab_extend_2(mgdb_id, name, keywords, create_time, create_by, update_time, update_by, id)
        values (?, ?, ?, ?, ?, ?, ?, ?) ::: [300004407490, test300004407490, Keywords300004407490, 2021-12-22 14:38:40.111, admin, 2021-12-22 14:38:40.111, admin, 680423153981194240]
2021-12-22 14:38:42.124  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Logic SQL: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail where tab_id = ?
2021-12-22 14:38:42.124  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@1d67fb85, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@655800cc), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@655800cc, projectionsContext=ProjectionsContext(startIndex=17, stopIndex=160, distinctRow=false, projections=[ColumnProjection(owner=null, name=tab_id, alias=Optional.empty), ColumnProjection(owner=null, name=mgdb_id, alias=Optional.empty), ColumnProjection(owner=null, name=period, alias=Optional.empty), ColumnProjection(owner=null, name=tab_type, alias=Optional.empty), ColumnProjection(owner=null, name=is_show, alias=Optional.empty), ColumnProjection(owner=null, name=name, alias=Optional.empty), ColumnProjection(owner=null, name=url, alias=Optional.empty), ColumnProjection(owner=null, name=descripton, alias=Optional.empty), ColumnProjection(owner=null, name=del_falg, alias=Optional.empty), ColumnProjection(owner=null, name=create_time, alias=Optional.empty), ColumnProjection(owner=null, name=create_by, alias=Optional.empty), ColumnProjection(owner=null, name=update_time, alias=Optional.empty), ColumnProjection(owner=null, name=update_by, alias=Optional.empty), ColumnProjection(owner=null, name=app_id, alias=Optional.empty), ColumnProjection(owner=null, name=terminal_id, alias=Optional.empty)]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@3beaf7c4, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@b6c1aab, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@29757390, containsSubquery=false)
2021-12-22 14:38:42.124  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Actual SQL: ds1 ::: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail_1 where tab_id = ? ::: [300004407490]
2021-12-22 14:38:42.125  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Actual SQL: ds1 ::: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail_2 where tab_id = ? ::: [300004407490]
2021-12-22 14:38:42.125  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Actual SQL: ds2 ::: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail_1 where tab_id = ? ::: [300004407490]
2021-12-22 14:38:42.125  INFO [,eb9cf006cdcb72d4,eb9cf006cdcb72d4,true] 14076 --- [nio-9014-exec-1] ShardingSphere-SQL                       : Actual SQL: ds2 ::: select
          tab_id, mgdb_id, period, tab_type, is_show, name, url, descripton, del_falg, create_time, create_by, update_time, update_by, app_id, terminal_id
        from wc_pendant_tab_detail_2 where tab_id = ? ::: [300004407490]

4, References

Spring Boot Configuration :: ShardingSphere

ShardingSphere application topic -- 4.1 Version 1 -- sharding JDBC read-write separation + sub database and sub table (VII) _ blog of brushed underpants - CSDN blog

Single library sub table: shardingsphere 4 1.1 sharding JDBC and SpringBoot project integration case (line expression and forced routing fragmentation strategy) _wang7241 blog - CSDN blog _shardingjdbc4.1.1Construction of Mysql master-slave replication based on Docker - CoderFocus - blog Park 

Topics: Java Database MySQL Back-end