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

Merged
merged 74 commits into from
Jun 2, 2020
Merged

planner,executor,infoschema: add system table table_storage_stats #15056

merged 74 commits into from
Jun 2, 2020

Conversation

reafans
Copy link
Contributor

@reafans reafans commented Mar 2, 2020

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 * from information_schema.table_storage_stats where table_schema = 'test' and table_name='t';
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | PEER_COUNT | REGION_COUNT | EMPTY_REGION_COUNT | TABLE_SIZE | TABLE_KEYS |
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
| test         | t          | 441      | 3          | 1            | 1                  | 1          | 0          |
+--------------+------------+----------+------------+--------------+--------------------+------------+------------+
1 row in set

Check List

Tests

  • Integration test

Release note

  • Add system table table_storage_stats

@reafans reafans requested a review from a team as a code owner March 2, 2020 02:46
@ghost ghost requested review from alivxxx and lzmhhh123 and removed request for a team March 2, 2020 02:46
@codecov
Copy link

codecov bot commented Mar 2, 2020

Codecov Report

Merging #15056 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #15056   +/-   ##
===========================================
  Coverage   79.6451%   79.6451%           
===========================================
  Files           520        520           
  Lines        141308     141308           
===========================================
  Hits         112545     112545           
  Misses        19773      19773           
  Partials       8990       8990           

@zz-jason zz-jason changed the title infoschema: add disk_usage sys table planner,executor,infoschema: add system table disk_usage Mar 2, 2020
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.

No test cases?

executor/infoschema_reader.go Outdated Show resolved Hide resolved
executor/infoschema_reader.go Outdated Show resolved Hide resolved
executor/infoschema_reader.go Outdated Show resolved Hide resolved
executor/infoschema_reader.go Outdated Show resolved Hide resolved
executor/infoschema_reader.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added the sig/sql-infra SIG: SQL Infra label Mar 8, 2020
@breezewish
Copy link
Member

Maybe we should integrate it with INFORMATION_SCHEMA.TABLES as much as possible, to be compatible with different kind of MySQL tools.

@reafans reafans changed the title planner,executor,infoschema: add system table disk_usage planner,executor,infoschema: add system table table_storage_stats Mar 9, 2020
@reafans reafans requested a review from a team as a code owner March 10, 2020 13:16
@ghost ghost requested review from wshwsh12 and XuHuaiyu and removed request for a team March 10, 2020 13:16
@reafans
Copy link
Contributor Author

reafans commented Mar 10, 2020

/run-all-tests

@reafans
Copy link
Contributor Author

reafans commented Mar 10, 2020

/run-unit-test


// Extract the tables to the initialTable.
for _, db := range databases {
// The user didn't specified the table, extract all tables of this db to initialTable.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/db/DB

}
}

// Cache the helper and return an error if pd unavailable.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/pd/PD

rows := make([][]types.Datum, 0, 1024)
count := 0
for e.curTable < len(e.initialTables) && count < 1024 {
table := (e.initialTables)[e.curTable]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
table := (e.initialTables)[e.curTable]
table := e.initialTables[e.curTable]

Copy link
Contributor

@zimulala zimulala 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

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,
Please address comment.

@crazycs520
Copy link
Contributor

/run-all-tests

crazycs520
crazycs520 previously approved these changes Jun 1, 2020
@crazycs520
Copy link
Contributor

/run-all-tests

Signed-off-by: crazycs <crazycs520@gmail.com>
@crazycs520
Copy link
Contributor

/run-all-tests

@crazycs520 crazycs520 merged commit cfbd754 into pingcap:master Jun 2, 2020
@reafans reafans deleted the add_disk_usage_tb branch June 3, 2020 02:25
@crazycs520
Copy link
Contributor

/run-cherry-picker

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Oct 13, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #20431

ti-srebot added a commit that referenced this pull request Oct 15, 2020
…15056) (#20431)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants