Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix data races detected by go test -race #1407

Merged
merged 2 commits into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ func newMemSchemaHandle() (*memSchemaHandle, error) {
if err != nil {
return nil, errors.Trace(err)
}
initMemoryTables(h)
h.perfHandle, err = perfschema.NewPerfHandle()
if err != nil {
return nil, errors.Trace(err)
Expand Down
12 changes: 5 additions & 7 deletions perfschema/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ func (ps *perfSchema) initRecords(tbName string, records [][]types.Datum) error
return nil
}

var setupTimersRecords [][]types.Datum
var setupTimersRecords = [][]types.Datum{
types.MakeDatums("stage", mysql.Enum{Name: "NANOSECOND", Value: 1}),
types.MakeDatums("statement", mysql.Enum{Name: "NANOSECOND", Value: 1}),
types.MakeDatums("transaction", mysql.Enum{Name: "NANOSECOND", Value: 1}),
}

func (ps *perfSchema) initialize() (err error) {
ps.tables = make(map[string]*model.TableInfo)
Expand Down Expand Up @@ -425,12 +429,6 @@ func (ps *perfSchema) initialize() (err error) {
if err != nil {
return errors.Trace(err)
}

setupTimersRecords = [][]types.Datum{
types.MakeDatums("stage", mysql.Enum{Name: "NANOSECOND", Value: 1}),
types.MakeDatums("statement", mysql.Enum{Name: "NANOSECOND", Value: 1}),
types.MakeDatums("transaction", mysql.Enum{Name: "NANOSECOND", Value: 1}),
}
err = ps.initRecords(TableSetupTimers, setupTimersRecords)
if err != nil {
return errors.Trace(err)
Expand Down
6 changes: 5 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ type Server struct {

// ConnectionCount gets current connection count.
func (s *Server) ConnectionCount() int {
return len(s.clients)
var cnt int
s.rwlock.RLock()
cnt = len(s.clients)
s.rwlock.RUnlock()
return cnt
}

func (s *Server) getToken() *Token {
Expand Down
3 changes: 1 addition & 2 deletions server/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type TidbTestSuite struct {
var _ = Suite(new(TidbTestSuite))

func (ts *TidbTestSuite) SetUpSuite(c *C) {
log.SetLevelByString("error")
store, err := tidb.NewStore("memory:///tmp/tidb")
c.Assert(err, IsNil)
ts.tidbdrv = NewTiDBDriver(store)
Expand All @@ -42,8 +43,6 @@ func (ts *TidbTestSuite) SetUpSuite(c *C) {
ts.server = server
go ts.server.Run()
time.Sleep(time.Millisecond * 100)

log.SetLevelByString("error")
}

func (ts *TidbTestSuite) TearDownSuite(c *C) {
Expand Down
2 changes: 0 additions & 2 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sync/atomic"
"time"

"github.com/ngaut/log"
. "github.com/pingcap/check"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/executor"
Expand Down Expand Up @@ -58,7 +57,6 @@ func (s *testSessionSuite) SetUpSuite(c *C) {
s.dropTableSQL = `Drop TABLE if exists t;`
s.createTableSQL = `CREATE TABLE t(id TEXT);`
s.selectSQL = `SELECT * from t;`
log.SetLevelByString("error")
}

func (s *testSessionSuite) TearDownSuite(c *C) {
Expand Down
11 changes: 8 additions & 3 deletions store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ 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 @@ -269,9 +271,11 @@ 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
}
select {
Expand All @@ -282,12 +286,13 @@ func (it *copIterator) Next() (io.ReadCloser, error) {
task.status = taskDone
it.mu.Unlock()
}

it.mu.Lock()
defer it.mu.Unlock()
if err != nil {
it.Close()
return nil, err
}
it.mu.Lock()
defer it.mu.Unlock()
it.respGot++
if it.respGot == len(it.tasks) {
it.Close()
Expand Down
3 changes: 1 addition & 2 deletions tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
var store = flag.String("store", "memory", "registered store name, [memory, goleveldb, boltdb]")

func TestT(t *testing.T) {
log.SetLevelByString("error")
TestingT(t)
}

Expand Down Expand Up @@ -67,8 +68,6 @@ func (s *testMainSuite) SetUpSuite(c *C) {
CREATE TABLE tbl_test2(id INT NOT NULL DEFAULT 3, name varchar(255), PRIMARY KEY(id));`
s.selectSQL = `SELECT * from tbl_test;`
runtime.GOMAXPROCS(runtime.NumCPU())

log.SetLevelByString("error")
}

func (s *testMainSuite) TearDownSuite(c *C) {
Expand Down