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

ddl: Unify drop table index and tiny clean up #823

Merged
merged 2 commits into from
Jan 7, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 2 additions & 50 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ func (d *ddl) getSnapshotRows(t table.Table, version uint64, seekHandle int64) (

handles = append(handles, handle)
if len(handles) == maxBatchSize {
seekHandle = handle + 1
break
}

Expand Down Expand Up @@ -476,54 +475,7 @@ func (d *ddl) backfillTableIndex(t table.Table, indexInfo *model.IndexInfo, hand

func (d *ddl) dropTableIndex(t table.Table, indexInfo *model.IndexInfo) error {
prefix := kv.GenIndexPrefix(t.IndexPrefix(), indexInfo.ID)
for {
keys := make([]kv.Key, 0, maxBatchSize)
err := kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error {
iter, err := txn.Seek(prefix)
if err != nil {
return errors.Trace(err)
}

defer iter.Close()
for i := 0; i < maxBatchSize; i++ {
if iter.Valid() && iter.Key().HasPrefix(prefix) {
keys = append(keys, iter.Key().Clone())
err = iter.Next()
if err != nil {
return errors.Trace(err)
}
} else {
break
}
}

return nil
})

// if err or delete no keys, return.
if err != nil || len(keys) == 0 {
return errors.Trace(err)
}

// delete index key one by one
for _, key := range keys {
err = kv.RunInNewTxn(d.store, true, func(txn kv.Transaction) error {
if err1 := d.isReorgRunnable(txn); err1 != nil {
return errors.Trace(err1)
}

err1 := txn.Delete(key)
// if key doesn't exist, skip this error.
if err1 != nil && !terror.ErrorEqual(err1, kv.ErrNotExist) {
return errors.Trace(err1)
}
err := d.delKeysWithPrefix(prefix)

return nil
})

if err != nil {
return errors.Trace(err)
}
}
}
return errors.Trace(err)
}
9 changes: 3 additions & 6 deletions ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (d *ddl) delKeysWithPrefix(prefix kv.Key) error {
for _, key := range keys {
err := txn.Delete(key)
// must skip ErrNotExist
// if key doesn't exist, skip this error.
if err != nil && !terror.ErrorEqual(err, kv.ErrNotExist) {
return errors.Trace(err)
}
Expand All @@ -190,14 +191,10 @@ func (d *ddl) delKeysWithPrefix(prefix kv.Key) error {
return nil
})

if err != nil {
// if err or delete no keys, returns.
if err != nil || len(keys) == 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 keep check err and value separately, like old code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it.

return errors.Trace(err)
}

// delete no keys, return.
if len(keys) == 0 {
return nil
}
}
}

Expand Down