-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
executor/admin.go
Outdated
idxResult distsql.SelectResult | ||
|
||
//tblChunk *chunk.Chunk | ||
//tblResult distsql.SelectResult |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ?
executor/admin.go
Outdated
} | ||
|
||
type idxData struct { | ||
matched bool |
There was a problem hiding this comment.
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.
executor/admin.go
Outdated
return nil | ||
} | ||
handleIdx := len(e.idxCols) - 1 | ||
errInTxn := kv.RunInNewTxn(e.ctx.GetStore(), true, func(txn kv.Transaction) error { |
There was a problem hiding this comment.
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.
/run-all-tests |
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
if e.idxChunk.NumRows() == 0 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
LGTM |
/run-all-tests |
/run-integration-common-test |
executor/admin.go
Outdated
} | ||
count := 0 | ||
for { | ||
count++ |
There was a problem hiding this comment.
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.
PTAL @zimulala |
executor/admin.go
Outdated
return nil | ||
} | ||
|
||
func (e *CleanupIndexExec) extractIdxVals(row chunk.Row, idxVals []types.Datum) []types.Datum { |
There was a problem hiding this comment.
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?
executor/admin.go
Outdated
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} |
There was a problem hiding this comment.
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) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
PTAL @zimulala |
executor/builder.go
Outdated
return nil | ||
} | ||
idxName := strings.ToLower(v.IndexName) | ||
indices := t.WritableIndices() |
There was a problem hiding this comment.
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) | ||
} |
There was a problem hiding this comment.
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.
Rest LGTM |
executor/builder.go
Outdated
var index table.Index | ||
for _, idx := range indices { |
There was a problem hiding this comment.
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.
PTAL @zimulala , sorry for the late update. |
executor/builder.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Support
admin cleanup index table_name index_name
to clean up the dangling index.PTAL @zimulala @coocood