暫無描述

config-sharding.yaml 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. ######################################################################################################
  18. #
  19. # Here you can configure the rules for the proxy.
  20. # This example is configuration of sharding rule.
  21. #
  22. ######################################################################################################
  23. databaseName: data-center_db
  24. dataSources:
  25. ds_0:
  26. url: jdbc:mysql://localhost:3306/data-center_0?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
  27. username: root
  28. password: root
  29. connectionTimeoutMilliseconds: 30000
  30. idleTimeoutMilliseconds: 60000
  31. maxLifetimeMilliseconds: 1800000
  32. maxPoolSize: 50
  33. minPoolSize: 1
  34. ds_1:
  35. url: jdbc:mysql://localhost:3306/data-center_1?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
  36. username: root
  37. password: root
  38. connectionTimeoutMilliseconds: 30000
  39. idleTimeoutMilliseconds: 60000
  40. maxLifetimeMilliseconds: 1800000
  41. maxPoolSize: 50
  42. minPoolSize: 1
  43. rules:
  44. - !SHARDING
  45. tables: # 数据分片规则配置
  46. t_order: # 订单逻辑表名称
  47. actualDataNodes: ds_${0..1}.t_order_${0..1}
  48. databaseStrategy: # 配置分库策略
  49. standard:
  50. shardingColumn: user_id
  51. shardingAlgorithmName: database_user_inline
  52. tableStrategy: # 分表策略
  53. standard:
  54. shardingColumn: order_id
  55. shardingAlgorithmName: t_order_inline
  56. keyGenerateStrategy:
  57. column: order_id
  58. keyGeneratorName: snowflake
  59. # auditStrategy:
  60. # auditorNames:
  61. # - sharding_key_required_auditor
  62. # allowHintDisable: true
  63. t_order_item: # 子订单逻辑表名称
  64. actualDataNodes: ds_${0..1}.t_order_item_${0..1}
  65. databaseStrategy: # 配置分库策略
  66. standard:
  67. shardingColumn: user_id
  68. shardingAlgorithmName: database_user_inline
  69. tableStrategy: # 分表策略
  70. standard:
  71. shardingColumn: order_id
  72. shardingAlgorithmName: t_order_item_inline
  73. keyGenerateStrategy:
  74. column: order_item_id
  75. keyGeneratorName: snowflake
  76. bindingTables: # 绑定表规则列表
  77. - t_order,t_order_item
  78. # defaultDatabaseStrategy:
  79. # standard:
  80. # shardingColumn: user_id
  81. # shardingAlgorithmName: database_user_inline
  82. # defaultTableStrategy:
  83. # none:
  84. # defaultAuditStrategy:
  85. # auditorNames:
  86. # - sharding_key_required_auditor
  87. # allowHintDisable: true
  88. # 分片算法配置
  89. shardingAlgorithms:
  90. database_user_inline:
  91. type: INLINE
  92. props:
  93. algorithm-expression: ds_${user_id % 2}
  94. t_order_inline: # 订单表分片算法名称
  95. type: INLINE
  96. props:
  97. algorithm-expression: t_order_${order_id % 2}
  98. allow-range-query-with-inline-sharding: true
  99. t_order_item_inline: # 子订单表分片算法名称
  100. type: INLINE
  101. props:
  102. algorithm-expression: t_order_item_${order_id % 2}
  103. allow-range-query-with-inline-sharding: true
  104. # 分布式序列算法配置
  105. keyGenerators:
  106. snowflake:
  107. type: SNOWFLAKE
  108. props:
  109. worker-id: 1
  110. # auditors:
  111. # sharding_key_required_auditor:
  112. # type: DML_SHARDING_CONDITIONS
  113. # - !BROADCAST
  114. # tables:
  115. # - t_address