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

*: support 'admin show ddl jobs <number>' grammar #7028

Merged
merged 7 commits into from
Jul 12, 2018

Conversation

crazycs520
Copy link
Contributor

What have you changed? (mandatory)

issue#7025
add "admin show ddl jobs [number]" grammar support.
this is use to support parallel ddl test in schrodinger-test
eg:

mysql root@127.0.0.1:(none)> admin show ddl jobs
+--------+---------+--------------------------------------+--------------+--------------+-----------+----------+-----------+-----------------------------------+--------+
| JOB_ID | DB_NAME | TABLE_NAME                           | JOB_TYPE     | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | START_TIME                        | STATE  |
+--------+---------+--------------------------------------+--------------+--------------+-----------+----------+-----------+-----------------------------------+--------+
| 545    | test    | d5ea4e33-4fe2-46ae-accb-82610ea1e0b1 | add index    | public       | 1         | 489      | 0         | 2018-07-10 20:07:04.144 +0800 CST | synced |
| 544    | test    | a9ce39c0-f856-4ac0-9c80-78e32ac44481 | create table | public       | 1         | 543      | 0         | 2018-07-10 20:07:04.067 +0800 CST | synced |
| 542    | test    | 0284e4b1-56e9-43c1-bcf5-0a82126fbaee | drop column  | none         | 1         | 517      | 0         | 2018-07-10 20:07:03.366 +0800 CST | synced |
| 541    | test    | f94383a9-bd1c-4a1e-bd1f-ec44af3e3c1e | add column   | public       | 1         | 474      | 0         | 2018-07-10 20:07:03.195 +0800 CST | synced |
| 540    | test    | 0284e4b1-56e9-43c1-bcf5-0a82126fbaee | drop index   | none         | 1         | 517      | 0         | 2018-07-10 20:07:03.139 +0800 CST | synced |
| 539    | test    | afe54691-648f-4574-a05a-f706b368e07b | add index    | public       | 1         | 496      | 1         | 2018-07-10 20:07:02.621 +0800 CST | synced |
| 538    | test    | f94383a9-bd1c-4a1e-bd1f-ec44af3e3c1e | add column   | public       | 1         | 474      | 0         | 2018-07-10 20:07:02.506 +0800 CST | synced |
| 537    | test    | f94383a9-bd1c-4a1e-bd1f-ec44af3e3c1e | add column   | public       | 1         | 474      | 0         | 2018-07-10 20:07:02.032 +0800 CST | synced |
| 536    | test    | f94383a9-bd1c-4a1e-bd1f-ec44af3e3c1e | add index    | public       | 1         | 474      | 0         | 2018-07-10 20:07:01.86 +0800 CST  | synced |
| 535    | test    | d5ea4e33-4fe2-46ae-accb-82610ea1e0b1 | drop index   | none         | 1         | 489      | 0         | 2018-07-10 20:07:01.694 +0800 CST | synced |
+--------+---------+--------------------------------------+--------------+--------------+-----------+----------+-----------+-----------------------------------+--------+
10 rows in set
Time: 0.079s
mysql root@127.0.0.1:(none)> admin show ddl jobs 20
+--------+---------+--------------------------------------+--------------+--------------+-----------+----------+-----------+-----------------------------------+--------+
| JOB_ID | DB_NAME | TABLE_NAME                           | JOB_TYPE     | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | START_TIME                        | STATE  |
+--------+---------+--------------------------------------+--------------+--------------+-----------+----------+-----------+-----------------------------------+--------+
| 545    | test    | d5ea4e33-4fe2-46ae-accb-82610ea1e0b1 | add index    | public       | 1         | 489      | 0         | 2018-07-10 20:07:04.144 +0800 CST | synced |
| 544    | test    | a9ce39c0-f856-4ac0-9c80-78e32ac44481 | create table | public       | 1         | 543      | 0         | 2018-07-10 20:07:04.067 +0800 CST | synced |
| 542    | test    | 0284e4b1-56e9-43c1-bcf5-0a82126fbaee | drop column  | none         | 1         | 517      | 0         | 2018-07-10 20:07:03.366 +0800 CST | synced |
| 541    | test    | f94383a9-bd1c-4a1e-bd1f-ec44af3e3c1e | add column   | public       | 1         | 474      | 0         | 2018-07-10 20:07:03.195 +0800 CST | synced |
| 540    | test    | 0284e4b1-56e9-43c1-bcf5-0a82126fbaee | drop index   | none         | 1         | 517      | 0         | 2018-07-10 20:07:03.139 +0800 CST | synced |
| 539    | test    | afe54691-648f-4574-a05a-f706b368e07b | add index    | public       | 1         | 496      | 1         | 2018-07-10 20:07:02.621 +0800 CST | synced |
| 538    | test    | f94383a9-bd1c-4a1e-bd1f-ec44af3e3c1e | add column   | public       | 1         | 474      | 0         | 2018-07-10 20:07:02.506 +0800 CST | synced |
| 537    | test    | f94383a9-bd1c-4a1e-bd1f-ec44af3e3c1e | add column   | public       | 1         | 474      | 0         | 2018-07-10 20:07:02.032 +0800 CST | synced |
| 536    | test    | f94383a9-bd1c-4a1e-bd1f-ec44af3e3c1e | add index    | public       | 1         | 474      | 0         | 2018-07-10 20:07:01.86 +0800 CST  | synced |
| 535    | test    | d5ea4e33-4fe2-46ae-accb-82610ea1e0b1 | drop index   | none         | 1         | 489      | 0         | 2018-07-10 20:07:01.694 +0800 CST | synced |
| 534    | test    |                                      | drop table   | none         | 1         | 502      | 0         | 2018-07-10 20:07:01.673 +0800 CST | synced |
| 533    | test    | d5ea4e33-4fe2-46ae-accb-82610ea1e0b1 | add index    | public       | 1         | 489      | 3         | 2018-07-10 20:07:01.312 +0800 CST | synced |
| 532    | test    | afe54691-648f-4574-a05a-f706b368e07b | add column   | public       | 1         | 496      | 0         | 2018-07-10 20:07:01.311 +0800 CST | synced |
| 531    | test    | d5ea4e33-4fe2-46ae-accb-82610ea1e0b1 | drop column  | none         | 1         | 489      | 0         | 2018-07-10 20:07:00.873 +0800 CST | synced |
| 530    | test    | afe54691-648f-4574-a05a-f706b368e07b | add column   | public       | 1         | 496      | 0         | 2018-07-10 20:07:00.872 +0800 CST | synced |
| 529    | test    |                                      | add index    | public       | 1         | 502      | 1         | 2018-07-10 20:07:00.419 +0800 CST | synced |
| 528    | test    | 0284e4b1-56e9-43c1-bcf5-0a82126fbaee | add column   | public       | 1         | 517      | 0         | 2018-07-10 20:07:00.417 +0800 CST | synced |
| 527    | test    | 0284e4b1-56e9-43c1-bcf5-0a82126fbaee | add column   | public       | 1         | 517      | 0         | 2018-07-10 20:06:59.972 +0800 CST | synced |
| 526    | test    | 0284e4b1-56e9-43c1-bcf5-0a82126fbaee | add index    | public       | 1         | 517      | 0         | 2018-07-10 20:06:59.97 +0800 CST  | synced |
| 525    | test    |                                      | add column   | public       | 1         | 502      | 0         | 2018-07-10 20:06:59.719 +0800 CST | synced |
+--------+---------+--------------------------------------+--------------+--------------+-----------+----------+-----------+-----------------------------------+--------+
20 rows in set
Time: 0.064s
mysql root@127.0.0.1:(none)>

What are the type of the changes (mandatory)?

  • New feature (non-breaking change which adds functionality)

How has this PR been tested (mandatory)?

unit test

@@ -247,7 +248,7 @@ func (e *ShowDDLJobQueriesExec) Open(ctx context.Context) error {
return errors.Trace(err)
}
// TODO: need to return the job that the user needs.
historyJobs, err := admin.GetHistoryDDLJobs(e.ctx.Txn())
historyJobs, err := admin.GetHistoryDDLJobs(e.ctx.Txn(), 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we define 10 as a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

err = r.Next(ctx, chk)
c.Assert(err, IsNil)
row = chk.GetRow(0)
c.Assert(row.Len(), Equals, 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is its value 10 is not 20?

Copy link
Member

Choose a reason for hiding this comment

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

I think it the first-row length.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ye~

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check the number of jobs in the result?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The number of jobs in the result cannot be ensured, it is related to the actual DDL jobs.

@@ -137,18 +137,21 @@ func GetDDLJobs(txn kv.Transaction) ([]*model.Job, error) {
// MaxHistoryJobs is exported for testing.
const MaxHistoryJobs = 10

// DefHistoryJobs is default value of the default number of history job
const DefHistoryJobs = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

s/DefHistoryJobs/DefHistoryJobsNum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


historyJobs, err := admin.GetHistoryDDLJobs(e.ctx.Txn())
if e.jobNumber == 0 {
e.jobNumber = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

s/ 10/ admin/DefHistoryJobs?

@@ -413,6 +413,7 @@ func (s *testParserSuite) TestDMLStmt(c *C) {
// for admin
{"admin show ddl;", true},
{"admin show ddl jobs;", true},
{"admin show ddl jobs 20;", true},
Copy link
Contributor

Choose a reason for hiding this comment

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

add test for
admin show ddl jobs -1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -247,7 +248,7 @@ func (e *ShowDDLJobQueriesExec) Open(ctx context.Context) error {
return errors.Trace(err)
}
// TODO: need to return the job that the user needs.
Copy link
Member

Choose a reason for hiding this comment

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

this todo can be removed?

@@ -137,18 +137,21 @@ func GetDDLJobs(txn kv.Transaction) ([]*model.Job, error) {
// MaxHistoryJobs is exported for testing.
const MaxHistoryJobs = 10

// DefHistoryJobsNum is default value of the default number of history job
const DefHistoryJobsNum = 10
Copy link
Member

Choose a reason for hiding this comment

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

how about s/DefHistoryJobsNum/DefNumHistoryJobs/ ?

// The maximum count of history jobs is MaxHistoryJobs.
func GetHistoryDDLJobs(txn kv.Transaction) ([]*model.Job, error) {
// The maximum count of history jobs is num.
func GetHistoryDDLJobs(txn kv.Transaction, num int) ([]*model.Job, error) {
Copy link
Member

Choose a reason for hiding this comment

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

how about s/num/maxNumJobs/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@zz-jason
Copy link
Member

LGTM

@zz-jason zz-jason added type/enhancement The issue or PR belongs to an enhancement. status/LGT1 Indicates that a PR has LGTM 1. labels Jul 12, 2018
@zz-jason
Copy link
Member

@zimulala @jackysp @XuHuaiyu PTAL

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 12, 2018
@zz-jason
Copy link
Member

/run-all-tests

@zz-jason zz-jason merged commit 4616636 into pingcap:master Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants