Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into optimize-heartbeat/…
Browse files Browse the repository at this point in the history
…async_2
  • Loading branch information
nolouch committed Apr 16, 2024
2 parents ef1bc25 + 22543a9 commit 3007e31
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/schedule/checker/checker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

// DefaultCacheSize is the default length of waiting list.
const DefaultCacheSize = 1000
const DefaultCacheSize = 100000

var denyCheckersByLabelerCounter = labeler.LabelerEventCounter.WithLabelValues("checkers", "deny")

Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/etcdutil/etcdutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,10 @@ func checkEtcdWithHangLeader(t *testing.T) error {
etcd2 := MustAddEtcdMember(t, &cfg1, client1)
defer etcd2.Close()
checkMembers(re, client1, []*embed.Etcd{etcd1, etcd2})
time.Sleep(1 * time.Second) // wait for etcd client sync endpoints

// Hang the etcd1 and wait for the client to connect to etcd2.
enableDiscard.Store(true)
time.Sleep(time.Second)
time.Sleep(3 * time.Second)
_, err = EtcdKVGet(client1, "test/key1")
return err
}
Expand Down Expand Up @@ -366,7 +365,8 @@ func ioCopy(ctx context.Context, dst io.Writer, src io.Reader, enableDiscard *at
return nil
default:
if enableDiscard.Load() {
io.Copy(io.Discard, src)
_, err := io.Copy(io.Discard, src)
return err
}
readNum, errRead := src.Read(buffer)
if readNum > 0 {
Expand Down
33 changes: 21 additions & 12 deletions pkg/utils/etcdutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,27 @@ func MustAddEtcdMember(t *testing.T, cfg1 *embed.Config, client *clientv3.Client

func checkMembers(re *require.Assertions, client *clientv3.Client, etcds []*embed.Etcd) {
// Check the client can get the new member.
listResp, err := ListEtcdMembers(client.Ctx(), client)
re.NoError(err)
re.Len(listResp.Members, len(etcds))
inList := func(m *etcdserverpb.Member) bool {
for _, etcd := range etcds {
if m.ID == uint64(etcd.Server.ID()) {
return true
testutil.Eventually(re, func() bool {
listResp, err := ListEtcdMembers(client.Ctx(), client)
if err != nil {
return false
}
if len(etcds) != len(listResp.Members) {
return false
}
inList := func(m *etcdserverpb.Member) bool {
for _, etcd := range etcds {
if m.ID == uint64(etcd.Server.ID()) {
return true
}
}
return false
}
return false
}
for _, m := range listResp.Members {
re.True(inList(m))
}
for _, m := range listResp.Members {
if !inList(m) {
return false
}
}
return true
})
}
9 changes: 5 additions & 4 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3480,10 +3480,11 @@ func TestStoreOverloadedWithReplace(t *testing.T) {
re.False(oc.AddOperator(op3))
ops, _ := lb.Schedule(tc, false /* dryRun */)
re.Empty(ops)
// sleep 2 seconds to make sure that token is filled up
time.Sleep(2 * time.Second)
ops, _ = lb.Schedule(tc, false /* dryRun */)
re.NotEmpty(ops)
// make sure that token is filled up
testutil.Eventually(re, func() bool {
ops, _ = lb.Schedule(tc, false /* dryRun */)
return len(ops) != 0
})
}

func TestDownStoreLimit(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/mcs/scheduling/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,11 @@ func (suite *apiTestSuite) checkStores(cluster *tests.TestCluster) {
Version: "2.0.0",
},
}
// prevent the offline store from changing to tombstone
tests.MustPutRegion(re, cluster, 3, 6, []byte("a"), []byte("b"))
for _, store := range stores {
tests.MustPutStore(re, cluster, store)
}
// prevent the offline store from changing to tombstone
tests.MustPutRegion(re, cluster, 3, 6, []byte("a"), []byte("b"))
// Test /stores
apiServerAddr := cluster.GetLeaderServer().GetAddr()
urlPrefix := fmt.Sprintf("%s/pd/api/v1/stores", apiServerAddr)
Expand Down
2 changes: 1 addition & 1 deletion tests/server/tso/global_tso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestLogicalOverflow(t *testing.T) {
re.NoError(err)
if i == 1 {
// the 2nd request may (but not must) overflow, as max logical interval is 262144
re.Less(time.Since(begin), updateInterval+20*time.Millisecond) // additional 20ms for gRPC latency
re.Less(time.Since(begin), updateInterval+50*time.Millisecond) // additional 50ms for gRPC latency
}
}
// the 3rd request must overflow
Expand Down
20 changes: 20 additions & 0 deletions tools/pd-ut/go-compile-without-link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# See https://gist.github.com/howardjohn/c0f5d0bc293ef7d7fada533a2c9ffaf4
# Usage: go test -exec=true -toolexec=go-compile-without-link -vet=off ./...
# Preferably as an alias like `alias go-test-compile='go test -exec=true -toolexec=go-compile-without-link -vet=off'`
# This will compile all tests, but not link them (which is the least cacheable part)

if [[ "${2}" == "-V=full" ]]; then
"$@"
exit 0
fi
case "$(basename ${1})" in
link)
# Output a dummy file
touch "${3}"
;;
# We could skip vet as well, but it can be done with -vet=off if desired
*)
"$@"
esac
20 changes: 20 additions & 0 deletions tools/pd-ut/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,28 @@ func skipDIR(pkg string) bool {
return false
}

func generateBuildCache() error {
// cd cmd/pd-server && go test -tags=tso_function_test,deadlock -exec-=true -vet=off -toolexec=go-compile-without-link
cmd := exec.Command("go", "test", "-exec=true", "-vet", "off", "--tags=tso_function_test,deadlock")
goCompileWithoutLink := fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh", workDir)
cmd.Args = append(cmd.Args, goCompileWithoutLink)
cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return withTrace(err)
}
return nil
}

// buildTestBinaryMulti is much faster than build the test packages one by one.
func buildTestBinaryMulti(pkgs []string) error {
// staged build, generate the build cache for all the tests first, then generate the test binary.
// This way is faster than generating test binaries directly, because the cache can be used.
if err := generateBuildCache(); err != nil {
return withTrace(err)
}

// go test --exec=xprog --tags=tso_function_test,deadlock -vet=off --count=0 $(pkgs)
xprogPath := path.Join(workDir, "bin/xprog")
packages := make([]string, 0, len(pkgs))
Expand Down

0 comments on commit 3007e31

Please sign in to comment.