-
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
*: use txn for saving timestamp #6199
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
a7a59b2
to
087c36d
Compare
/merge |
@JmPotato: 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. |
This pull request has been accepted and is ready to merge. Commit hash: 087c36d
|
Signed-off-by: Ryan Leung <rleungx@gmail.com>
ci failed |
/hold |
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.
left a few comments.
pkg/storage/endpoint/tso.go
Outdated
func (se *StorageEndpoint) SaveTimestamp(prefix string, key string, ts time.Time) error { | ||
return se.RunInTxn(context.Background(), func(txn kv.Txn) error { | ||
prefixEnd := clientv3.GetPrefixRangeEnd(prefix) | ||
keys, values, err := txn.LoadRange(prefix, prefixEnd, 0) |
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 my understanding is correct, for global location, we use '/pd/[cluster-id]' to do prefix scan, but there are a lot of things, under this path, irrelevant to tso. In order to "“LoadTimestamp will get all time windows of Local/Global TSOs from etcd and return the biggest one.”, shall we use the /pd//timestamp/ for local TSOs?
pkg/storage/endpoint/tso.go
Outdated
previousTS := typeutil.ZeroTime | ||
for i, key := range keys { | ||
key := strings.TrimSpace(key) | ||
if !strings.HasSuffix(key, timestampKey) { |
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.
Isn't this condition "!strings.HasSuffix(key, timestampKey)" too loose, considering we're using "/pd/[cluster-id]" to do prefix range scan? Could there be chance that 'timestamp' suffix are added to the path for other use cases?
return nil | ||
} | ||
data := typeutil.Uint64ToBytes(uint64(ts.UnixNano())) | ||
return txn.Save(key, string(data)) |
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.
Because LoadTimestamp() use the logic to do prefix scan then return the largest timestamp among all timestamps, it seems that we don't need the whole change in this pr -- tso service doesn't need to use the same path as pd's but the same prefix for timestamp range scan, then anyway LoadTimestamp() will return the largest one among the last writes of pd and tso service. Thus we can avoid using the expensive transaction here.
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.
With this transaction, we scan all the dir and sub-dir of /pd/【cluster-id】 in a transaction, which is too expensive.
Signed-off-by: Ryan Leung <rleungx@gmail.com>
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
return nil | ||
} | ||
data := typeutil.Uint64ToBytes(uint64(ts.UnixNano())) | ||
return txn.Save(key, string(data)) |
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.
With this transaction, we scan all the dir and sub-dir of /pd/【cluster-id】 in a transaction, which is too expensive.
} | ||
data := typeutil.Uint64ToBytes(uint64(ts.UnixNano())) | ||
return txn.Save(key, string(data)) | ||
}) |
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.
Without this pr,even LoadTimestamp is invoked only once after it becomes the leader/primary,when we switch service mode, we need to ensure the it campaigns to be the leader/primary then invoke LoadTimestamp() to load the largest one among the last writes of pd and tso service which use the same prefix but different paths.
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.
already change to Load
which will only get one key.
} | ||
|
||
previousTS := typeutil.ZeroTime | ||
if value != "" { |
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 value != "" { | |
if len(value) > 0 { |
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.
I think there is not much difference.
pkg/storage/endpoint/tso.go
Outdated
} | ||
} | ||
if previousTS != typeutil.ZeroTime && typeutil.SubRealTimeByWallClock(ts, previousTS) <= 0 { | ||
log.Warn("save timestamp failed, the timestamp is not bigger than the previous one", zap.Time("previous", previousTS), zap.Time("current", ts)) |
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.
Do we need this log line? It seems to be a normal case.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #6199 +/- ##
==========================================
+ Coverage 74.77% 74.81% +0.04%
==========================================
Files 395 395
Lines 38704 38716 +12
==========================================
+ Hits 28939 28966 +27
+ Misses 7232 7225 -7
+ Partials 2533 2525 -8
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 22 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. |
/hold cancel |
/merge |
@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. |
This pull request has been accepted and is ready to merge. Commit hash: d491ede
|
@rleungx: Your PR was out of date, I have automatically updated it for you. If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. 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. |
ci failed |
/hold |
/hold cancel |
What problem does this PR solve?
Issue Number: Ref #5895.
What is changed and how does it work?
This PR supports using Txn to save the timestamp to prevent TSO from falling back when two places advance at the same time.
Check List
Tests
Release note