Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes
key, op, and values fields, as shown below:{"key": "key1", "op": "op1", "values": ["value1","value2"]}
key | op | values |
region | "in", "notIn", "exists", "notExists" | region list, such as ["guangzhou"] |
zone | "in", "notIn", "exists", "notExists" | AZ list, such as ["guangzhou-1"] |
rack | "in", "notIn", "exists", "notExists" | rack list, such as ["rack-1","rack-2"] |
host | "in", "notIn", "exists", "notExists" | host list, such as ["host-1","host-2","host-3"] |
node | "in", "notIn" | node list, such as ["node-tdsql3-xxx-001"] |
replica-count | "=" | number of replicas, such as ["3"] |
follower-count | "=" | number of RG followers, such as ["2"] |
learner-count | "=" | number of RG learners, such as ["1"] |
witness-count | "=" | number of RG witnesses, such as ["1"] |
leader-preferences | "=" | RG leader preference. For usage, refer to note 2 |
fault-tolerance-level | "=" | disaster recovery level, such as ["zone"] |
tdsql-storage-type | "in", "notIn", "exists", "notExists" | disk type list, such as ["CLOUD_TCS","CLOUD_BSSD"] |
mc-ctl as an example, and the same result can be achieved using the corresponding HTTP API.distribution-policy-enabled is enabled by default in v18.0.0../mc-ctl schedule set --config_key distribution-policy-enabled --config_value 1
./mc-ctl schedule set --config_key distribution-policy-enabled --config_value 0
./mc-ctl dp create --data'{"policy_name":"$name","constraints":[{"key": "key1", "op": "op1", "values": ["value1","value2"]},...]}'
./mc-ctl dp modify --data'{"policy_id": $id,"policy_name":"$name","constraints":[{"key": "key1", "op": "op1", "values": ["value1","value2"]},...]}'
# Delete by ID./mc-ctl dp delete --distribution_policy_id ${id}# Delete by distribution policy name./mc-ctl dp delete --distribution_policy_name ${policy_name}
# List all created DPs./mc-ctl dp info all# Get a single DP by distribution policy name./mc-ctl dp info single --distribution_policy_name ${policy_name}
CREATE DATABASE db1 USING distribution policy ${policy_name};
CREATE TABLE t1(a INT) USING distribution policy ${policy_name};
CREATE TABLE t1(a INT) PARTITION BY HASH(a) PARTITIONS 4 USING distribution policy ${policy_name};
./mc-ctl dp create --data '{"policy_name": "policy_1", "constraints": [{"key": "replica-count", "op": "=", "values": ["5"]}]}'
./mc-ctl dp create --data '{"policy_name": "policy_2", "constraints": [{"key": "replica-count", "op": "=", "values": ["4"]}, {"key": "learner-count", "op": "=", "values": ["1"]}]}'
./mc-ctl dp create --data '{"policy_name": "policy_3", "constraints": [{"key": "node", "op": "in", "values": ["node-001", "node-002", "node-003"]},{"key": "leader-preferences", "op": "=", "values": ["{\\"key\\": \\"node\\", \\"op\\": \\"in\\", \\"values\\": [\\"node-001\\"]}"]}]}'
./mc-ctl dp create --data '{"policy_name": "policy_4", "constraints": [{"key": "tdsql-storage-type", "op": "in", "values": ["SSD"]}]}'
mc-ctl, minimizing the learning curve for users. The specific usage is as follows:key rule include:REGION, ZONE, RACK, HOST, NODE, REPLICA_COUNT, FOLLOWER_COUNT, LEARNER_COUNT, WITNESS_COUNT, STORAGE_TYPE,FAULT_TOLERANCE_LEVEL, LEADER_PREFERENCESop include:IN, NOT IN, EXISTS, NOT EXISTS # Create a Distribution Policy that requires replicas to be placed in AZ zone1 and AZ zone2 with 2 replicas.CREATE DISTRIBUTION POLICY "policy_1" SET ZONE IN ("zone1", "zone2") AND REPLICA_COUNT = 2;
# Modify the constraint for the Distribution Policy named "policy_1" to: replicas must be placed on disks of type "SSD".ALTER DISTRIBUTION POLICY "policy_1" SET STORAGE_TYPE IN ("SSD");# Rename the DP "old_dp_name" to "new_dp_name"RENAME DISTRIBUTION POLICY "old_dp_name" TO "new_dp_name";
# Delete the DP named "policy_1"DROP DISTRIBUTION POLICY "policy_1";

