You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/09 08:59:35 UTC

[GitHub] [shardingsphere] saeipi opened a new issue, #22035: I want to implement sub-database and sub-table at the same time, please teach me how to do it.

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

   I want to implement sub-database and sub-table at the same time, please teach me how to do it.
   In my configuration, read-write separation has no effect.
   
   
   databaseName: lark
   ```
   databaseName: lark
   
   # 数据源,连接真实物理库,注意物理库必须有相应的库存在,否则proxy无法启动。
   dataSources:
     mds_0:
       url: jdbc:mysql://10.0.115.108:13306/lark_chat_msg?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
       username: root
       password: lark2022
       # 连接超时毫秒数
       connectionTimeoutMilliseconds: 30000
       # 空闲连接回收超时毫秒数
       idleTimeoutMilliseconds: 60000
       # 连接最大存活时间毫秒数
       maxLifetimeMilliseconds: 1800000
       # 连接池中最大维持的连接数量
       maxPoolSize: 50
       # 连接池的最小连接数量
       minPoolSize: 1
     mds_1:
       url: jdbc:mysql://10.0.115.108:13307/lark_chat_msg?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
       username: root
       password: lark2022
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
       minPoolSize: 1
     sds_0:
       url: jdbc:mysql://10.0.115.108:13308/lark_chat_msg?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
       username: root
       password: lark2022
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
       minPoolSize: 1
     sds_1:
       url: jdbc:mysql://10.0.115.108:13309/lark_chat_msg?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
       username: root
       password: lark2022
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
       minPoolSize: 1
   
   # 分片策略
   rules:
   # 读写分离规则
   - !READWRITE_SPLITTING
      dataSources:
        wr_ds_0:
          # 负载均衡算法名称
          loadBalancerName: random
          staticStrategy:
            # 写库数据源名称
            writeDataSourceName: mds_0
            # 读库数据源名称,多个从数据源用逗号分隔
            readDataSourceNames:
              - sds_0
        wr_ds_1:
          # 负载均衡算法名称
          loadBalancerName: random
          staticStrategy:
            # 写库数据源名称
            writeDataSourceName: mds_1
            # 读库数据源名称,多个从数据源用逗号分隔
            readDataSourceNames:
              - sds_1
      loadBalancers:
        random:
          # 负载均衡算法,默认为轮询算法,还有加权算法和随机算法 可选值:ROUND_ROBIN,RANDOM
          type: RANDOM
   
   - !SHARDING
     tables:
       # 逻辑表名称
       messages:
         # 由逻辑数据源名 + 表名组成(参考 Inline 语法规则)
         actualDataNodes: mds_${0..1}.messages_${202201..202212}
         #  分库策略,缺省表示使用默认分库策略
         databaseStrategy:
           # standard:用于单分片键的标准分片场景 standard/complex/hint/none
           standard:
             # 分片列名称
             shardingColumn: chat_id
             # 分片算法名称
             shardingAlgorithmName: database-inline
         #  分表策略,同分库策略
         tableStrategy:
           standard:
             shardingColumn: srv_ts
             # 算法名称,具体使用哪一种算法下面会根据算法名称配置
             shardingAlgorithmName: messages-inline
         # 分布式序列策略
         keyGenerateStrategy:
           # 自增列名称,缺省表示不使用自增主键生成器
           column: srv_msg_id
           # 分布式序列算法名称
           keyGeneratorName: snowflake
     # 绑定表规则列表 解决笛卡尔积问题(主从集群,当存在有关联关系表时候,联合查询数据会有重复的问题)
     bindingTables:
      - messages
     # 分布式序列算法配置 主键生成规则配置
     keyGenerators:
       snowflake:
         type: SNOWFLAKE
         props:
           worker-id: 1
     # 分片算法配置,根据上面的算法名称配置算法的类型和算法接收的参数
     shardingAlgorithms:
       database-inline:
         type: INLINE
         props:
           algorithm-expression: mds_${chat_id % 2}
           # 分片如何在 inline 分表策略时,允许执行范围查询操作
           allow-range-query-with-inline-sharding: true
       # messages表分片算法名称
       messages-inline:
         type: INTERVAL
         props:
           # 分片键的时间戳格式
           datetime-pattern: "yyyy-MM-dd HH:mm:ss"
           # 范围下限
           datetime-lower: "2022-01-01 00:00:00"
           # 范围上限
           datetime-upper: "2022-12-01 00:00:00"
           # 分片名后缀,可以是MM,yyyyMMdd等。
           sharding-suffix-pattern: "yyyyMM"
           # 分片键时间间隔,超过该时间间隔将进入下一分片
           datetime-interval-amount: 1
           # 分片键时间间隔单位
           datetime-interval-unit: "MONTHS"
           # 以1个月为单位进行划分
           sharding-seconds: '2678400'
   ```
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] saeipi commented on issue #22035: I want to implement sub-database and sub-table at the same time, please teach me how to do it.

Posted by GitBox <gi...@apache.org>.
saeipi commented on issue #22035:
URL: https://github.com/apache/shardingsphere/issues/22035#issuecomment-1310174134

   > Try using `wr_ds_0`, `wr_ds_1` in Sharding rule.
   
   Thank you. You answered my questions perfectly


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] saeipi closed issue #22035: I want to implement sub-database and sub-table at the same time, please teach me how to do it.

Posted by GitBox <gi...@apache.org>.
saeipi closed issue #22035: I want to implement sub-database and sub-table at the same time, please teach me how to do it.
URL: https://github.com/apache/shardingsphere/issues/22035


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] TeslaCN commented on issue #22035: I want to implement sub-database and sub-table at the same time, please teach me how to do it.

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on issue #22035:
URL: https://github.com/apache/shardingsphere/issues/22035#issuecomment-1309709581

   Try using `wr_ds_0`, `wr_ds_1` in Sharding rule.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] saeipi commented on issue #22035: I want to implement sub-database and sub-table at the same time, please teach me how to do it.

Posted by GitBox <gi...@apache.org>.
saeipi commented on issue #22035:
URL: https://github.com/apache/shardingsphere/issues/22035#issuecomment-1311220741

   Thank you. You answered my questions perfectly


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org