-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into remove_duplicate
- Loading branch information
Showing
14 changed files
with
485 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_test") | ||
|
||
go_test( | ||
name = "copr_test_test", | ||
srcs = [ | ||
"coprocessor_test.go", | ||
"main_test.go", | ||
], | ||
deps = [ | ||
"//config", | ||
"//kv", | ||
"//store/copr", | ||
"//store/mockstore", | ||
"//testkit/testmain", | ||
"//testkit/testsetup", | ||
"@com_github_stretchr_testify//require", | ||
"@com_github_tikv_client_go_v2//testutils", | ||
"@com_github_tikv_client_go_v2//tikv", | ||
"@org_uber_go_goleak//:goleak", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2022 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package copr_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/kv" | ||
"github.com/pingcap/tidb/store/copr" | ||
"github.com/pingcap/tidb/store/mockstore" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tikv/client-go/v2/testutils" | ||
) | ||
|
||
func TestBuildCopIteratorWithRowCountHint(t *testing.T) { | ||
// nil --- 'g' --- 'n' --- 't' --- nil | ||
// <- 0 -> <- 1 -> <- 2 -> <- 3 -> | ||
store, err := mockstore.NewMockStore( | ||
mockstore.WithClusterInspector(func(c testutils.Cluster) { | ||
mockstore.BootstrapWithMultiRegions(c, []byte("g"), []byte("n"), []byte("t")) | ||
}), | ||
) | ||
require.NoError(t, err) | ||
defer require.NoError(t, store.Close()) | ||
copClient := store.GetClient().(*copr.CopClient) | ||
ctx := context.Background() | ||
killed := uint32(0) | ||
vars := kv.NewVariables(&killed) | ||
opt := &kv.ClientSendOption{} | ||
|
||
req := &kv.Request{ | ||
Tp: kv.ReqTypeDAG, | ||
KeyRanges: copr.BuildKeyRanges("a", "c", "d", "e", "h", "x", "y", "z"), | ||
FixedRowCountHint: []int{1, 1, 3, copr.CopSmallTaskRow}, | ||
Concurrency: 15, | ||
} | ||
it, errRes := copClient.BuildCopIterator(ctx, req, vars, opt) | ||
require.Nil(t, errRes) | ||
conc, smallConc := it.GetConcurrency() | ||
rateLimit := it.GetSendRate() | ||
require.Equal(t, conc, 1) | ||
require.Equal(t, smallConc, 1) | ||
require.Equal(t, rateLimit.GetCapacity(), 2) | ||
|
||
req = &kv.Request{ | ||
Tp: kv.ReqTypeDAG, | ||
KeyRanges: copr.BuildKeyRanges("a", "c", "d", "e", "h", "x", "y", "z"), | ||
FixedRowCountHint: []int{1, 1, 3, 3}, | ||
Concurrency: 15, | ||
} | ||
it, errRes = copClient.BuildCopIterator(ctx, req, vars, opt) | ||
require.Nil(t, errRes) | ||
conc, smallConc = it.GetConcurrency() | ||
rateLimit = it.GetSendRate() | ||
require.Equal(t, conc, 1) | ||
require.Equal(t, smallConc, 2) | ||
require.Equal(t, rateLimit.GetCapacity(), 3) | ||
|
||
// cross-region long range | ||
req = &kv.Request{ | ||
Tp: kv.ReqTypeDAG, | ||
KeyRanges: copr.BuildKeyRanges("a", "z"), | ||
FixedRowCountHint: []int{10}, | ||
Concurrency: 15, | ||
} | ||
it, errRes = copClient.BuildCopIterator(ctx, req, vars, opt) | ||
require.Nil(t, errRes) | ||
conc, smallConc = it.GetConcurrency() | ||
rateLimit = it.GetSendRate() | ||
require.Equal(t, conc, 1) | ||
require.Equal(t, smallConc, 2) | ||
require.Equal(t, rateLimit.GetCapacity(), 3) | ||
|
||
req = &kv.Request{ | ||
Tp: kv.ReqTypeDAG, | ||
KeyRanges: copr.BuildKeyRanges("a", "z"), | ||
FixedRowCountHint: []int{copr.CopSmallTaskRow + 1}, | ||
Concurrency: 15, | ||
} | ||
it, errRes = copClient.BuildCopIterator(ctx, req, vars, opt) | ||
require.Nil(t, errRes) | ||
conc, smallConc = it.GetConcurrency() | ||
rateLimit = it.GetSendRate() | ||
require.Equal(t, conc, 4) | ||
require.Equal(t, smallConc, 0) | ||
require.Equal(t, rateLimit.GetCapacity(), 4) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2022 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package copr_test | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pingcap/tidb/config" | ||
"github.com/pingcap/tidb/testkit/testmain" | ||
"github.com/pingcap/tidb/testkit/testsetup" | ||
"github.com/tikv/client-go/v2/tikv" | ||
"go.uber.org/goleak" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testmain.ShortCircuitForBench(m) | ||
|
||
testsetup.SetupForCommonTest() | ||
|
||
flag.Parse() | ||
config.UpdateGlobal(func(conf *config.Config) { | ||
conf.TiKVClient.AsyncCommit.SafeWindow = 0 | ||
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0 | ||
}) | ||
tikv.EnableFailpoints() | ||
opts := []goleak.Option{ | ||
// TODO: figure the reason and shorten this list | ||
goleak.IgnoreTopFunction("github.com/golang/glog.(*loggingT).flushDaemon"), | ||
goleak.IgnoreTopFunction("github.com/tikv/client-go/v2/internal/retry.newBackoffFn.func1"), | ||
goleak.IgnoreTopFunction("go.etcd.io/etcd/client/v3.waitRetryBackoff"), | ||
goleak.IgnoreTopFunction("go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop"), | ||
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), | ||
goleak.IgnoreTopFunction("google.golang.org/grpc.(*addrConn).resetTransport"), | ||
goleak.IgnoreTopFunction("google.golang.org/grpc.(*ccBalancerWrapper).watcher"), | ||
goleak.IgnoreTopFunction("google.golang.org/grpc/internal/transport.(*controlBuffer).get"), | ||
goleak.IgnoreTopFunction("google.golang.org/grpc/internal/transport.(*http2Client).keepalive"), | ||
goleak.IgnoreTopFunction("internal/poll.runtime_pollWait"), | ||
goleak.IgnoreTopFunction("net/http.(*persistConn).writeLoop"), | ||
} | ||
callback := func(i int) int { | ||
// wait for MVCCLevelDB to close, MVCCLevelDB will be closed in one second | ||
time.Sleep(time.Second) | ||
return i | ||
} | ||
goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...) | ||
} |
Oops, something went wrong.