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

planner,executor,infoschema: add system table table_storage_stats (#15056) #20431

Merged
merged 5 commits into from
Oct 15, 2020

Conversation

ti-srebot
Copy link
Contributor

cherry-pick #15056 to release-4.0


What problem does this PR solve?

we can only get the disk-usage from http API

What is changed and how it works?

  1. This pr could help us by using the table_storage_stats get the usage of a table, if a table is empty or its size < 0, its TABLE_SIZE would return 1MB.
  2. Extract the get PdRegionStats func to helper which used by http API and this sys table.
mysql> select * from table_storage_stats where table_schema = 'test';
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | PEER_COUNT | REGION_COUNT | EMPTY_REGION_COUNT | TABLE_SIZE | TABLE_KEYS |
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
| test         | t          |      143 |          3 |            1 |                  1 |          1 |          0 |
| test         | usertable  |      343 |          3 |           97 |                  0 |       9127 |   16605517 |
| test         | t2         |      348 |          3 |            1 |                  1 |          1 |          0 |
| test         | tcs1       |      360 |          3 |           70 |                  0 |       7087 |   10204927 |
| test         | tcs2       |      362 |          3 |           70 |                  0 |       7141 |    9712408 |
| test         | tcs3       |      364 |          3 |           70 |                  0 |       7174 |    9765219 |
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
6 rows in set (0.35 sec)


mysql> select count(*) from information_schema.TABLE_STORAGE_STATS;
+----------+
| count(*) |
+----------+
|     1249 |
+----------+

mysql> select * from table_storage_stats where table_schema = 'mysql'and table_name = 'tidb';
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | PEER_COUNT | REGION_COUNT | EMPTY_REGION_COUNT | TABLE_SIZE | TABLE_KEYS |
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
| mysql        | tidb       |       17 |          3 |            1 |                  1 |          1 |        134 |
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
1 row in set (0.12 sec)

Check List

Tests

  • Integration test

Release note

  • Add system table table_storage_stats

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor Author

/run-all-tests

Signed-off-by: crazycs520 <crazycs520@gmail.com>
@crazycs520 crazycs520 removed sig/execution SIG execution sig/planner SIG: Planner labels Oct 14, 2020
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

infoschema/tables.go Show resolved Hide resolved
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot
Copy link
Contributor Author

@AilinKid, Thanks for your review, however we are sorry that your vote won't be count.

@github-actions github-actions bot added the sig/execution SIG execution label Oct 14, 2020
Copy link
Contributor

@tangenta tangenta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot
Copy link
Contributor Author

@tangenta, Thanks for your review, however we are sorry that your vote won't be count.

Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot
Copy link
Contributor Author

@djshow832, Thanks for your review, however we are sorry that your vote won't be count.

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 15, 2020
@crazycs520
Copy link
Contributor

/run-all-tests

Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 15, 2020
@SunRunAway
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor Author

Sorry @SunRunAway, this branch cannot be merged without an approval of release maintainers

@Hexilee
Copy link
Contributor

Hexilee commented Oct 15, 2020

/merge

@ti-srebot
Copy link
Contributor Author

Sorry @Hexilee, this branch cannot be merged without an approval of release maintainers

@Hexilee
Copy link
Contributor

Hexilee commented Oct 15, 2020

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 15, 2020
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@SunRunAway
Copy link
Contributor

/merge

@ti-srebot ti-srebot merged commit 06cbfe6 into pingcap:release-4.0 Oct 15, 2020
@SunRunAway SunRunAway deleted the release-4.0-cfbd75465377 branch October 15, 2020 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/infoschema sig/execution SIG execution sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/4.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants