Skip to content

Commit

Permalink
ddl: rename batchSize to batchCnt (pingcap#2005)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaut authored and zimulala committed Nov 15, 2016
1 parent 7ddb150 commit bb70acd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (d *ddl) addTableColumn(t table.Table, columnInfo *model.ColumnInfo, reorgI
}

// backfillColumnInTxn deals with a part of backfilling column data in a Transaction.
// This part of the column data rows is defaultSmallBatchSize.
// This part of the column data rows is defaultSmallBatchCnt.
func (d *ddl) backfillColumnInTxn(t table.Table, colID int64, handles []int64, colMap map[int64]*types.FieldType,
defaultVal types.Datum, txn kv.Transaction) (int64, error) {
nextHandle := handles[0]
Expand Down Expand Up @@ -391,8 +391,8 @@ func (d *ddl) backfillColumn(t table.Table, columnInfo *model.ColumnInfo, handle

var endIdx int
for len(handles) > 0 {
if len(handles) >= defaultSmallBatchSize {
endIdx = defaultSmallBatchSize
if len(handles) >= defaultSmallBatchCnt {
endIdx = defaultSmallBatchCnt
} else {
endIdx = len(handles)
}
Expand Down
14 changes: 7 additions & 7 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ func fetchRowColVals(txn kv.Transaction, t table.Table, handle int64, indexInfo
return rowKey, vals, nil
}

const defaultBatchSize = 1024
const defaultSmallBatchSize = 128
const defaultBatchCnt = 1024
const defaultSmallBatchCnt = 128

// How to add index in reorganization state?
// 1. Generate a snapshot with special version.
Expand Down Expand Up @@ -417,7 +417,7 @@ func (d *ddl) getSnapshotRows(t table.Table, version uint64, seekHandle int64) (
}
defer it.Close()

handles := make([]int64, 0, defaultBatchSize)
handles := make([]int64, 0, defaultBatchCnt)
for it.Valid() {
if !it.Key().HasPrefix(t.RecordPrefix()) {
break
Expand All @@ -430,7 +430,7 @@ func (d *ddl) getSnapshotRows(t table.Table, version uint64, seekHandle int64) (
}

handles = append(handles, handle)
if len(handles) == defaultBatchSize {
if len(handles) == defaultBatchCnt {
break
}

Expand All @@ -447,7 +447,7 @@ func (d *ddl) getSnapshotRows(t table.Table, version uint64, seekHandle int64) (
}

// backfillIndexInTxn deals with a part of backfilling index data in a Transaction.
// This part of the index data rows is defaultSmallBatchSize.
// This part of the index data rows is defaultSmallBatchCnt.
func (d *ddl) backfillIndexInTxn(t table.Table, kvIdx table.Index, handles []int64, txn kv.Transaction) (int64, error) {
nextHandle := handles[0]
for _, handle := range handles {
Expand Down Expand Up @@ -489,8 +489,8 @@ func (d *ddl) backfillTableIndex(t table.Table, indexInfo *model.IndexInfo, hand
var endIdx int
kvIdx := tables.NewIndex(t.Meta(), indexInfo)
for len(handles) > 0 {
if len(handles) >= defaultSmallBatchSize {
endIdx = defaultSmallBatchSize
if len(handles) >= defaultSmallBatchCnt {
endIdx = defaultSmallBatchCnt
} else {
endIdx = len(handles)
}
Expand Down
4 changes: 2 additions & 2 deletions ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ func (d *ddl) delKeysWithStartKey(prefix, startKey kv.Key, jobType JobType, job

var count int
total := job.GetRowCount()
keys := make([]kv.Key, 0, defaultBatchSize)
keys := make([]kv.Key, 0, defaultBatchCnt)
for {
if limitedDel && count >= limit {
break
}
batch := defaultBatchSize
batch := defaultBatchCnt
if limitedDel && count+batch > limit {
batch = limit - count
}
Expand Down
4 changes: 2 additions & 2 deletions ddl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ func (d *ddl) dropSchemaData(tIDs []int64, startKey kv.Key, job *model.Job, m *m
if startKey == nil {
startKey = tablecodec.EncodeTablePrefix(id)
}
delCount, err := d.dropTableData(startKey, job, defaultBatchSize)
delCount, err := d.dropTableData(startKey, job, defaultBatchCnt)
if err != nil {
return false, errors.Trace(err)
}

if delCount == defaultBatchSize {
if delCount == defaultBatchCnt {
isFinished = false
nextStartKey = job.Args[len(job.Args)-1].(kv.Key)
break
Expand Down
12 changes: 6 additions & 6 deletions ddl/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ func (s *testSchemaSuite) TestSchema(c *C) {
_, err := tbl1.AddRecord(ctx, types.MakeDatums(i, i, i))
c.Assert(err, IsNil)
}
// create table t1 with defaultBatchSize+10 records.
// create table t1 with defaultBatchCnt+10 records.
tblInfo2 := testTableInfo(c, d, "t1", 3)
tJob2 := testCreateTable(c, ctx, d, dbInfo, tblInfo2)
testCheckTableState(c, d, dbInfo, tblInfo2, model.StatePublic)
testCheckJobDone(c, d, tJob2, true)
tbl2 := testGetTable(c, d, dbInfo.ID, tblInfo2.ID)
for i := 1; i <= defaultBatchSize+10; i++ {
for i := 1; i <= defaultBatchCnt+10; i++ {
_, err := tbl2.AddRecord(ctx, types.MakeDatums(i, i, i))
c.Assert(err, IsNil)
}
Expand All @@ -157,12 +157,12 @@ func (s *testSchemaSuite) TestSchema(c *C) {
job.Mu.Lock()
count := job.RowCount
job.Mu.Unlock()
if updatedCount == 0 && count != defaultBatchSize+100 {
checkErr = errors.Errorf("row count %v isn't equal to %v", count, defaultBatchSize+100)
if updatedCount == 0 && count != defaultBatchCnt+100 {
checkErr = errors.Errorf("row count %v isn't equal to %v", count, defaultBatchCnt+100)
return
}
if updatedCount == 1 && count != defaultBatchSize+110 {
checkErr = errors.Errorf("row count %v isn't equal to %v", count, defaultBatchSize+110)
if updatedCount == 1 && count != defaultBatchCnt+110 {
checkErr = errors.Errorf("row count %v isn't equal to %v", count, defaultBatchCnt+110)
}
updatedCount++
}
Expand Down

0 comments on commit bb70acd

Please sign in to comment.