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

executor: support cleanup dangling index data command #6102

Merged
merged 19 commits into from
Apr 2, 2018

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Mar 20, 2018

Support admin cleanup index table_name index_name to clean up the dangling index.
PTAL @zimulala @coocood

@jackysp jackysp added the WIP label Mar 20, 2018
idxResult distsql.SelectResult

//tblChunk *chunk.Chunk
//tblResult distsql.SelectResult
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 remove these comments?

parser/parser.y Outdated
@@ -260,6 +260,7 @@ import (
cascaded "CASCADED"
charsetKwd "CHARSET"
checksum "CHECKSUM"
cleanup "CLEANUP"
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep alignment.

@@ -4782,6 +4783,14 @@ AdminStmt:
Index: string($5),
}
}
| "ADMIN" "CLEANUP" "INDEX" TableName Identifier
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 add tests in parser_test.go ?

}

type idxData struct {
matched bool
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we don't use this field.

return nil
}
handleIdx := len(e.idxCols) - 1
errInTxn := kv.RunInNewTxn(e.ctx.GetStore(), true, func(txn kv.Transaction) error {
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 handle this code in batch? I'm afraid that we need to clean up a lot of data. At the same time, some people also modified the data. Then we need to redo it.

@jackysp jackysp removed the WIP label Mar 23, 2018
@jackysp
Copy link
Member Author

jackysp commented Mar 23, 2018

/run-all-tests

if err != nil {
return errors.Trace(err)
}
if e.idxChunk.NumRows() == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

We should check the e.scanRowCnt to return.

Copy link
Contributor

Choose a reason for hiding this comment

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

friendly ping @jackysp Please resolve reviewer's comment

@jackysp
Copy link
Member Author

jackysp commented Mar 25, 2018

PTAL @coocood @zimulala

@coocood
Copy link
Member

coocood commented Mar 26, 2018

LGTM

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 26, 2018
@zimulala
Copy link
Contributor

/run-all-tests

@jackysp
Copy link
Member Author

jackysp commented Mar 26, 2018

/run-integration-common-test

}
count := 0
for {
count++
Copy link
Contributor

Choose a reason for hiding this comment

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

count doesn't be used.

@jackysp
Copy link
Member Author

jackysp commented Mar 28, 2018

PTAL @zimulala

return nil
}

func (e *CleanupIndexExec) extractIdxVals(row chunk.Row, idxVals []types.Datum) []types.Datum {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function logic is the same as RecoverIndexExec's extractIdxVals. Could we use the same one?

handle := row.GetInt64(len(e.idxCols) - 1)
idxVals := e.extractIdxVals(row, e.idxValsBufs[e.scanRowCnt])
e.idxValsBufs[e.scanRowCnt] = idxVals
e.matchedIndex[handle] = idxData{false, idxVals}
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 remove the field ofmatched ?

err := plan.SetPBColumnsDefaultValue(e.ctx, dagReq.Executors[0].IdxScan.Columns, e.idxCols)
if err != nil {
return nil, errors.Trace(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these codes be extracted into a function?
The logic is used in many places.

Copy link
Member Author

@jackysp jackysp Mar 28, 2018

Choose a reason for hiding this comment

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

They are looked similar, but not exactly the same. It needs a refactor. Maybe in the next pr.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the same as CheckIndexRangeExec's buildDAGPB.
But if you want to refactor some of the exec in admin, you can handle it in the next PR.

@jackysp
Copy link
Member Author

jackysp commented Mar 28, 2018

PTAL @zimulala

return nil
}
idxName := strings.ToLower(v.IndexName)
indices := t.WritableIndices()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it enough if we only handle the public index?

err := plan.SetPBColumnsDefaultValue(e.ctx, dagReq.Executors[0].IdxScan.Columns, e.idxCols)
if err != nil {
return nil, errors.Trace(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's the same as CheckIndexRangeExec's buildDAGPB.
But if you want to refactor some of the exec in admin, you can handle it in the next PR.

@zimulala
Copy link
Contributor

Rest LGTM

var index table.Index
for _, idx := range indices {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indices() isn't equal to public indices.

@jackysp
Copy link
Member Author

jackysp commented Mar 31, 2018

PTAL @zimulala , sorry for the late update.

@@ -321,7 +321,10 @@ func (b *executorBuilder) buildCleanupIndex(v *plan.CleanupIndex) Executor {
}
idxName := strings.ToLower(v.IndexName)
var index table.Index
for _, idx := range t.WritableIndices() {
for _, idx := range t.Indices() {
if idx.Meta().State != model.StatePublic {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think to do this check as line 334 is better.

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.

LGTM

@jackysp jackysp merged commit 39a2f84 into pingcap:master Apr 2, 2018
@jackysp jackysp deleted the recover_table branch May 22, 2018 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants