Skip to content

Commit

Permalink
Merge branch 'master' into history_hot_regions_command
Browse files Browse the repository at this point in the history
  • Loading branch information
qidi1 authored Sep 27, 2021
2 parents c8110bb + 455a2f9 commit e7c9945
Show file tree
Hide file tree
Showing 488 changed files with 11,261 additions and 3,016 deletions.
21 changes: 0 additions & 21 deletions .github/auto_assign.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/challenge-bot.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/auto-assignee.yaml

This file was deleted.

14 changes: 7 additions & 7 deletions .github/workflows/pd-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: PD Tests
on:
push:
branches:
Expand All @@ -9,9 +10,6 @@ on:
- master
- release-4.0
- release-5.*

name: PD Tests

jobs:
chunks:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -43,14 +41,16 @@ jobs:
id: packages-units
env:
WORKER_ID: ${{ matrix.worker_id }}
# github.com/tikv/pd/tests/server/tso is the integration test of TSO, which will take a long time,
# will be run independently in the TSO Function Test.
run: |
go list ./... |grep -v -E "github.com/tikv/pd/tests/client|github.com/tikv/pd/server/api" > packages.list
go list ./... | grep -v -E "github.com/tikv/pd/server/api|github.com/tikv/pd/tests/client|github.com/tikv/pd/tests/server/tso" > packages.list
total=$(expr ${{ strategy.job-total }} - 1)
echo "Dispatched ${total} normal chunks"
split packages.list -n r/${total} packages_unit_ -a 1 --numeric-suffixes=1
echo "Dispatched 2 special task to the last chunk(the special test takes a long time)"
echo github.com/tikv/pd/tests/client > packages_unit_${{ strategy.job-total }}
echo github.com/tikv/pd/server/api >> packages_unit_${{ strategy.job-total }}
echo "Dispatched 2 special task to the last chunk (the special tests take a long time)"
echo github.com/tikv/pd/server/api > packages_unit_${{ strategy.job-total }}
echo github.com/tikv/pd/tests/client >> packages_unit_${{ strategy.job-total }}
packages="{$(cat packages_unit_${WORKER_ID} |tr "\n" ",")}"
echo "This worker will test the chunk - ${packages}"
echo "::set-output name=list::${packages}"
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/tso-consistency-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: TSO Consistency Test
on:
# Only run when the new code is merged into master.
push:
branches:
- master
jobs:
tso-consistency-test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Checkout code
uses: actions/checkout@v2
- name: Make TSO Consistency Test
run: make test-tso-consistency
19 changes: 19 additions & 0 deletions .github/workflows/tso-function-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: TSO Function Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
tso-function-test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Checkout code
uses: actions/checkout@v2
- name: Make TSO Function Test
run: make test-tso-function
11 changes: 0 additions & 11 deletions Jenkinsfile

This file was deleted.

34 changes: 31 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ TEST_PKGS := $(shell find . -iname "*_test.go" -exec dirname {} \; | \
sort -u | sed -e "s/^\./github.com\/tikv\/pd/")
INTEGRATION_TEST_PKGS := $(shell find . -iname "*_test.go" -exec dirname {} \; | \
sort -u | sed -e "s/^\./github.com\/tikv\/pd/" | grep -E "tests")
TSO_INTEGRATION_TEST_PKGS := $(shell find . -iname "*_test.go" -exec dirname {} \; | \
sort -u | sed -e "s/^\./github.com\/tikv\/pd/" | grep -E "server/tso")
BASIC_TEST_PKGS := $(filter-out $(INTEGRATION_TEST_PKGS),$(TEST_PKGS))

PACKAGES := go list ./...
Expand Down Expand Up @@ -97,6 +99,10 @@ PD_SERVER_DEP :=
ifneq ($(SWAGGER), 0)
PD_SERVER_DEP += swagger-spec
endif
ifneq ($(DASHBOARD_DISTRIBUTION_DIR),)
BUILD_TAGS += dashboard_distro
PD_SERVER_DEP += dashboard-replace-distro-info
endif
PD_SERVER_DEP += dashboard-ui

pd-server: export GO111MODULE=on
Expand Down Expand Up @@ -125,6 +131,10 @@ dashboard-ui: export GO111MODULE=on
dashboard-ui:
./scripts/embed-dashboard-ui.sh

dashboard-replace-distro-info:
rm -f pkg/dashboard/distro/distro_info.go
cp $(DASHBOARD_DISTRIBUTION_DIR)/distro_info.go pkg/dashboard/distro/distro_info.go

# Tools
pd-ctl: export GO111MODULE=on
pd-ctl:
Expand All @@ -143,20 +153,21 @@ pd-heartbeat-bench:
CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/pd-heartbeat-bench tools/pd-heartbeat-bench/main.go

test: install-go-tools
# testing...
# testing all pkgs...
@$(DEADLOCK_ENABLE)
@$(FAILPOINT_ENABLE)
CGO_ENABLED=1 GO111MODULE=on go test -race -cover $(TEST_PKGS) || { $(FAILPOINT_DISABLE); $(DEADLOCK_DISABLE); exit 1; }
CGO_ENABLED=1 GO111MODULE=on go test -tags tso_function_test -timeout 20m -race -cover $(TEST_PKGS) || { $(FAILPOINT_DISABLE); $(DEADLOCK_DISABLE); exit 1; }
@$(FAILPOINT_DISABLE)
@$(DEADLOCK_DISABLE)

basic-test:
# testing basic pkgs...
@$(FAILPOINT_ENABLE)
GO111MODULE=on go test $(BASIC_TEST_PKGS) || { $(FAILPOINT_DISABLE); exit 1; }
@$(FAILPOINT_DISABLE)

test-with-cover: install-go-tools dashboard-ui
# testing...
# testing all pkgs (expect TSO consistency test) with converage...
@$(FAILPOINT_ENABLE)
for PKG in $(TEST_PKGS); do\
set -euo pipefail;\
Expand All @@ -165,6 +176,22 @@ test-with-cover: install-go-tools dashboard-ui
done
@$(FAILPOINT_DISABLE)

test-tso-function: install-go-tools dashboard-ui
# testing TSO function...
@$(DEADLOCK_ENABLE)
@$(FAILPOINT_ENABLE)
CGO_ENABLED=1 GO111MODULE=on go test -race -tags tso_function_test $(TSO_INTEGRATION_TEST_PKGS) || { $(FAILPOINT_DISABLE); $(DEADLOCK_DISABLE); exit 1; }
@$(FAILPOINT_DISABLE)
@$(DEADLOCK_DISABLE)

test-tso-consistency: install-go-tools dashboard-ui
# testing TSO consistency...
@$(DEADLOCK_ENABLE)
@$(FAILPOINT_ENABLE)
CGO_ENABLED=1 GO111MODULE=on go test -race -tags tso_consistency_test $(TSO_INTEGRATION_TEST_PKGS) || { $(FAILPOINT_DISABLE); $(DEADLOCK_DISABLE); exit 1; }
@$(FAILPOINT_DISABLE)
@$(DEADLOCK_DISABLE)

check: install-go-tools check-all check-plugin errdoc check-testing-t docker-build-test

check-all: static lint tidy
Expand Down Expand Up @@ -220,6 +247,7 @@ clean-test:
rm -rf /tmp/test_pd*
rm -rf /tmp/pd-tests*
rm -rf /tmp/test_etcd*
go clean -testcache

clean-build:
# Cleaning building files...
Expand Down
62 changes: 15 additions & 47 deletions client/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//
// 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.

Expand Down Expand Up @@ -54,10 +55,10 @@ type baseClient struct {

security SecurityOption

gRPCDialOptions []grpc.DialOption
timeout time.Duration
maxRetryTimes int
enableForwarding bool
// BaseClient options.
gRPCDialOptions []grpc.DialOption
timeout time.Duration
maxRetryTimes int
}

// SecurityOption records options about tls
Expand All @@ -67,68 +68,35 @@ type SecurityOption struct {
KeyPath string
}

// ClientOption configures client.
type ClientOption func(c *baseClient)

// WithGRPCDialOptions configures the client with gRPC dial options.
func WithGRPCDialOptions(opts ...grpc.DialOption) ClientOption {
return func(c *baseClient) {
c.gRPCDialOptions = append(c.gRPCDialOptions, opts...)
}
}

// WithCustomTimeoutOption configures the client with timeout option.
func WithCustomTimeoutOption(timeout time.Duration) ClientOption {
return func(c *baseClient) {
c.timeout = timeout
}
}

// WithForwardingOption configures the client with forwarding option.
func WithForwardingOption(enableForwarding bool) ClientOption {
return func(c *baseClient) {
c.enableForwarding = enableForwarding
}
}

// WithMaxErrorRetry configures the client max retry times when connect meets error.
func WithMaxErrorRetry(count int) ClientOption {
return func(c *baseClient) {
c.maxRetryTimes = count
}
}

// newBaseClient returns a new baseClient.
func newBaseClient(ctx context.Context, urls []string, security SecurityOption, opts ...ClientOption) (*baseClient, error) {
ctx1, cancel := context.WithCancel(ctx)
c := &baseClient{
func newBaseClient(ctx context.Context, urls []string, security SecurityOption) *baseClient {
clientCtx, clientCancel := context.WithCancel(ctx)
return &baseClient{
urls: urls,
checkLeaderCh: make(chan struct{}, 1),
checkTSODispatcherCh: make(chan struct{}, 1),
ctx: ctx1,
cancel: cancel,
ctx: clientCtx,
cancel: clientCancel,
security: security,
timeout: defaultPDTimeout,
maxRetryTimes: maxInitClusterRetries,
}
for _, opt := range opts {
opt(c)
}
}

func (c *baseClient) init() error {
if err := c.initRetry(c.initClusterID); err != nil {
c.cancel()
return nil, err
return err
}
if err := c.initRetry(c.updateMember); err != nil {
c.cancel()
return nil, err
return err
}
log.Info("[pd] init cluster id", zap.Uint64("cluster-id", c.clusterID))

c.wg.Add(1)
go c.memberLoop()

return c, nil
return nil
}

func (c *baseClient) initRetry(f func() error) error {
Expand Down
Loading

0 comments on commit e7c9945

Please sign in to comment.