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

*: add config client #2041

Merged
merged 7 commits into from
Jan 6, 2020
Merged

*: add config client #2041

merged 7 commits into from
Jan 6, 2020

Conversation

rleungx
Copy link
Member

@rleungx rleungx commented Dec 19, 2019

What problem does this PR solve?

Part of #1977. It should be reviewed after #2033 is merged.

What is changed and how it works?

This PR adds a client for config manager service.

Check List

Tests

  • Unit test

@rleungx rleungx added the component/config Configuration logic. label Dec 19, 2019
@rleungx rleungx added this to the v4.0.0-beta milestone Dec 19, 2019
@rleungx rleungx force-pushed the config-client branch 2 times, most recently from b88c677 to ccd1729 Compare December 20, 2019 06:09
@codecov-io
Copy link

codecov-io commented Dec 20, 2019

Codecov Report

Merging #2041 into master will increase coverage by 0.1%.
The diff coverage is 77.39%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #2041     +/-   ##
=========================================
+ Coverage   76.72%   76.83%   +0.1%     
=========================================
  Files         191      193      +2     
  Lines       19293    19414    +121     
=========================================
+ Hits        14803    14916    +113     
  Misses       3369     3369             
- Partials     1121     1129      +8
Impacted Files Coverage Δ
client/metrics.go 100% <100%> (ø) ⬆️
client/config_client.go 56.56% <56.56%> (ø)
client/client.go 68.46% <77.77%> (-4.18%) ⬇️
server/config_manager/config_manager.go 76.71% <80%> (+2.95%) ⬆️
client/base_client.go 91.91% <91.91%> (ø)
server/region_syncer/client.go 66.26% <0%> (-10.85%) ⬇️
server/schedulers/base_scheduler.go 60.86% <0%> (-8.7%) ⬇️
server/kv/etcd_kv.go 75.32% <0%> (-6.5%) ⬇️
server/schedulers/shuffle_hot_region.go 64.58% <0%> (-5.21%) ⬇️
server/schedulers/adjacent_region.go 75.4% <0%> (-1.07%) ⬇️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c32c3d5...04d68d4. Read the comment docs.

return errors.WithStack(errFailInitClusterID)
}

func (c *configClient) updateLeader() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we add it to PD client so we don't have to manage connections in both places.

Copy link
Member Author

Choose a reason for hiding this comment

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

@overvenus PTAL

Copy link
Member

Choose a reason for hiding this comment

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

OK

@rleungx rleungx force-pushed the config-client branch 3 times, most recently from e2b8f51 to 62dc5ea Compare December 30, 2019 09:10
@rleungx
Copy link
Member Author

rleungx commented Dec 30, 2019

PTAL @disksing @overvenus

Copy link
Member

@overvenus overvenus left a comment

Choose a reason for hiding this comment

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

Rest LGTM

)

// BaseClient is a basic client for all other complex client.
type BaseClient struct {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type BaseClient struct {
type baseClient struct {

If BaseClient is only for internal use, I think it's better to not export it for better maintainability.

}

// NewBaseClient returns a new BaseClient.
func NewBaseClient(ctx context.Context, urls []string, security SecurityOption, opts ...ClientOption) *BaseClient {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func NewBaseClient(ctx context.Context, urls []string, security SecurityOption, opts ...ClientOption) *BaseClient {
func newBaseClient(ctx context.Context, urls []string, security SecurityOption, opts ...ClientOption) *BaseClient {

mergeAndUpdateConfig(localCfg, updateEntries)
if wrongEntry, err := mergeAndUpdateConfig(localCfg, updateEntries); err != nil {
c.deleteEntry(component, wrongEntry)

Copy link
Contributor

Choose a reason for hiding this comment

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

remove empty line.

log.Info("[pd] init cluster id", zap.Uint64("cluster-id", c.clusterID))

c.wg.Add(1)
go c.leaderLoop()
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move this to baseclient?

log.Info("[pd] create pd configuration client with endpoints", zap.Strings("pd-address", pdAddrs))
base := NewBaseClient(ctx, addrsToUrls(pdAddrs), security)
c := &configClient{base}
c.connMu.clientConns = make(map[string]*grpc.ClientConn)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems already created in baseClient.

if err := c.initRetry(c.initClusterID); err != nil {
return nil, err
}
if err := c.initRetry(c.updateLeader); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe do it in baseClient

@rleungx
Copy link
Member Author

rleungx commented Jan 3, 2020

/run-all-tests

Copy link
Member

@overvenus overvenus left a comment

Choose a reason for hiding this comment

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

Rest LGTM

client/config_client.go Show resolved Hide resolved
client/config_client.go Show resolved Hide resolved
@@ -117,45 +113,13 @@ var (
)

type client struct {
urls []string
clusterID uint64
*baseClient
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding a function in Client that we can generate a ConfigClient from Client. TiDB may want to only use one client or one connection.

@rleungx rleungx force-pushed the config-client branch 2 times, most recently from 04d68d4 to d475550 Compare January 6, 2020 10:03
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
@rleungx
Copy link
Member Author

rleungx commented Jan 6, 2020

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jan 6, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Jan 6, 2020

/run-all-tests

@sre-bot sre-bot merged commit 4498b6f into tikv:master Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/config Configuration logic. status/can-merge Indicates a PR has been approved by a committer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants