-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
session: support setting tso into session variable "tidb_snapshot" #6749
session: support setting tso into session variable "tidb_snapshot" #6749
Conversation
LGTM |
/run-all-tests |
types/time.go
Outdated
@@ -45,6 +45,10 @@ const ( | |||
TimeFormat = "2006-01-02 15:04:05" | |||
// TimeFSPFormat is time format with fractional seconds precision. | |||
TimeFSPFormat = "2006-01-02 15:04:05.000000" | |||
|
|||
// used for encodinh/decoding tso | |||
physicalShiftBits = 18 |
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.
There is a constant in store/tikv/oracle/oracle.go
. Could we use that one?
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.
DONE
We need to update the related document. |
@shenli PTAL |
sessionctx/variable/varsutil.go
Outdated
|
||
if tso, err2 := strconv.ParseUint(sVal, 10, 64); err2 == nil { | ||
s.SnapshotTS = tso | ||
return errors.Trace(nil) |
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.
return nil
@shenli PTAL |
store/tikv/oracle/oracle.go
Outdated
@@ -48,3 +48,15 @@ func ExtractPhysical(ts uint64) int64 { | |||
func GetPhysical(t time.Time) int64 { | |||
return t.UnixNano() / int64(time.Millisecond) | |||
} | |||
|
|||
// EncodeTso encodes a millisecond into tso. | |||
func EncodeTso(ts int64) uint64 { |
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.
s/Tso/TSO ?
store/tikv/oracle/oracle.go
Outdated
} | ||
|
||
// DecodeTso decodes a tso into a golang's time struct. | ||
func DecodeTso(tso uint64) time.Time { |
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.
Ditto.
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 use this function? Could we remove it?
sessionctx/variable/varsutil.go
Outdated
t, err := types.ParseTime(s.StmtCtx, sVal, mysql.TypeTimestamp, types.MaxFsp) | ||
|
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.
Remove this useless line.
sessionctx/variable/varsutil.go
Outdated
@@ -175,10 +175,18 @@ func setSnapshotTS(s *SessionVars, sVal string) error { | |||
s.SnapshotTS = 0 | |||
return nil | |||
} | |||
|
|||
if tso, err2 := strconv.ParseUint(sVal, 10, 64); err2 == nil { |
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.
s/err2/err ?
@zimulala All comments are addressed. PTAL |
7c78f53
to
e6e88d1
Compare
store/tikv/oracle/oracle.go
Outdated
} | ||
|
||
// DecodeTSO decodes a tso into a golang's time struct. | ||
func DecodeTSO(tso uint64) time.Time { |
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 use this function? Could we remove it?
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
/run-all-tests |
@zhexuany We need to cherry-pick this to the release-2.0 branch. |
confirmed with @WangXiangUSTC, as long as this PR be in part of 2.0.4 release, they are fine with this. |
After this PR,
set @@tidb_snapshot= '400036290571534337'
can be used.