Skip to content

Commit

Permalink
ddl: add statistical log (pingcap#1719)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored Sep 13, 2016
1 parent 2d6e0e3 commit 4c9f291
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ func (d *ddl) onDropColumn(t *meta.Meta, job *model.Job) error {
func (d *ddl) backfillColumn(t table.Table, columnInfo *model.ColumnInfo, reorgInfo *reorgInfo) error {
seekHandle := reorgInfo.Handle
version := reorgInfo.SnapshotVer
count := 0

for {
handles, err := d.getSnapshotRows(t, version, seekHandle)
Expand All @@ -318,11 +319,13 @@ func (d *ddl) backfillColumn(t table.Table, columnInfo *model.ColumnInfo, reorgI
if err != nil {
return errors.Trace(err)
}

count += len(handles)
log.Infof("[ddl] added column for %v rows", count)
}
}

func (d *ddl) backfillColumnData(t table.Table, columnInfo *model.ColumnInfo, handles []int64, reorgInfo *reorgInfo) error {
log.Infof("[ddl] backfill column handles %v", len(handles))
var (
defaultVal types.Datum
err error
Expand Down
7 changes: 5 additions & 2 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ const maxBatchSize = 1024
func (d *ddl) addTableIndex(t table.Table, indexInfo *model.IndexInfo, reorgInfo *reorgInfo) error {
seekHandle := reorgInfo.Handle
version := reorgInfo.SnapshotVer
count := 0

for {
handles, err := d.getSnapshotRows(t, version, seekHandle)
if err != nil {
Expand All @@ -356,11 +358,13 @@ func (d *ddl) addTableIndex(t table.Table, indexInfo *model.IndexInfo, reorgInfo
}

seekHandle = handles[len(handles)-1] + 1

err = d.backfillTableIndex(t, indexInfo, handles, reorgInfo)
if err != nil {
return errors.Trace(err)
}

count += len(handles)
log.Infof("[ddl] added index for %v rows", count)
}
}

Expand Down Expand Up @@ -409,7 +413,6 @@ func (d *ddl) getSnapshotRows(t table.Table, version uint64, seekHandle int64) (

func (d *ddl) backfillTableIndex(t table.Table, indexInfo *model.IndexInfo, handles []int64, reorgInfo *reorgInfo) error {
kvX := tables.NewIndex(t.Meta(), indexInfo)
log.Infof("[ddl] backfill index %v rows ", len(handles))

for _, handle := range handles {
log.Debug("[ddl] backfill index...", handle)
Expand Down
5 changes: 4 additions & 1 deletion ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func (d *ddl) isReorgRunnable(txn kv.Transaction, flag JobType) error {
}

func (d *ddl) delKeysWithPrefix(prefix kv.Key, jobType JobType) error {
count := 0

for {
keys := make([]kv.Key, 0, maxBatchSize)
err := kv.RunInNewTxn(d.store, true, func(txn kv.Transaction) error {
Expand All @@ -191,7 +193,6 @@ func (d *ddl) delKeysWithPrefix(prefix kv.Key, jobType JobType) error {
}
}

log.Infof("[ddl] delete %v keys with prefix %q", len(keys), prefix)
for _, key := range keys {
err := txn.Delete(key)
// must skip ErrNotExist
Expand All @@ -201,13 +202,15 @@ func (d *ddl) delKeysWithPrefix(prefix kv.Key, jobType JobType) error {
}
}

count += len(keys)
return nil
})

if err != nil {
return errors.Trace(err)
}

log.Infof("[ddl] deleted %v keys with prefix %q", count, prefix)
// delete no keys, return.
if len(keys) == 0 {
return nil
Expand Down

0 comments on commit 4c9f291

Please sign in to comment.