Skip to content

Commit

Permalink
Improve for_select_default_busy (pingcap#169)
Browse files Browse the repository at this point in the history
* fix for_select_default_busy
  • Loading branch information
sylzd authored Oct 21, 2020
1 parent a999e35 commit b91c706
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions dumpling/v4/export/writer_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,19 @@ func WriteInsert(pCtx context.Context, tblIR TableDataIR, w storage.Writer, file
bf.WriteString(";\n")
}
if bf.Len() >= lengthLimit {
wp.input <- bf
bf = pool.Get().(*bytes.Buffer)
if bfCap := bf.Cap(); bfCap < lengthLimit {
bf.Grow(lengthLimit - bfCap)
select {
case <-pCtx.Done():
return pCtx.Err()
case err := <-wp.errCh:
return err
case wp.input <- bf:
bf = pool.Get().(*bytes.Buffer)
if bfCap := bf.Cap(); bfCap < lengthLimit {
bf.Grow(lengthLimit - bfCap)
}
}
}

select {
case <-pCtx.Done():
return pCtx.Err()
case err := <-wp.errCh:
return err
default:
}

if shouldSwitch {
break
}
Expand Down Expand Up @@ -288,21 +286,20 @@ func WriteInsertInCsv(pCtx context.Context, tblIR TableDataIR, w storage.Writer,

bf.WriteByte('\n')
if bf.Len() >= lengthLimit {
wp.input <- bf
bf = pool.Get().(*bytes.Buffer)
if bfCap := bf.Cap(); bfCap < lengthLimit {
bf.Grow(lengthLimit - bfCap)
select {
case <-pCtx.Done():
return pCtx.Err()
case err := <-wp.errCh:
return err
case wp.input <- bf:
bf = pool.Get().(*bytes.Buffer)
if bfCap := bf.Cap(); bfCap < lengthLimit {
bf.Grow(lengthLimit - bfCap)
}
}
}

fileRowIter.Next()
select {
case <-pCtx.Done():
return pCtx.Err()
case err := <-wp.errCh:
return err
default:
}
if wp.ShouldSwitchFile() {
break
}
Expand Down

0 comments on commit b91c706

Please sign in to comment.