Skip to content

Commit

Permalink
Merge branch 'master' into refine_progress_test
Browse files Browse the repository at this point in the history
  • Loading branch information
HuSharp authored Apr 11, 2024
2 parents f6616a3 + 7e18a69 commit 4590464
Show file tree
Hide file tree
Showing 301 changed files with 2,363 additions and 1,325 deletions.
147 changes: 147 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ linters:
- bodyclose
- testifylint
- gofmt
- revive
disable:
- errcheck
linters-settings:
Expand Down Expand Up @@ -52,3 +53,149 @@ linters-settings:
rewrite-rules:
- pattern: "interface{}"
replacement: "any"
revive:
ignore-generated-header: false
severity: error
confidence: 0.8
rules:
- name: atomic
severity: warning
exclude: [""]
disabled: false
- name: blank-imports
severity: warning
exclude: [""]
disabled: false
- name: confusing-naming
severity: warning
disabled: false
exclude: [""]
- name: confusing-results
severity: warning
disabled: false
exclude: [""]
- name: context-as-argument
severity: warning
disabled: false
exclude: [""]
arguments:
- allowTypesBefore: "*testing.T,*github.com/user/repo/testing.Harness"
- name: datarace
severity: warning
disabled: false
exclude: [""]
- name: defer
severity: warning
disabled: false
exclude: [""]
arguments:
- ["call-chain", "loop"]
- name: dot-imports
severity: warning
disabled: false
exclude: [""]
- name: duplicated-imports
severity: warning
disabled: false
exclude: [""]
- name: empty-block
severity: warning
disabled: false
exclude: [""]
- name: empty-lines
severity: warning
disabled: false
exclude: [""]
- name: error-return
severity: warning
disabled: false
exclude: [""]
- name: error-strings
severity: warning
disabled: false
exclude: [""]
- name: error-naming
severity: warning
disabled: false
exclude: [""]
- name: exported
severity: warning
disabled: false
exclude: [""]
arguments:
- "checkPrivateReceivers"
- "sayRepetitiveInsteadOfStutters"
- name: identical-branches
severity: warning
disabled: false
exclude: [""]
- name: if-return
severity: warning
disabled: false
exclude: [""]
- name: modifies-parameter
severity: warning
disabled: false
exclude: [""]
- name: optimize-operands-order
severity: warning
disabled: false
exclude: [""]
- name: package-comments
severity: warning
disabled: false
exclude: [""]
- name: range
severity: warning
disabled: false
exclude: [""]
- name: range-val-in-closure
severity: warning
disabled: false
exclude: [""]
- name: range-val-address
severity: warning
disabled: false
exclude: [""]
- name: receiver-naming
severity: warning
disabled: false
exclude: [""]
- name: indent-error-flow
severity: warning
disabled: false
exclude: [""]
- name: superfluous-else
severity: warning
disabled: false
exclude: [""]
- name: unnecessary-stmt
severity: warning
disabled: false
exclude: [""]
- name: unreachable-code
severity: warning
disabled: false
exclude: [""]
- name: unused-parameter
severity: warning
disabled: false
exclude: [""]
arguments:
- allowRegex: "^_"
- name: unused-receiver
severity: warning
disabled: false
exclude: [""]
- name: useless-break
severity: warning
disabled: false
exclude: [""]
- name: var-naming
severity: warning
disabled: false
exclude: [""]
- name: waitgroup-by-value
severity: warning
disabled: false
exclude: [""]
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ BUILD_BIN_PATH := $(ROOT_PATH)/bin

build: pd-server pd-ctl pd-recover

tools: pd-tso-bench pd-heartbeat-bench regions-dump stores-dump pd-api-bench
tools: pd-tso-bench pd-heartbeat-bench regions-dump stores-dump pd-api-bench pd-ut

PD_SERVER_DEP :=
ifeq ($(SWAGGER), 1)
Expand Down Expand Up @@ -108,7 +108,6 @@ pd-server-basic:
.PHONY: pre-build build tools pd-server pd-server-basic

# Tools

pd-ctl:
cd tools && GOEXPERIMENT=$(BUILD_GOEXPERIMENT) CGO_ENABLED=$(BUILD_TOOL_CGO_ENABLED) go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/pd-ctl pd-ctl/main.go
pd-tso-bench:
Expand All @@ -127,8 +126,12 @@ regions-dump:
cd tools && CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/regions-dump regions-dump/main.go
stores-dump:
cd tools && CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/stores-dump stores-dump/main.go
pd-ut: pd-xprog
cd tools && GOEXPERIMENT=$(BUILD_GOEXPERIMENT) CGO_ENABLED=$(BUILD_TOOL_CGO_ENABLED) go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/pd-ut pd-ut/ut.go
pd-xprog:
cd tools && GOEXPERIMENT=$(BUILD_GOEXPERIMENT) CGO_ENABLED=$(BUILD_TOOL_CGO_ENABLED) go build -tags xprog -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/xprog pd-ut/xprog.go

.PHONY: pd-ctl pd-tso-bench pd-recover pd-analysis pd-heartbeat-bench simulator regions-dump stores-dump pd-api-bench
.PHONY: pd-ctl pd-tso-bench pd-recover pd-analysis pd-heartbeat-bench simulator regions-dump stores-dump pd-api-bench pd-ut

#### Docker image ####

Expand Down Expand Up @@ -181,9 +184,6 @@ static: install-tools pre-build
@ gofmt -s -l -d $(PACKAGE_DIRECTORIES) 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ echo "golangci-lint ..."
@ golangci-lint run --verbose $(PACKAGE_DIRECTORIES) --allow-parallel-runners
@ echo "revive ..."
@ revive -formatter friendly -config revive.toml $(PACKAGES)

@ for mod in $(SUBMODULES); do cd $$mod && $(MAKE) static && cd $(ROOT_PATH) > /dev/null; done

# Because CI downloads the dashboard code and runs gofmt, we can't add this check into static now.
Expand Down Expand Up @@ -225,6 +225,12 @@ failpoint-disable: install-tools

#### Test ####

ut: pd-ut
@$(FAILPOINT_ENABLE)
./bin/pd-ut run --race
@$(CLEAN_UT_BINARY)
@$(FAILPOINT_DISABLE)

PACKAGE_DIRECTORIES := $(subst $(PD_PKG)/,,$(PACKAGES))
TEST_PKGS := $(filter $(shell find . -iname "*_test.go" -exec dirname {} \; | \
sort -u | sed -e "s/^\./github.com\/tikv\/pd/"),$(PACKAGES))
Expand Down Expand Up @@ -303,13 +309,16 @@ split:

clean: failpoint-disable clean-test clean-build

CLEAN_UT_BINARY := find . -name '*.test.bin'| xargs rm -f

clean-test:
# Cleaning test tmp...
rm -rf /tmp/test_pd*
rm -rf /tmp/pd-tests*
rm -rf /tmp/test_etcd*
rm -f $(REAL_CLUSTER_TEST_PATH)/playground.log
go clean -testcache
@$(CLEAN_UT_BINARY)

clean-build:
# Cleaning building files...
Expand Down
2 changes: 0 additions & 2 deletions client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ static: install-tools
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ echo "golangci-lint ..."
@ golangci-lint run -c ../.golangci.yml --verbose ./... --allow-parallel-runners
@ echo "revive ..."
@ revive -formatter friendly -config ../revive.toml ./...

tidy:
@ go mod tidy
Expand Down
41 changes: 24 additions & 17 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,10 @@ type GlobalConfigItem struct {
PayLoad []byte
}