CREATE DISTRIBUTION POLICY "policy_x" SET PARTITION_METHOD = "RANGE" ANDPARTITION_KEY_TO_TIME_TYPE = "predefined:TO_DAYS" ANDEXPIRE = "1 YEAR" ANDSTART_TIME = "2024-06-11 00:11:22" ANDEND_TIME = "2025-06-11 00:11:22" ANDSTORAGE_TYPE IN ("HDD");
PARTITION_METHOD: indicates the partitioning method supported by partitioned tables associated with the DP. Currently, only RANGE and RANGE COLUMNS are supported.PARTITION_KEY_TO_TIME_TYPE: Only required for RANGE partitioning method, used to convert partition boundary values to time types. The values corresponding to this key are conversion functions. The system provides three predefined conversion functions: TO_DAYS, UNIX_TIMESTAMP, and YEAR. Users can also define custom conversion functions, which must provide calculation formulas for year, month, day, hour, minute, and second, following the format: year/month/day/hour/minute/second:(mathematical formula containing identifier v), where v is the identifier representing the integer value of the partition boundary. For example, setting values to ["year:v/100", "month:v%100"] will treat omitted day/hour/minute/second as zero values for their respective time units.EXPIRE: Partition expiration time, in the format of a positive integer + unit, such as 1 YEAR. Available units include: YEAR, MONTH, DAY, HOUR.START_TIME: Optional, defaults to the start of the partition. If START_TIME is specified, the DP rule is applied after this time.END_TIME: Optional, defaults to the end of the partition. If END_TIME is specified, the DP rule will be rejected from being applied after this time.# Use the predefined functionUNIX_TIMESTAMPto createpolicy_x1CREATE DISTRIBUTION POLICY "policy_x1" SET PARTITION_METHOD = "RANGE" ANDPARTITION_KEY_TO_TIME_TYPE = ("predefined:UNIX_TIMESTAMP") ANDEXPIRE = "1 MONTH" ANDSTORAGE_TYPE IN ("HDD");# Create a RANGE partitioned table and bind to policy_x1CREATE TABLE t_order_1(id bigint NOT NULL,gmt_modified timestamp NOT NULL)PARTITION BY RANGE(unix_timestamp(gmt_modified))(PARTITION p1 VALUES LESS THAN(unix_timestamp('2025-11-11')),PARTITION p2 VALUES LESS THAN(unix_timestamp('2025-12-11'))) USING DISTRIBUTION POLICY policy_x1;
# Use a custom function to createpolicy_x2CREATE DISTRIBUTION POLICY "policy_x2" SET PARTITION_METHOD = "RANGE" ANDPARTITION_KEY_TO_TIME_TYPE = ("year:v/100", "month:v%100") ANDEXPIRE = "1 MONTH" ANDLEADER_PREFERENCES = (ZONE in ("zone1")) ANDSTART_TIME = "2025-12-10 00:00:00";# Create a RANGE partitioned table and bind topolicy_x2CREATE TABLE t_order_2(id bigint NOT NULL,gmt_modified datetime NOT NULL)PARTITION BY RANGE(YEAR(gmt_modified) * 100 + MONTH(gmt_modified))(PARTITION p1 VALUES LESS THAN(202511),PARTITION p2 VALUES LESS THAN(202512),PARTITION p3 VALUES LESS THAN(202601)) USING DISTRIBUTION POLICY policy_x2;
Custom function: year:v/100, month:v%100The partition boundary value v = YEAR(gmt_modified) * 100 + MONTH(gmt_modified)Example calculation:- p1: v=202511 → year=202511/100=2025, month=202511%100=11- p2: v=202512 → year=202512/100=2025, month=202512%100=12- p3: v=202601 → year=202601/100=2026, month=202601%100=1
Partitioning Operations | Boundary Value | Converted Time | Scheduling Trigger Time | Whether Constrained |
p1 | 202511 | 2025-11-01 00:00:00 | 2025-12-01 00:00:00 | Unconstrained |
p2 | 202512 | 2025-12-01 00:00:00 | 2026-01-01 00:00:00 | Unconstrained |
p3 | 202601 | 2026-01-01 00:00:00 | 2026-02-01 00:00:00 | Constrained |
# Createpolicy_x3CREATE DISTRIBUTION POLICY "policy_x3" SET PARTITION_METHOD = "RANGE COLUMNS" ANDEXPIRE = "1 YEAR" ANDNODE NOT IN ("node-tdsql3-x-001") ANDSTART_TIME = "2025-12-10 00:00:00" ANDEND_TIME = "2026-12-10 00:00:00";# Create a RANGE COLUMNS partitioned table and bind topolicy_x3CREATE TABLE t_order_3(id bigint NOT NULL,gmt_modified datetime NOT NULL)PARTITION BY RANGE COLUMNS(gmt_modified)(PARTITION p1 VALUES LESS THAN("2024-12-10 00:00:00"),PARTITION p2 VALUES LESS THAN("2025-12-10 00:00:00"),PARTITION p3 VALUES LESS THAN("2026-12-10 00:00:00"),PARTITION p4 VALUES LESS THAN("2027-12-10 00:00:00")) USING DISTRIBUTION POLICY policy_x3;
Partitioning Operations | Boundary Time | Scheduling Trigger Time | Whether Within the Time Window |
p1 | 2024-12-10 | 2025-12-10 | Earlier than START_TIME |
p2 | 2025-12-10 | 2026-12-10 | Within [START_TIME, END_TIME] |
p3 | 2026-12-10 | 2027-12-10 | Within [START_TIME, END_TIME] |
p4 | 2027-12-10 | 2028-12-10 | Later than END_TIME |
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan