Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
mydump: dynamic batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
lonng committed Jan 9, 2019
1 parent 92e8dad commit 7f0d002
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion lightning/mydump/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ func MakeTableRegions(meta *MDTableMeta, columns int, batchSize int64) ([]*Table
// Split files into regions
filesRegions := make(regionSlice, 0, len(meta.DataFiles))

// import() step will not be concurrent.
// If multiple Batch end times are close, it will result in multiple
// Batch import serials. `batchSizeScale` used to implement dynamic
// batch size: curBatchSize = batchSize / int64(batchSizeScale-curEngineID)
const batchSizeScale = 20

prevRowIDMax := int64(0)
curEngineID := 0
curEngineSize := int64(0)
curBatchSize := batchSize / batchSizeScale
for _, dataFile := range meta.DataFiles {
dataFileInfo, err := os.Stat(dataFile)
if err != nil {
Expand All @@ -75,9 +82,14 @@ func MakeTableRegions(meta *MDTableMeta, columns int, batchSize int64) ([]*Table
prevRowIDMax = rowIDMax

curEngineSize += dataFileSize
if curEngineSize > batchSize {
if curEngineSize > curBatchSize {
curEngineSize = 0
curEngineID++
if curEngineID < batchSizeScale {
curBatchSize = batchSize / int64(batchSizeScale-curEngineID)
} else {
curBatchSize = batchSize
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/checkpoint_engines/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ run_lightning
# Check that we have indeed opened 4 engines
OPEN_ENGINES_COUNT=$(grep 'open engine' "$TEST_DIR/lightning-checkpoint-engines.log" | wc -l)
echo "Number of open engines: $OPEN_ENGINES_COUNT"
[ "$OPEN_ENGINES_COUNT" -eq 4 ]
[ "$OPEN_ENGINES_COUNT" -eq 5 ]

# Check that everything is correctly imported
run_sql 'SELECT count(*), sum(c) FROM cpeng.a'
Expand All @@ -29,7 +29,7 @@ run_sql 'DROP DATABASE cpeng;'

export GOFAIL_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/restore/SlowDownImport=sleep(500);github.com/pingcap/tidb-lightning/lightning/restore/FailIfStatusBecomes=return(120)'
set +e
for i in $(seq 4); do
for i in $(seq 5); do
echo "******** Importing Table Now (step $i/4) ********"
run_lightning 2> /dev/null
[ $? -ne 0 ] || exit 1
Expand All @@ -52,7 +52,7 @@ check_contains 'sum(c): 46'
run_sql 'DROP DATABASE cpeng;'

set +e
for i in $(seq 4); do
for i in $(seq 5); do
echo "******** Importing Table Now (step $i/4) ********"
run_lightning mysql 2> /dev/null
[ $? -ne 0 ] || exit 1
Expand Down

0 comments on commit 7f0d002

Please sign in to comment.