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

drop/truncate partition will not remove partition placement rule after GC #44116

Closed
lcwangchao opened this issue May 23, 2023 · 0 comments · Fixed by #44129
Closed

drop/truncate partition will not remove partition placement rule after GC #44116

lcwangchao opened this issue May 23, 2023 · 0 comments · Fixed by #44129

Comments

@lcwangchao
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create placement policy p1 followers=1;

CREATE TABLE tp1 (
    id INT NOT NULL
) PLACEMENT POLICY p1 PARTITION BY RANGE (id) (
    PARTITION p0 VALUES LESS THAN (10),
    PARTITION p1 VALUES LESS THAN (100)
);

After creating the partition table, its placement rule in PD is:

[
  {
    "group_id": "pd",
    "group_index": 0,
    "group_override": false,
    "rules": [
      {
        "group_id": "pd",
        "id": "default",
        "start_key": "",
        "end_key": "",
        "role": "voter",
        "is_witness": false,
        "count": 1
      }
    ]
  },
  {
    "group_id": "TiDB_DDL_249",
    "group_index": 40,
    "group_override": true,
    "rules": [
      {
        "group_id": "TiDB_DDL_249",
        "id": "table_rule_249_0",
        "index": 40,
        "start_key": "7480000000000000fff900000000000000f8",
        "end_key": "7480000000000000fffa00000000000000f8",
        "role": "voter",
        "is_witness": false,
        "count": 2,
        "label_constraints": [
          {
            "key": "engine",
            "op": "notIn",
            "values": [
              "tiflash"
            ]
          }
        ],
        "create_timestamp": 1684838930
      },
      {
        "group_id": "TiDB_DDL_249",
        "id": "partition_rule_250_0",
        "index": 80,
        "start_key": "7480000000000000fffa00000000000000f8",
        "end_key": "7480000000000000fffb00000000000000f8",
        "role": "voter",
        "is_witness": false,
        "count": 2,
        "label_constraints": [
          {
            "key": "engine",
            "op": "notIn",
            "values": [
              "tiflash"
            ]
          }
        ],
        "create_timestamp": 1684838930
      },
      {
        "group_id": "TiDB_DDL_249",
        "id": "partition_rule_251_0",
        "index": 80,
        "start_key": "7480000000000000fffb00000000000000f8",
        "end_key": "7480000000000000fffc00000000000000f8",
        "role": "voter",
        "is_witness": false,
        "count": 2,
        "label_constraints": [
          {
            "key": "engine",
            "op": "notIn",
            "values": [
              "tiflash"
            ]
          }
        ],
        "create_timestamp": 1684838930
      }
    ]
  },
  {
    "group_id": "tiflash",
    "group_index": 120,
    "group_override": false,
    "rules": null
  }
]

We can see in group TiDB_DDL_249 we have two rules for partitions with rule id partition_rule_250_0 and partition_rule_251_0

Then

alter table tp1 drop partition p1;

We can see the rules are unchanged, partition_rule_251_0 still exists after DDL. However, after the dropped partition table GC, the rule still exists.

After we execute:

alter table tp1 add partition (PARTITION p1 VALUES LESS THAN (100));

The placement rule changes to:

[
  {
    "group_id": "pd",
    "group_index": 0,
    "group_override": false,
    "rules": [
      {
        "group_id": "pd",
        "id": "default",
        "start_key": "",
        "end_key": "",
        "role": "voter",
        "is_witness": false,
        "count": 1
      }
    ]
  },
  {
    "group_id": "TiDB_DDL_249",
    "group_index": 40,
    "group_override": true,
    "rules": [
      {
        "group_id": "TiDB_DDL_249",
        "id": "table_rule_249_0",
        "index": 40,
        "start_key": "7480000000000000fff900000000000000f8",
        "end_key": "7480000000000000fffa00000000000000f8",
        "role": "voter",
        "is_witness": false,
        "count": 2,
        "label_constraints": [
          {
            "key": "engine",
            "op": "notIn",
            "values": [
              "tiflash"
            ]
          }
        ],
        "version": 1,
        "create_timestamp": 1684838930
      },
      {
        "group_id": "TiDB_DDL_249",
        "id": "partition_rule_250_0",
        "index": 80,
        "start_key": "7480000000000000fffa00000000000000f8",
        "end_key": "7480000000000000fffb00000000000000f8",
        "role": "voter",
        "is_witness": false,
        "count": 2,
        "label_constraints": [
          {
            "key": "engine",
            "op": "notIn",
            "values": [
              "tiflash"
            ]
          }
        ],
        "version": 1,
        "create_timestamp": 1684838930
      },
      {
        "group_id": "TiDB_DDL_249",
        "id": "partition_rule_254_0",
        "index": 80,
        "start_key": "7480000000000000fffe00000000000000f8",
        "end_key": "7480000000000000ffff00000000000000f8",
        "role": "voter",
        "is_witness": false,
        "count": 2,
        "label_constraints": [
          {
            "key": "engine",
            "op": "notIn",
            "values": [
              "tiflash"
            ]
          }
        ],
        "create_timestamp": 1684839285
      }
    ]
  },
  {
    "group_id": "tiflash",
    "group_index": 120,
    "group_override": false,
    "rules": null
  }
]

partition_rule_251_0 is deleted and partition_rule_254_0 created. However, if we execute the above add partition DDL before old dropped partition GC, partition_rule_251_0 will still be deleted without waiting for GC.

2. What did you expect to see? (Required)

  1. After drop/truncate a partition, the old placement rule should exist, but it should be deleted after GC.
  2. After add a new partition or other DDL, the old placement rule should still exist until GC.

3. What did you see instead (Required)

  1. The dropped partition's placement rule will not be deleted after GC.
  2. After add a new partition, the old placement rule will be deleted by mistake without waiting for GC

4. What is your TiDB version? (Required)

master

ti-chi-bot bot pushed a commit that referenced this issue May 24, 2023
ti-chi-bot bot pushed a commit that referenced this issue May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant