-
Notifications
You must be signed in to change notification settings - Fork 726
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
server: alloc timestamp after recover #1173
Conversation
server/tso.go
Outdated
if subTimeByWallClock(last, now)+updateTimestampGuard > 0 { | ||
log.Errorf("system time may be incorrect, last: %v, now: %v", last, now) | ||
s.ts.Store(&atomicObject{physical: last}) | ||
return 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.
I think you want to update now
and save it to etcd.
server/tso.go
Outdated
continue | ||
// If the time window is enough, it will increase the physical time, | ||
// otherwise, it will wait for updating the time window. | ||
if subTimeByWallClock(s.lastSavedTime, current.physical) > updateTimestampGuard { |
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 lastSavedTime
is accessed concurrently without any mutex.
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.
agree.
server/tso.go
Outdated
log.Debugf("save timestamp ok: prev %v last %v save %v", prev, last, save) | ||
// If the time window is no more than updateTimestampGuard, | ||
// it will adjust the time window. | ||
if subTimeByWallClock(saved, now) <= updateTimestampGuard { |
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.
better also validate the TsoSaveInterval
large than updateTimestampGuard
in config.
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.
They are not in the same order of magnitude, and thus it doesn't make much sense. What do you think?
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.
Oh, It's ok. I before thought the updateTimestampGuard
was 1s.
server/tso.go
Outdated
} | ||
// Since the physical timestamp is greater than the current system time, | ||
// the physical timestamp will be used to alloc timestamp temporarily. | ||
current.physical = prev |
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.
The logical part will clean to 0, but you do not increase the physical part.
PTAL @liukun4515 |
server/tso.go
Outdated
physical: current.physical.Add(time.Millisecond), | ||
logical: 0, | ||
} | ||
s.ts.Store(last) |
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.
miss a continue
?
/rebuild |
I think we can refactor
|
154689e
to
2daa77f
Compare
I think we need more detailed comments. |
server/tso.go
Outdated
next = now | ||
} else if atomic.LoadInt64(&prev.logical) > maxLogical/2 { | ||
next = prev.physical.Add(time.Millisecond) | ||
} else { |
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.
tsoCounter.WithLabelValues("skip_save").Inc()
before return nil
server/tso.go
Outdated
if jetLag > updateTimestampGuard { | ||
next = now | ||
} else if atomic.LoadInt64(&prev.logical) > maxLogical/2 { | ||
next = prev.physical.Add(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.
Add warning log here.
server/tso.go
Outdated
// the timestamp allocation will start from the saved etcd timestamp temporarily. | ||
if subTimeByWallClock(next, last) < updateTimestampGuard { | ||
log.Errorf("system time may be incorrect: last: %v next %v", last, next) | ||
next = next.Add(updateTimestampGuard) |
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.
next = last.Add(updateTimestampGuard)
?
Please review this PR carefully. /cc @nolouch @siddontang @liukun4515 |
14ff8f2
to
4e9fd5b
Compare
@disksing PTAL. |
// | ||
// Here is some constraints that this function must satisfy: | ||
// 1. The physical time is monotonically increasing. | ||
// 2. The saved time is monotonically increasing. |
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.
And the physical should always less than saved timestamp.
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
please construct a test for the time fallback. |
3c15dc1
to
8ae950c
Compare
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
why add DNM label again? @rleungx |
There is a concurrency problem in the test. @siddontang |
The test will be added in another PR. I will create it once this PR is merged. |
What have you changed? (required)
This PR allows allocating timestamp after recovering from the incorrect system time.
What are the type of the changes (required)?
How has this PR been tested (required)?
Refer to a related PR or issue link (optional)
#499, #940, pingcap/tidb#5709.
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)