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

*: support keyspace group RESTful API #6229

Merged
merged 6 commits into from Mar 29, 2023

Conversation

rleungx
Copy link
Member

@rleungx rleungx commented Mar 27, 2023

What problem does this PR solve?

Issue Number: Ref #6231.

What is changed and how does it work?

This PR adds key space group-related APIs and a basic framework for management.

Check List

Tests

  • Unit test

Release note

None.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 27, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • binshi-bing
  • lhy1024

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot
Copy link
Member

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none labels Mar 27, 2023
@rleungx rleungx changed the title *: draft for keyspace group RESTful API *: support keyspace group RESTful API Mar 27, 2023
@codecov
Copy link

codecov bot commented Mar 27, 2023

Codecov Report

Patch coverage: 54.16% and project coverage change: +0.03 🎉

Comparison is base (34949b8) 74.95% compared to head (a1f7126) 74.99%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6229      +/-   ##
==========================================
+ Coverage   74.95%   74.99%   +0.03%     
==========================================
  Files         401      404       +3     
  Lines       38884    39015     +131     
==========================================
+ Hits        29147    29260     +113     
- Misses       7194     7209      +15     
- Partials     2543     2546       +3     
Flag Coverage Δ
unittests 74.99% <54.16%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
client/tso_dispatcher.go 81.20% <ø> (+1.50%) ⬆️
client/tso_service_discovery.go 66.34% <ø> (ø)
pkg/storage/storage.go 71.15% <ø> (ø)
pkg/tso/keyspace_group_manager.go 88.88% <0.00%> (ø)
server/keyspace/util.go 95.23% <ø> (ø)
server/apiv2/handlers/tso_keyspace_group.go 29.50% <29.50%> (ø)
server/server.go 75.53% <50.00%> (+0.11%) ⬆️
pkg/storage/endpoint/tso_keyspace_group.go 61.53% <61.53%> (ø)
server/apiv2/handlers/keyspace.go 66.66% <83.33%> (+1.85%) ⬆️
server/keyspace/tso_keyspace_group.go 83.33% <83.33%> (ø)
... and 4 more

... and 27 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rleungx rleungx force-pushed the keyspace-group-API branch 3 times, most recently from c436e0e to 5b8a281 Compare March 28, 2023 06:15
@rleungx rleungx marked this pull request as ready for review March 28, 2023 06:18
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 28, 2023
@rleungx rleungx requested review from binshi-bing and lhy1024 and removed request for disksing March 28, 2023 06:21
server/keyspace/keyspace_group.go Outdated Show resolved Hide resolved
server/apiv2/handlers/keyspace_group.go Outdated Show resolved Hide resolved
server/apiv2/handlers/keyspace_group.go Outdated Show resolved Hide resolved
// CreateKeyspaces creates keyspace groups.
func (m *GroupManager) CreateKeyspaces(keyspaceGroups []*endpoint.KeyspaceGroup) error {
for _, keyspaceGroup := range keyspaceGroups {
// TODO: add replica count
Copy link
Contributor

Choose a reason for hiding this comment

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

How will it pass into?

Copy link
Member Author

Choose a reason for hiding this comment

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

The replica count is the input contained in the request, we need to add the member info to it according to the count.

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>
Copy link
Contributor

@binshi-bing binshi-bing left a comment

Choose a reason for hiding this comment

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

Left some comments

@@ -53,6 +53,9 @@ const (
tsoServiceKey = utils.TSOServiceName
timestampKey = "timestamp"

tsoKeyspaceGroupPrefix = "tso/keyspace_groups"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we change to utils.TSOServiceName + "keyspace_groups"

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, I think there is no need and it's simpler. Once some other services need the group concept, we can refactor it.

Copy link
Contributor

Choose a reason for hiding this comment

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

My current change is using it. Leave this refactor to me then. Your pr goest first.

Copy link
Member Author

Choose a reason for hiding this comment

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

get it

// KeyspaceGroupStorage is the interface for keyspace group storage.
type KeyspaceGroupStorage interface {
LoadKeyspaceGroups(startID uint32, limit int) ([]*KeyspaceGroup, error)
LoadKeyspaceGroup(txn kv.Txn, id uint32) (*KeyspaceGroup, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is to load from single key-value pair, correct? If yes, do we still need transaction?

Copy link
Member Author

Choose a reason for hiding this comment

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

As long as we use the storage interface, it will create a txn. I think it's ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok.

type KeyspaceGroupStorage interface {
LoadKeyspaceGroups(startID uint32, limit int) ([]*KeyspaceGroup, error)
LoadKeyspaceGroup(txn kv.Txn, id uint32) (*KeyspaceGroup, error)
SaveKeyspaceGroup(txn kv.Txn, kg *KeyspaceGroup) error
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto - SaveKeyspaceGroup and DeleteKeyspaceGroup

Copy link
Member Author

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

return txn.Remove(KeyspaceGroupIDPath(id))
}

// LoadKeyspaceGroups loads all keyspace groups.
Copy link
Contributor

Choose a reason for hiding this comment

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

if this function is used to load all keyspace groups, as said by this comments, probably we shouldn't have the limit parameter.

With the limit parameter, LoadKeyspaceGroups looks like a function supporting pagination, but the return values don't contain 'continuation' field indicating the position of the next page.

The comments and function signature seem to need refinement to support either LoadAllKeyspaceGroups or LoadKeyspaceGroups(pagination) or both.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the comment is wrong.


// KeyspaceGroupStorage is the interface for keyspace group storage.
type KeyspaceGroupStorage interface {
LoadKeyspaceGroups(startID uint32, limit int) ([]*KeyspaceGroup, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Compared to the function "LoadKeyspaceGroup(txn kv.Txn, id uint32)", if we load multiple groups here, do we need to use transaction to provide snapshot isolation consistency level?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

}

// GetKeyspaceGroups returns all keyspace groups.
func (m *GroupManager) GetKeyspaceGroups(startID uint32, limit int) ([]*endpoint.KeyspaceGroup, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

Please ignore this comment then, according to our offline discussion.

err error
)

m.store.RunInTxn(m.ctx, func(txn kv.Txn) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need transaction as mentioned above?

Copy link
Contributor

Choose a reason for hiding this comment

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

After I saw the implementation of "saveKeyspaceGroup" below, I realized that the reason that we use transaction for LoadKeyspaceGroup is because we want to support LoadOrSave() semantics for "saveKeyspaceGroup". In this sense, do we need to provide two versions of LoadKeyspaceGroup - one is non-transactional and another is transactional? GetKeyspaceGroupByID then will just use the non-transactional version. I assume that, without transaction, the single key-value get/put has better performance. Correct me, if I'm wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please ignore this comment then, according to our offline discussion.

}

func (m *GroupManager) saveKeyspaceGroup(keyspaceGroup *endpoint.KeyspaceGroup) error {
return m.store.RunInTxn(m.ctx, func(txn kv.Txn) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering, compared to the two round-trips in the change, if the following LoadOrSave operation is pushed down to etcd and just need one round-trip?

	txnResp, err := cli.Txn(context.Background()).
		If(clientv3.Compare(clientv3.Version(key), "=", 0)).
		Then(clientv3.OpPut(key, defaultValue)).
		Else(clientv3.OpGet(key)).
		Commit()

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but the current kv interface doesn't have it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please ignore this comment then, according to our offline discussion.

defaultKeyspaceGroup := &endpoint.KeyspaceGroup{
ID: utils.DefaultKeySpaceGroupID,
// TODO: define a user kind type
UserKind: "default",
Copy link
Contributor

Choose a reason for hiding this comment

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

The doc "Keyspace group membership management APIs" defines the enum values of UserKind. Shall we double-check with serverless service team to say if it's sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The user kind in this PR is just a placeholder.

@@ -39,9 +39,11 @@ var (
ErrKeyspaceNotFound = errors.New("keyspace does not exist")
// ErrKeyspaceExists indicates target keyspace already exists.
// Used when creating a new keyspace.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Used when creating a new keyspace.
// Use when creating a new keyspace.

type KeyspaceGroup struct {
ID uint32 `json:"id"`
UserKind string `json:"user-kind"`
// TODO: add `Members` field
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 should call it Replicas. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both are ok to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

up to you then

Copy link
Contributor

Choose a reason for hiding this comment

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

keep members then. I'm using members in my change.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor

@binshi-bing binshi-bing left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 29, 2023
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 29, 2023
@rleungx rleungx force-pushed the keyspace-group-API branch 2 times, most recently from 541073d to 0a48c1c Compare March 29, 2023 04:13
Signed-off-by: Ryan Leung <rleungx@gmail.com>
type KeyspaceGroup struct {
ID uint32 `json:"id"`
UserKind string `json:"user-kind"`
// TODO: add `Members` field
Copy link
Contributor

Choose a reason for hiding this comment

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

keep members then. I'm using members in my change.

@rleungx
Copy link
Member Author

rleungx commented Mar 29, 2023

/merge

@ti-chi-bot
Copy link
Member

@rleungx: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: a1f7126

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 29, 2023
@ti-chi-bot ti-chi-bot merged commit fe22771 into tikv:master Mar 29, 2023
20 of 21 checks passed
@rleungx rleungx deleted the keyspace-group-API branch March 29, 2023 08:48
rleungx added a commit to rleungx/pd that referenced this pull request Jun 5, 2023
* client: refine serviceModeKeeper code (tikv#6201)

ref tikv#5895

Some code refinements for `serviceModeKeeper`.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* *: use revision for watch test (tikv#6205)

ref tikv#6071

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* *: remove unnecessary rand init (tikv#6207)

close tikv#6134

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* Refactor TSO forward/dispatcher to be shared by both PD and TSO (tikv#6175)

ref tikv#5895

Add general tso forward/dispatcher for independent pd(tso)/tso services and cross cluster forwarding.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* Add basic multi-keyspace-group management (tikv#6214)

ref tikv#5895

Support basic functions of multi-keyspace-group management

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* *: support keyspace group RESTful API (tikv#6229)

ref tikv#6231

Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* mcs: add more tso tests (tikv#6184)

ref tikv#5836

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* client: fix compatibility problem of pd client (tikv#6244)

close tikv#6243

Signed-off-by: Ryan Leung <rleungx@gmail.com>

* *: unify the key prefix (tikv#6248)

ref tikv#5836

Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* *: remove cluster dependency from keyspace (tikv#6249)

ref tikv#6231

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* *: make code clear by rename `isServing` to `isRunning` (tikv#6258)

ref tikv#4399

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* cgroup: fix the path problem due to special container name (tikv#6267)

close tikv#6266

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* server: fix watch keyspace revision (tikv#6251)

ref tikv#5895

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* tso, server: refine the TSO allocator manager parameters (tikv#6269)

ref tikv#5895

- Refine the TSO allocator manager parameters.
- Always run `tsoAllocatorLoop` to advance the Global TSO.

Signed-off-by: JmPotato <ghzpotato@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* tso: unify the TSO ServiceConfig and ConfigProvider interfaces (tikv#6272)

ref tikv#5895

Unify the TSO `ServiceConfig` and `ConfigProvider` interfaces.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

* Load initial assignment and dynamically watch/apply keyspace groups' membership/distribution change (tikv#6247)

ref tikv#6232

Load initial keyspace group assignment.
Dynamically watch/apply keyspace groups' membership/distribution change.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* *: define user kind for keyspace group (tikv#6241)

ref tikv#6231

Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* Add more failure tests when tso service loading initial keyspace groups assignment (tikv#6280)

ref tikv#6232

Add more failure tests when tso service loading initial keyspace groups assignment

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* Apply multi-keyspace-group membership to tso service and handle inconsistency issue (tikv#6282)

ref tikv#6232

Apply multi-keyspace-group membership to tso service and handle inconsistency issue.

1. Add KeyspaceLookupTable to endpoint.KeyspaceGroup
type KeyspaceGroup struct {
        ...
        // KeyspaceLookupTable is for fast lookup if a given keyspace belongs to this keyspace group.
        // It's not persisted and will be built when loading from storage.
        KeyspaceLookupTable map[uint32]struct{} `json:"-"`
}

2. After loading keyspace groups, the Keyspace Group Manager builds KeyspaceLookupTable for every keyspace groups.

3. When Keyspace Group Manager handles tso requests, it uses the keyspaceLookupTable to check if the required keypsace still belongs to the required keyspace group. If not, returns the current keyspace group id in the tso response header.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* *: auto assign keyspace group (tikv#6268)

close tikv#6231

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* keyspace, api: support the keyspace group split (tikv#6293)

ref tikv#6232

Support the keyspace group split and add related tests.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* Improve lock mechanism in tso.KeyspaceGroupManager (tikv#6305)

ref tikv#6232

Use the RWMutex instead of individual atomic types to better protect the state of the keyspace group manager

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* keyspace: add split-from field for endpoint.KeyspaceGroup (tikv#6309)

ref tikv#6232

Add `split-from` field for `endpoint.KeyspaceGroup`.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* Add read lock at one place for protection and better structure (tikv#6310)

ref tikv#6232, ref tikv#6305

follow-up tikv#6305 
Add read lock at one place for protection and better structure

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* tso: optimize function signatures to reduce parameter passing (tikv#6315)

ref tikv#6232

Optimize function signatures to reduce parameter passing.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

* *: bootstrap keyspace group when server is in API mode (tikv#6308)

ref tikv#6231

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* keyspace: avoid keyspace being updated during the split (tikv#6316)

ref tikv#6232

Prevent keyspace from being updated during the split.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

* *: fix `TestConcurrentlyReset` (tikv#6318)

close tikv#6275

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* bootstrap default keyspace group in the tso service (tikv#6306)

ref tikv#6232

Changes:

1. Introduce the initialization logic of the default keyspace group.
- If the default keyspace group isn't configured in the etcd, every tso node/pod should initialize it and join the election for the primary of this group.
- If the default keyspace group is configured in the etcd, the tso nodes/pods which are assigned with this group will initialize it and join the election for the primary of this group.

2. Introduce the keyspace group membership restriction -- default keyspace always belongs to default keyspace group.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* *: change the log level (tikv#6324)

ref tikv#6232

Signed-off-by: Ryan Leung <rleungx@gmail.com>

* *: fix the missing log panic (tikv#6325)

close tikv#6257

Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* mcs: fix watch primary address revision and update cache when meets not leader  (tikv#6279)

ref tikv#5895

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* tso, member: support TSO split based on keyspace group split (tikv#6313)

ref tikv#6232

Support TSO split based on keyspace group split.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* mcs: support metrics HTTP interface for tso/resource manager server (tikv#6329)

ref tikv#5895

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* tso: put finishSplitKeyspaceGroup into the critical section (tikv#6331)

ref tikv#6232

Put `finishSplitKeyspaceGroup` into the critical section.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* *: make `TestServerRegister` stable (tikv#6337)

close tikv#6334

Signed-off-by: Ryan Leung <rleungx@gmail.com>

* tests: divide all tests into the CI chunks including submodule tests (tikv#6198)

ref tikv#6181, ref tikv#6183

Divide all tests into the CI chunks including submodule tests.

Signed-off-by: JmPotato <ghzpotato@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* tests: introduce TSO TestCluster in the test (tikv#6333)

ref tikv#6232

Introduce TSO `TestCluster` in the test.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* mcs: add balancer for keyspace group (tikv#6274)

close tikv#6233

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* Fixed bugs in tso service registry watching loop. (tikv#6346)

ref tikv#6343

Fixed the following two bugs:
1. When re-watch a range, to continue from what left by the last watch, the revision is wresp.Header.Revision + 1 instead of wresp.Header.Revision, where wresp.Header.Revision is the revision indicated in the response of the last watch. Because of this bug, it was processing the same event endless as you can see from the log below.
2. In tso service watch loop in /Users/binshi/code/pingcap/my-pd/pkg/keyspace/tso_keyspace_group.go, If this is delete event, the json.Unmarshal(event.Kv.Value, s) will fail with the error "unexpected end of JSON input", so there is no way to get s.serviceAddr from the result of json.Unmarshal.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* mcs: fix double compression of prom handler (tikv#6339)

ref prometheus/client_golang#622, ref tikv#5895

Signed-off-by: Ryan Leung <rleungx@gmail.com>

* tests, tso: add more TSO split tests (tikv#6338)

ref tikv#6232

Add more TSO split tests.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

* keyspace, tso: fix next revision to watch after watch/Get/RangeScan (tikv#6353)

ref tikv#6232

The next revision to watch should always be Header.Revision + 1 where header is response header of watch/Get/RangeScan

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* mcs, tests: use TSO cluster to do the failover test (tikv#6356)

ref tikv#5895

Use TSO cluster to do the failover test.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

* fix startWatchLoop leak (tikv#6352)

Signed-off-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* mcs: update client when meet transport is closing (tikv#6341)

* mcs: update client when meet transport is closing

Signed-off-by: lhy1024 <admin@liudos.us>

* address comments

Signed-off-by: lhy1024 <admin@liudos.us>

* add retry

Signed-off-by: lhy1024 <admin@liudos.us>

---------

Signed-off-by: lhy1024 <admin@liudos.us>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* add bootstrap test (tikv#6347)

Signed-off-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* Fix flaky TestLoadKeyspaceGroupsAssignment test (tikv#6365)

Reduce the count of keyspace groups from 4096 to 512 in TestKeyspaceGroupManagerTestSuite/TestLoadKeyspaceGroupsAssignment to avoid timeout when test running slow.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* mcs, tso: fix ts fallback caused by multi-primary of the same keyspace group  (tikv#6362)

* Change participant election-prifix from listen-addr to advertise-listen-addr to gurantee uniqueness.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* Add TestPariticipantStartWithAdvertiseListenAddr

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* Add comments to fix go fmt errors

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

---------

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Co-authored-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* fix log output (tikv#6364)

Signed-off-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* mcs: fix duplicate start of RaftCluster. (tikv#6358)

* Using double-checked locking to avoid duplicate start of RaftCluster.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* Handle feedback

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* improve locking

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* handle feedback

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

---------

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Co-authored-by: Ryan Leung <rleungx@gmail.com>

* Add retry mechanism for updating keyspace group (tikv#6372)

Signed-off-by: JmPotato <ghzpotato@gmail.com>

* mcs: add set handler for balancer and alloc node for default keyspace group (tikv#6342)

ref tikv#6233

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* mcs, tso: fix Nil pointer deference when (*AllocatorManager).GetMember (tikv#6383)

close tikv#6381

If the desired keyspace group fall back to the default keyspace group and the AM isn't initialized, return not served error.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* mcs, tso: support multi-keyspace-group and its service discovery in E2E path (tikv#6321)

ref tikv#6232

Support multi-keyspace-group in PD(TSO) client

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* client: add `NewClientWithKeyspaceName` for client (tikv#6380)

ref tikv#5895

Signed-off-by: Ryan Leung <rleungx@gmail.com>

* keyspace, tso: check the replica count before the split (tikv#6382)

ref tikv#6233

Check the replica count before the split.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: lhy1024 <admin@liudos.us>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* tso: fix bugs to make split test case to pass (tikv#6389)

ref tikv#6232

fix bugs to make split test case to pass

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* keyspace: patrol keyspace assignment before the first split (tikv#6388)

ref tikv#6232

Patrol the keyspace assignment before the first split to make sure every keyspace has its group assignment.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* tests: fix Flaky TestMicroserviceTSOServer/TestConcurrentlyReset (tikv#6396)

close tikv#6385

Get a copy of now then call base.add, because now is shared by all goroutines and now.add() will add to itself which isn't atomic and multi-goroutine safe.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* keyspace, slice: improve code efficiency in membership ops (tikv#6392)

ref tikv#6231

Improve code efficiency in membership ops

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* tests: enable TestTSOKeyspaceGroupSplitClient (tikv#6398)

ref tikv#6232

Enable `TestTSOKeyspaceGroupSplitClient`.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* tests: add more tests for multiple keyspace groups (tikv#6395)

ref tikv#5895

Add CheckMultiKeyspacesTSO() and WaitForMultiKeyspacesTSOAvailable in test utility. Add TestTSOKeyspaceGroupManager/TestKeyspacesServedByNonDefaultKeyspaceGroup. Cover TestGetTS, TestGetTSAsync, TestUpdateAfterResetTSO in TestMicroserviceTSOClient for multiple keyspace groups.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* tests: fix failpoint disable (tikv#6401)

ref tikv#4399

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* client: retry load keyspace meta when creating a new client (tikv#6402)

ref tikv#5895

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* Fix test issue in TestRandomResignLeader. (tikv#6410)

close tikv#6404

We need to make sure the selected keyspaces are from different keyspace groups, otherwise multiple goroutines below could try to resign the primary of the same keyspace group and cause race condition.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* keyspace, api2: fix the keyspace assignment patrol consistency (tikv#6397)

ref tikv#6232

Fix the keyspace assignment patrol consistency.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* election, tso: fix data race in lease.go (tikv#6379)

close tikv#6378

fix data race in lease.go

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* mcs: fix forward test with pd mode client (tikv#6290)

ref tikv#5895, ref tikv#6279, close tikv#6289

Signed-off-by: lhy1024 <admin@liudos.us>

* keyspace: patrol the keyspace assignment in batch (tikv#6411)

ref tikv#6232

Patrol the keyspace assignment in batch.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

* etcdutil: add watch loop (tikv#6390)

close tikv#6391

Signed-off-by: lhy1024 <admin@liudos.us>

* mcs, tso: add API interface to obtain the TSO keyspace group member info (tikv#6373)

ref tikv#6232

Add API interface to obtain the TSO keyspace group member info.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* pkg: move operator_check out from test_util tikv#6162

Signed-off-by: lhy1024 <admin@liudos.us>

* keysapce: wait region split when creating keyspace (tikv#6414)

ref tikv#6231

Signed-off-by: zeminzhou <zhouzemin@pingcap.com>
Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: zzm <zhouzemin@pingcap.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* mcs: use getClusterInfo to check whether api service is ready (tikv#6422)

ref tikv#5836

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* fix data race by replace clone (tikv#6242)

close tikv#6230

Signed-off-by: bufferflies <1045931706@qq.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: lhy1024 <admin@liudos.us>

* fix test and git mod tidy

Signed-off-by: lhy1024 <admin@liudos.us>

* revert makefile

Signed-off-by: lhy1024 <admin@liudos.us>

* fix ctx in watch loop

Signed-off-by: lhy1024 <admin@liudos.us>

* delete pd-tests.yaml

Signed-off-by: lhy1024 <admin@liudos.us>

* pd-ctl, tests: add the keyspace group commands (tikv#6423)

ref tikv#6232

Add the keyspace group commands to show and split keyspace groups.

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* Handle compatibility issue in GetClusterInfo RPC (tikv#6434)

ref tikv#5895, close tikv#6448

Handle the compatibility issue in the GetClusterInfo RPC

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* Provide GetMinTS API to solve the compatibility issue brought by multi-timeline tso (tikv#6421)

ref tikv#6142

1. Import kvproto change to introduce GetMinTS rpc in the TSO service.
6. Add server side implementation for GetMinTS rpc.
7. Add client side implementation for GetMinTS rpc.
8. Add unit test

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* tso: use less interval when waiting api service (tikv#6451)

close tikv#6449

Signed-off-by: lhy1024 <admin@liudos.us>

* etcdutil: fix ctx in watch loop (tikv#6445)

close tikv#6439

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* Fix "non-default keyspace groups use the same timestamp path by mistake" (tikv#6457)

close tikv#6453, close tikv#6465

The tso servers are loading keyspace groups asynchronously. Make sure all keyspace groups
are available for serving tso requests from corresponding keyspaces by querying
IsKeyspaceServing(keyspaceID, the Desired KeyspaceGroupID). if use default keyspace group id
in the query, it will always return true as the keyspace will be served by default keyspace group
before the keyspace groups are loaded.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>

* TSO microservice discovery fallback path shouldn't call FindGroupByKeyspaceID (tikv#6473)

close tikv#6472

TSO microservice discovery fallback path shouldn't call FindGroupByKeyspaceID

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* Revert "cgroup: fix the path problem due to special container name (tikv#6267)"

This reverts commit 0c4cf7f947799e5c45d6e37448475b921044bdde.

* *: rm debug file (tikv#6458)

ref tikv#4399

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* Revert "*: remove unnecessary rand init (tikv#6207)"

This reverts commit 7383ded7581c417a3866da271eb2ec0a27b5a6c8.

* mcs, tso: handle null keyspace (tikv#6476)

ref tikv#5895

For API V1 and legacy path (NewClientWithContext w/o keyspace id/name),
using Null Keypsace ID (uint32max) instead of default keyspace id and
make sure it can be served by the default keyspace group's timeline. Modifying test accordingly.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* mcs, tso: print TSO service discovery fallback log just once (tikv#6478)

ref tikv#5895

Print TSO service discovery fallback log just once

Signed-off-by: Bin Shi <binshi.bing@gmail.com>

* client: return error if the keyspace meta cannot be found (tikv#6479)

ref tikv#6142

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>

* client: support use API context to create client (tikv#6482)

ref tikv#6142

Signed-off-by: Ryan Leung <rleungx@gmail.com>

---------

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Signed-off-by: lhy1024 <admin@liudos.us>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: JmPotato <ghzpotato@gmail.com>
Co-authored-by: JmPotato <ghzpotato@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Co-authored-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: Bin Shi <39923490+binshi-bing@users.noreply.github.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Co-authored-by: zzm <zhouzemin@pingcap.com>
Co-authored-by: buffer <1045931706@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants