-
Notifications
You must be signed in to change notification settings - Fork 289
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
perf: optimize get tso frequency #801
Conversation
cdc/kv/client.go
Outdated
@@ -251,6 +252,8 @@ type CDCClient struct { | |||
|
|||
regionCache *tikv.RegionCache | |||
kvStorage tikv.Storage | |||
|
|||
currentVersionCache tidbkv.Version |
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.
currentVersionCache tidbkv.Version | |
currentVersionCache model.Ts |
cdc/kv/client.go
Outdated
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-ticker.C: |
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 there is no region to resolve lock, we still query the tso from pd every two seconds?
cdc/kv/client.go
Outdated
// GetCurrentVersion gets a cached version that is regularly updated by a background goroutine | ||
func (c *CDCClient) GetCurrentVersion() tidbkv.Version { | ||
for atomic.LoadUint64(&c.currentVersionCache.Ver) == 0 { | ||
time.Sleep(1 * time.Second) |
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 graceful
cdc/kv/client.go
Outdated
@@ -286,6 +308,14 @@ func (c *CDCClient) Close() error { | |||
return nil | |||
} | |||
|
|||
// GetCurrentVersion gets a cached version that is regularly updated by a background goroutine | |||
func (c *CDCClient) GetCurrentVersion() tidbkv.Version { |
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.
How many CDCClient would CDC create? How about caching the TS in the processor?
fb3f770
to
5c722b0
Compare
/run-all-tests |
cdc/puller/puller.go
Outdated
return tidbkv.Version{Ver: ver}, nil | ||
} | ||
|
||
func (s *kvStorageWithVersionCache) Close() error { |
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.
Where is the Close
called
cdc/puller/puller.go
Outdated
@@ -15,6 +15,7 @@ package puller | |||
|
|||
import ( | |||
"context" | |||
"github.com/pingcap/ticdc/pkg/notify" |
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.
Please move this import to the group of third-party lib
cdc/puller/puller.go
Outdated
@@ -69,6 +166,7 @@ func NewPuller( | |||
spans []regionspan.Span, | |||
limitter *BlurResourceLimitter, | |||
) Puller { | |||
kvStorage = newKvStorageWithVersionCache(kvStorage) |
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.
KvStorageWithVersionCache
should be globally unique, not one per puller.
/run-all-tests |
2 similar comments
/run-all-tests |
/run-all-tests |
ccdae04
to
c1dc174
Compare
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #801 +/- ##
===========================================
Coverage 32.4447% 32.4447%
===========================================
Files 96 96
Lines 10541 10541
===========================================
Hits 3420 3420
Misses 6780 6780
Partials 341 341 |
/run-all-tests |
1 similar comment
/run-all-tests |
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.
/lgtm
/merge |
/run-all-tests |
What problem does this PR solve?
Querying CurrentVersion too frequently when resolving lock. #790
What is changed and how it works?
CurrentVersion is now cached and is updated regularly by a separate goroutine.
Check List
Tests
Code changes
Release note