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

Client provides addresses of current leader and members to callback function of upper layer #7063

Open
lance6716 opened this issue Sep 11, 2023 · 2 comments
Labels
type/enhancement The issue belongs to an enhancement.

Comments

@lance6716
Copy link
Contributor

Enhancement Task

Currently PD client has the functionality to maintain the latest leader and members in pdServiceDiscovery. It's helpful that this functionality can help caller know latest PD leader/member information when caller access them directly rather than use Client interface. One example is lightning directly use leader address to use HTTP API.

So I propose these new methods to Client interface

type Client interface {
...
    ToLeader(ctx context.Context, fn func(leaderAddr string) error) error
    ToAtLeastOneMember(ctx context.Context, fn func(addrs []string) error) error
}

And caller can use it like

// check PD version
err := pdCli.ToAtLeastOneMember(ctx, func (addrs []string) error {
    for _, addr := range addrs {
        err := tls.WithHost(addr).GetJSON(ctx, "/pd/api/v1/version", &rawVersion)
        ...
    }
    ...
})

When the callback function fails for network problem, PD client can also trigger internal leader/member updating.

@lance6716 lance6716 added the type/enhancement The issue belongs to an enhancement. label Sep 11, 2023
@lance6716
Copy link
Contributor Author

Also, when currently cluster has no leader elected, the ToLeader can be blocked until leader is online

@bufferflies
Copy link
Contributor

how about use watch api?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants