-
Notifications
You must be signed in to change notification settings - Fork 719
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 dynamic tso service #8517
base: master
Are you sure you want to change the base?
Conversation
@@ -660,7 +660,7 @@ func (c *client) Close() { | |||
} | |||
} | |||
|
|||
func (c *client) setServiceMode(newMode pdpb.ServiceMode) { | |||
func (c *client) setServiceMode(newMode pdpb.ServiceMode, skipSameMode bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using a more straightforward word.
func (c *client) setServiceMode(newMode pdpb.ServiceMode, skipSameMode bool) { | |
func (c *client) setServiceMode(newMode pdpb.ServiceMode, force bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the same as force.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not skipSameMode always?
} | ||
errMsg := err.Error() | ||
return strings.Contains(errMsg, "not found tso address") || | ||
strings.Contains(errMsg, "maximum number of retries exceeded") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error would also occur when the leadership cannot be elected. In which case will this be a misjudgment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't check this error on client side, do you know about the reason?
@@ -406,6 +406,8 @@ func TestTSOFollowerProxyWithTSOService(t *testing.T) { | |||
backendEndpoints := pdLeaderServer.GetAddr() | |||
tsoCluster, err := tests.NewTestTSOCluster(ctx, 2, backendEndpoints) | |||
re.NoError(err) | |||
// let service discovery know the TSO service | |||
time.Sleep(500 * time.Millisecond) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be replaced with an Eventually
?
6c98636
to
dc6b4a7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8517 +/- ##
==========================================
- Coverage 77.53% 77.48% -0.05%
==========================================
Files 474 474
Lines 62355 62469 +114
==========================================
+ Hits 48345 48404 +59
- Misses 10437 10485 +48
- Partials 3573 3580 +7
Flags with carried forward coverage won't be shown. Click here to find out more. |
a36ad5d
to
f2c0c14
Compare
5d11416
to
12c7821
Compare
client/errs/errs.go
Outdated
@@ -38,6 +38,16 @@ func IsLeaderChange(err error) bool { | |||
strings.Contains(errMsg, NotPrimaryErr) | |||
} | |||
|
|||
// IsServiceModeChange will determine whether there is a service mode change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// IsServiceModeChange will determine whether there is a service mode change. | |
// IsServiceModeChange determines whether there is a service mode change. |
server/forward.go
Outdated
if err != nil { | ||
if needRetry := handleStreamError(err); needRetry { | ||
continue | ||
if s.forwardToTSOService() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can reduce some of the indentation
if s.forwardToTSOService() { | |
if !s.forwardToTSOService() { | |
return s.tsoAllocatorManager.HandleRequest(ctx, tso.GlobalDCLocation, 1) | |
} | |
request := xxxx | |
..... |
@@ -569,6 +590,72 @@ func (s *GrpcServer) Tso(stream pdpb.PD_TsoServer) error { | |||
continue | |||
} | |||
|
|||
if s.forwardToTSOService() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe wrap three situation(local tso/ms tso/normal) to three functions. Just a suggestion.
server/cluster/cluster.go
Outdated
if !c.IsServiceIndependent(constant.TSOServiceName) { | ||
// leader tso service exit, tso independent service provide tso | ||
c.tsoAllocator.ResetAllocatorGroup(tso.GlobalDCLocation, true) | ||
} | ||
if !c.IsServiceIndependent(constant.TSOServiceName) { | ||
log.Info("TSO server starts to provide timestamp") | ||
} | ||
c.SetServiceIndependent(constant.TSOServiceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !c.IsServiceIndependent(constant.TSOServiceName) { | |
// leader tso service exit, tso independent service provide tso | |
c.tsoAllocator.ResetAllocatorGroup(tso.GlobalDCLocation, true) | |
} | |
if !c.IsServiceIndependent(constant.TSOServiceName) { | |
log.Info("TSO server starts to provide timestamp") | |
} | |
c.SetServiceIndependent(constant.TSOServiceName) | |
if !c.IsServiceIndependent(constant.TSOServiceName) { | |
// leader tso service exit, tso independent service provide tso | |
c.tsoAllocator.ResetAllocatorGroup(tso.GlobalDCLocation, true) | |
log.Info("TSO server starts to provide timestamp") | |
} | |
c.SetServiceIndependent(constant.TSOServiceName) |
@@ -390,24 +397,84 @@ func (c *RaftCluster) checkServices() { | |||
} | |||
} | |||
|
|||
// checkTSOService checks the TSO service. | |||
func (c *RaftCluster) checkTSOService() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add more comments for this function and inside this function. Seems there are too many situations in this function
client/pd_service_discovery.go
Outdated
|
||
ctx, cancel := context.WithCancel(c.ctx) | ||
defer cancel() | ||
ticker := time.NewTicker(serviceModeUpdateInterval) | ||
failpoint.Inject("fastUpdateServiceMode", func() { | ||
ticker.Stop() | ||
ticker = time.NewTicker(10 * time.Millisecond) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ticker.Reset()?
client/client.go
Outdated
@@ -713,6 +712,7 @@ func (c *client) resetTSOClientLocked(mode pdpb.ServiceMode) { | |||
log.Warn("[pd] intend to switch to unknown service mode, just return") | |||
return | |||
} | |||
// Replace the old TSO client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate
@@ -660,7 +660,7 @@ func (c *client) Close() { | |||
} | |||
} | |||
|
|||
func (c *client) setServiceMode(newMode pdpb.ServiceMode) { | |||
func (c *client) setServiceMode(newMode pdpb.ServiceMode, skipSameMode bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not skipSameMode always?
PR needs rebase. 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 kubernetes-sigs/prow repository. |
96c89a1
to
0a659c8
Compare
0a659c8
to
80133c9
Compare
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
80133c9
to
e3f29e6
Compare
Signed-off-by: Ryan Leung <[email protected]>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Ryan Leung <[email protected]>
What problem does this PR solve?
Issue Number: ref #8477
What is changed and how does it work?
Check List
Tests
Release note