Skip to content

Commit

Permalink
*: Pass make race (pingcap#1521)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored and disksing committed Jul 29, 2016
1 parent 9c2ca4d commit d2b4ad8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ gotest:

race:
rm -rf vendor && ln -s _vendor/vendor vendor
$(GO) test --race -cover $(PACKAGES)
$(GO) test --race $(PACKAGES)
rm -rf vendor

tikv_integration_test:
Expand Down
6 changes: 6 additions & 0 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package ddl

import (
"reflect"
"sync"

"github.com/juju/errors"
. "github.com/pingcap/check"
Expand Down Expand Up @@ -821,6 +822,7 @@ func (s *testColumnSuite) TestDropColumn(c *C) {
c.Assert(err, IsNil)

checkOK := false
var mu sync.Mutex
oldCol := &table.Column{}

tc := &testDDLCallback{}
Expand All @@ -831,7 +833,9 @@ func (s *testColumnSuite) TestDropColumn(c *C) {
t := testGetTable(c, d, s.dbInfo.ID, tblInfo.ID).(*tables.Table)
col := table.FindCol(t.Columns, colName)
if col == nil {
mu.Lock()
checkOK = true
mu.Unlock()
return
}
oldCol = col
Expand All @@ -847,7 +851,9 @@ func (s *testColumnSuite) TestDropColumn(c *C) {

job := testDropColumn(c, ctx, s.d, s.dbInfo, tblInfo, colName, false)
testCheckJobDone(c, d, job, false)
mu.Lock()
c.Assert(checkOK, IsTrue)
mu.Unlock()

_, err = ctx.GetTxn(true)
c.Assert(err, IsNil)
Expand Down
4 changes: 3 additions & 1 deletion executor/new_executor_xapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ func (e *NewXSelectIndexExec) Close() error {
e.result = nil
e.subResult = nil
e.taskCursor = 0
e.mu.Lock()
e.tasks = nil
e.mu.Unlock()
e.indexOrder = make(map[int64]int)
return nil
}
Expand Down Expand Up @@ -270,8 +272,8 @@ func (e *NewXSelectIndexExec) runTableTasks(n int) {
func (e *NewXSelectIndexExec) pickAndExecTask() {
for {
// Pick a new task.
e.mu.Lock()
var task *lookupTableTask
e.mu.Lock()
for _, t := range e.tasks {
if t.status == taskNew {
task = t
Expand Down
5 changes: 4 additions & 1 deletion privilege/privileges/privileges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ type testPrivilegeSuite struct {
createColumnPrivTableSQL string
}

func (s *testPrivilegeSuite) SetUpTest(c *C) {
func (s *testPrivilegeSuite) SetUpSuit(c *C) {
log.SetLevelByString("error")
}

func (s *testPrivilegeSuite) SetUpTest(c *C) {
s.dbName = "test"
s.store = newStore(c, s.dbName)
se := newSession(c, s.store, s.dbName)
Expand Down
17 changes: 12 additions & 5 deletions store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ func (c *CopClient) Send(req *kv.Request) kv.Response {
}
it.errChan = make(chan error, 1)
if len(it.tasks) == 0 {
it.mu.Lock()
it.Close()
it.mu.Unlock()
}
it.run()
return it
Expand Down Expand Up @@ -275,10 +273,10 @@ func (it *copIterator) Next() (io.ReadCloser, error) {
break
}
}
it.mu.Unlock()
if task == nil {
it.Close()
}
it.mu.Unlock()
if task == nil {
return nil, nil
}
Expand All @@ -294,19 +292,26 @@ func (it *copIterator) Next() (io.ReadCloser, error) {
it.mu.Lock()
defer it.mu.Unlock()
if err != nil {
it.Close()
it.finished = true
return nil, errors.Trace(err)
}
it.respGot++
if it.respGot == len(it.tasks) {
it.Close()
it.finished = true
}
return ioutil.NopCloser(bytes.NewBuffer(resp.Data)), nil
}

// Handle single copTask.
func (it *copIterator) handleTask(bo *Backoffer, task *copTask) (*coprocessor.Response, error) {
for {
it.mu.RLock()
if it.finished {
it.mu.RUnlock()
return nil, nil
}
it.mu.RUnlock()

req := &coprocessor.Request{
Context: task.region.GetContext(),
Tp: proto.Int64(it.req.Tp),
Expand Down Expand Up @@ -394,7 +399,9 @@ func (it *copIterator) rebuildCurrentTask(bo *Backoffer, task *copTask) error {
}

func (it *copIterator) Close() error {
it.mu.Lock()
it.finished = true
it.mu.Unlock()
return nil
}

Expand Down
9 changes: 5 additions & 4 deletions store/tikv/txn_committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,12 @@ func (c *txnCommitter) cleanupKeys(bo *Backoffer, keys [][]byte) error {
func (c *txnCommitter) Commit() error {
defer func() {
// Always clean up all written keys if the txn does not commit.
if !c.committed {
c.mu.RLock()
writtenKeys := c.writtenKeys
committed := c.committed
c.mu.RUnlock()
if !committed {
go func() {
c.mu.RLock()
writtenKeys := c.writtenKeys
c.mu.RUnlock()
c.cleanupKeys(NewBackoffer(cleanupMaxBackoff), writtenKeys)
log.Infof("txn clean up done, tid: %d", c.startTS)
}()
Expand Down

0 comments on commit d2b4ad8

Please sign in to comment.