// Client is a PD (Placement Driver) RPC client.
// It should not be used after calling Close().
type Client interface {
// GetClusterID gets the cluster ID from PD.
GetClusterID(ctx context.Context) uint64
// RPCClient is a PD (Placement Driver) RPC and related mcs client which can only call RPC.
type RPCClient interface {
// GetAllMembers gets the members Info from PD
GetAllMembers(ctx context.Context) ([]*pdpb.Member, error)
// GetLeaderURL returns current leader's URL. It returns "" before
// syncing leader from server.
GetLeaderURL() string
// GetRegion gets a region and its leader Peer from PD by key.
// The region may expire after split. Caller is responsible for caching and
// taking care of region change.
Expand Down Expand Up @@ -133,17 +127,12 @@ type Client interface {
StoreGlobalConfig(ctx context.Context, configPath string, items []GlobalConfigItem) error
// WatchGlobalConfig returns a stream with all global config and updates
WatchGlobalConfig(ctx context.Context, configPath string, revision int64) (chan []GlobalConfigItem, error)
// UpdateOption updates the client option.
UpdateOption(option DynamicOption, value any) error

// GetExternalTimestamp returns external timestamp
GetExternalTimestamp(ctx context.Context) (uint64, error)
// SetExternalTimestamp sets external timestamp
SetExternalTimestamp(ctx context.Context, timestamp uint64) error

// GetServiceDiscovery returns ServiceDiscovery
GetServiceDiscovery() ServiceDiscovery

// TSOClient is the TSO client.
TSOClient
// MetaStorageClient is the meta storage client.
Expand All @@ -154,6 +143,24 @@ type Client interface {
GCClient
// ResourceManagerClient manages resource group metadata and token assignment.
ResourceManagerClient
}

// Client is a PD (Placement Driver) RPC client.
// It should not be used after calling Close().
type Client interface {
RPCClient

// GetClusterID gets the cluster ID from PD.
GetClusterID(ctx context.Context) uint64
// GetLeaderURL returns current leader's URL. It returns "" before
// syncing leader from server.
GetLeaderURL() string
// GetServiceDiscovery returns ServiceDiscovery
GetServiceDiscovery() ServiceDiscovery

// UpdateOption updates the client option.
UpdateOption(option DynamicOption, value any) error

// Close closes the client.
Close()
}
Expand Down Expand Up @@ -431,12 +438,12 @@ func NewAPIContextV1() APIContext {
}

// GetAPIVersion returns the API version.
func (apiCtx *apiContextV1) GetAPIVersion() (version APIVersion) {
func (*apiContextV1) GetAPIVersion() (version APIVersion) {
return V1
}

// GetKeyspaceName returns the keyspace name.
func (apiCtx *apiContextV1) GetKeyspaceName() (keyspaceName string) {
func (*apiContextV1) GetKeyspaceName() (keyspaceName string) {
return ""
}

Expand All @@ -453,7 +460,7 @@ func NewAPIContextV2(keyspaceName string) APIContext {
}

// GetAPIVersion returns the API version.
func (apiCtx *apiContextV2) GetAPIVersion() (version APIVersion) {
func (*apiContextV2) GetAPIVersion() (version APIVersion) {
return V2
}

Expand Down Expand Up @@ -912,7 +919,7 @@ func handleRegionResponse(res *pdpb.GetRegionResponse) *Region {
return r
}

func (c *client) GetRegionFromMember(ctx context.Context, key []byte, memberURLs []string, opts ...GetRegionOption) (*Region, error) {
func (c *client) GetRegionFromMember(ctx context.Context, key []byte, memberURLs []string, _ ...GetRegionOption) (*Region, error) {
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
span = span.Tracer().StartSpan("pdclient.GetRegionFromMember", opentracing.ChildOf(span.Context()))
defer span.Finish()
Expand Down
2 changes: 1 addition & 1 deletion client/keyspace_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *client) UpdateKeyspaceState(ctx context.Context, id uint32, state keysp
// It returns a stream of slices of keyspace metadata.
// The first message in stream contains all current keyspaceMeta,
// all subsequent messages contains new put events for all keyspaces.
func (c *client) WatchKeyspaces(ctx context.Context) (chan []*keyspacepb.KeyspaceMeta, error) {
func (*client) WatchKeyspaces(context.Context) (chan []*keyspacepb.KeyspaceMeta, error) {
return nil, errors.Errorf("WatchKeyspaces unimplemented")
}

Expand Down
28 changes: 14 additions & 14 deletions client/mock_pd_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ func (m *mockPDServiceDiscovery) GetAllServiceClients() []ServiceClient {
return m.clients
}

func (m *mockPDServiceDiscovery) GetClusterID() uint64 { return 0 }
func (m *mockPDServiceDiscovery) GetKeyspaceID() uint32 { return 0 }
func (m *mockPDServiceDiscovery) GetKeyspaceGroupID() uint32 { return 0 }
func (m *mockPDServiceDiscovery) GetServiceURLs() []string { return nil }
func (m *mockPDServiceDiscovery) GetServingEndpointClientConn() *grpc.ClientConn { return nil }
func (m *mockPDServiceDiscovery) GetClientConns() *sync.Map { return nil }
func (m *mockPDServiceDiscovery) GetServingURL() string { return "" }
func (m *mockPDServiceDiscovery) GetBackupURLs() []string { return nil }
func (m *mockPDServiceDiscovery) GetServiceClient() ServiceClient { return nil }
func (m *mockPDServiceDiscovery) GetOrCreateGRPCConn(url string) (*grpc.ClientConn, error) {
func (*mockPDServiceDiscovery) GetClusterID() uint64 { return 0 }
func (*mockPDServiceDiscovery) GetKeyspaceID() uint32 { return 0 }
func (*mockPDServiceDiscovery) GetKeyspaceGroupID() uint32 { return 0 }
func (*mockPDServiceDiscovery) GetServiceURLs() []string { return nil }
func (*mockPDServiceDiscovery) GetServingEndpointClientConn() *grpc.ClientConn { return nil }
func (*mockPDServiceDiscovery) GetClientConns() *sync.Map { return nil }
func (*mockPDServiceDiscovery) GetServingURL() string { return "" }
func (*mockPDServiceDiscovery) GetBackupURLs() []string { return nil }
func (*mockPDServiceDiscovery) GetServiceClient() ServiceClient { return nil }
func (*mockPDServiceDiscovery) GetOrCreateGRPCConn(string) (*grpc.ClientConn, error) {
return nil, nil
}
func (m *mockPDServiceDiscovery) ScheduleCheckMemberChanged() {}
func (m *mockPDServiceDiscovery) CheckMemberChanged() error { return nil }
func (m *mockPDServiceDiscovery) AddServingURLSwitchedCallback(callbacks ...func()) {}
func (m *mockPDServiceDiscovery) AddServiceURLsSwitchedCallback(callbacks ...func()) {}
func (*mockPDServiceDiscovery) ScheduleCheckMemberChanged() {}
func (*mockPDServiceDiscovery) CheckMemberChanged() error { return nil }
func (*mockPDServiceDiscovery) AddServingURLSwitchedCallback(...func()) {}
func (*mockPDServiceDiscovery) AddServiceURLsSwitchedCallback(...func()) {}
Loading

0 comments on commit 4590464

Please sign in to comment.