Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShardingSphere-Proxy be sharded by month #32914

Open
Vain-vayne opened this issue Sep 18, 2024 · 3 comments
Open

ShardingSphere-Proxy be sharded by month #32914

Vain-vayne opened this issue Sep 18, 2024 · 3 comments

Comments

@Vain-vayne
Copy link

Vain-vayne commented Sep 18, 2024

Can ShardingSphere-Proxy be sharded by month?

  • Version number: 5.5.0
  • How to handle monthly database sharding? For example, 202301 and 202401 are both in the ds_01.test database. How to configure? The following configuration shows an error after inserting data: org.apache.shardingsphere.sharding.exception.algorithm.NoShardingDatabaseRouteInfoException: No sharding database route info.
shardingAlgorithms:
shardingalgorithms_interval:
type: INTERVAL
props:
datetime-pattern: "yyyyMM"
datetime-lower: "202301"
sharding-suffix-pattern: "MM"
datetime-interval-amount: 1
datetime-interval-unit: "MONTHS"
@terrymanu
Copy link
Member

Can you polish the title? The meaning of this title is not clear.

@Vain-vayne
Copy link
Author

Vain-vayne commented Sep 19, 2024

  • ShardingSphere-Proxy configuration file
databaseName: log
dataSources:
  ds_01:
    ...
  ds_02:
  ...
rules:
- !SHARDING
  tables:
    log_test:
      actualDataNodes: ds_${01..12}.log_test
      databaseStrategy:
        standard:
          shardingColumn: tran_month
          shardingAlgorithmName: shardingalgorithms_interval
      tableStrategy:
        none:
...
  shardingAlgorithms:
    shardingalgorithms_interval:
      type: INTERVAL
      props:
        datetime-pattern: "yyyyMM"
        datetime-lower: "202401"
        sharding-suffix-pattern: "MM"
        datetime-interval-amount: 1
        datetime-interval-unit: "MONTHS"
...
  • SQL
INSERT INTO `log_test` (`TRAN_SN`, `TRAN_MONTH`, `TRAN_DATE`, `TRAN_TIME`) VALUES ('111111111','202401', '2024-01-10', '2024-01-10 11:26:08');
  • Error after executing SQL statement
org.apache.shardingsphere.sharding.exception.algorithm.NoShardingDatabaseRouteInfoException: No sharding database route info.
  • The configuration file must be changed to the following configuration to insert successfully

databaseName: log

dataSources:
  ds_202401:
    ...
  ds_202402:
  ...
rules:
- !SHARDING
  tables:
    log_acct_five_vld:
      actualDataNodes: ds_${202401..202412}.log_test
      databaseStrategy:
        standard:
          shardingColumn: tran_month
          shardingAlgorithmName: shardingalgorithms_interval
      tableStrategy:
        none:
...
  shardingAlgorithms:
    shardingalgorithms_interval:
      type: INTERVAL
      props:
        datetime-pattern: "yyyyMM"
        datetime-lower: "202401"
        sharding-suffix-pattern: "yyyyMM"
        datetime-interval-amount: 1
        datetime-interval-unit: "MONTHS"
...
  • sharding-suffix-pattern needs to use MM, not yyyyMM
  • I want to shard by month instead of year-month. How can I modify the configuration file?

@lazyboyl
Copy link

You can use the sharding jdbc composite sharding algorithm to implement it, then package it in a jar file and place it in the ext lib directory of the proxy. You can refer to the example of this repository: https://github.com/lazyboyl/shardingsphere-spring-boot-starter-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants