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

*: tidy code && prealloc some slice for performance #13468

Merged
merged 11 commits into from
Jan 2, 2020
2 changes: 1 addition & 1 deletion ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3818,7 +3818,7 @@ func (s *testDBSuite2) TestTablesLockDelayClean(c *C) {
tk.Se.Close()
wg.Done()
}()
time.Sleep(50)
time.Sleep(50 * time.Nanosecond)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.Sleep(50) is puzzled, we should add the unit.

checkTableLock(c, tk.Se, "test", "t1", model.TableLockWrite)
wg.Wait()
c.Assert(time.Since(startTime).Seconds() > 0.1, IsTrue)
Expand Down
6 changes: 3 additions & 3 deletions ddl/util/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
"go.etcd.io/etcd/integration"
"go.etcd.io/etcd/mvcc/mvccpb"
goctx "golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func TestT(t *testing.T) {
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestSyncerSimple(t *testing.T) {
}

func isTimeoutError(err error) bool {
if terror.ErrorEqual(err, goctx.DeadlineExceeded) || grpc.Code(errors.Cause(err)) == codes.DeadlineExceeded ||
if terror.ErrorEqual(err, goctx.DeadlineExceeded) || status.Code(errors.Cause(err)) == codes.DeadlineExceeded ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code returns the error code for err if it was produced by the rpc system. Otherwise, it returns codes.Unknown.
Deprecated: use status.Code instead.

https://godoc.org/google.golang.org/grpc#Code

terror.ErrorEqual(err, etcdserver.ErrTimeout) {
return true
}
Expand All @@ -250,7 +250,7 @@ func checkRespKV(t *testing.T, kvCount int, key, val string,
if string(kv.Key) != key {
t.Fatalf("key resp %s, exported %s", kv.Key, key)
}
if val != val {
if string(kv.Value) != val {
t.Fatalf("val resp %s, exported %s", kv.Value, val)
}
}
1 change: 1 addition & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ func (s *testSuite2) TestAdminCheckPartitionTableFailed(c *C) {
_, err = indexOpr.Create(s.ctx, txn, types.MakeDatums(i), int64(i))
c.Assert(err, IsNil)
err = txn.Commit(context.Background())
c.Assert(err, IsNil)
tk.MustExec("admin check table admin_test_p")
}

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
1 change: 1 addition & 0 deletions statistics/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ func getOverlapFraction(fb Feedback, bkt bucket) (float64, float64) {
// mergeFullyContainedFeedback merges the max fraction of non-overlapped feedbacks that are fully contained in the bucket.
func (b *BucketFeedback) mergeFullyContainedFeedback(sc *stmtctx.StatementContext, bkt bucket) (float64, float64, bool) {
var feedbacks []Feedback
feedbacks = make([]Feedback, 0, len(b.feedback))
xiekeyi98 marked this conversation as resolved.
Show resolved Hide resolved
// Get all the fully contained feedbacks.
for _, fb := range b.feedback {
res, err := outOfRange(sc, bkt.Lower, bkt.Upper, fb.Lower)
Expand Down
1 change: 1 addition & 0 deletions util/rowDecoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func SubstituteGenColsInDecodeColMap(decodeColMap map[int64]Column) {
colOffset int
}
var orderedCols []Pair
orderedCols = make([]Pair, 0, len(decodeColMap))
xiekeyi98 marked this conversation as resolved.
Show resolved Hide resolved
for colID, col := range decodeColMap {
orderedCols = append(orderedCols, Pair{colID, col.Col.Offset})
}
Expand Down
5 changes: 3 additions & 2 deletions util/testkit/ctestkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ func (tk *CTestKit) ConcurrentRun(c *check.C, concurrent int, loops int,

// PermInt returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n).
func (tk *CTestKit) PermInt(n int) []interface{} {
var v []interface{}
for _, i := range rand.Perm(n) {
randPermSlice := rand.Perm(n)
v := make([]interface{}, 0, len(randPermSlice))
for _, i := range randPermSlice {
v = append(v, i)
}
return v
Expand Down