You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/tso/allocator.go
+19-14Lines changed: 19 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -43,9 +43,17 @@ import (
43
43
"github.com/tikv/pd/pkg/utils/logutil"
44
44
)
45
45
46
-
// GlobalDCLocation is the Global TSO Allocator's DC location label.
47
-
// Deprecated: This is a legacy label, it should be removed in the future.
48
-
constGlobalDCLocation="global"
46
+
const (
47
+
// GlobalDCLocation is the Global TSO Allocator's DC location label.
48
+
// Deprecated: This is a legacy label, it should be removed in the future.
49
+
GlobalDCLocation="global"
50
+
// maxUpdateTSORetryCount is the max retry count for updating TSO.
51
+
// When encountering a network partition, manually retrying may help the next request succeed with the new endpoint according to https://github.com/etcd-io/etcd/issues/8711
52
+
maxUpdateTSORetryCount=3
53
+
// Etcd client retry with `roundRobinQuorumBackoff` (https://github.com/etcd-io/etcd/blob/d62cdeee4863001b09e772ed013eb1342a1d0f89/client/v3/client.go#L488),
54
+
// whose default interval is 25ms, so we sleep 50ms here. (https://github.com/etcd-io/etcd/blob/d62cdeee4863001b09e772ed013eb1342a1d0f89/client/v3/options.go#L53)
55
+
updateTSORetryInterval=50*time.Millisecond
56
+
)
49
57
50
58
// ElectionMember defines the interface for the election related logic.
51
59
typeElectionMemberinterface {
@@ -175,7 +183,8 @@ func (a *Allocator) allocatorUpdater() {
175
183
iferr:=a.UpdateTSO(); err!=nil {
176
184
log.Warn("failed to update allocator's timestamp", append(a.logFields, errs.ZapError(err))...)
177
185
a.Reset(true)
178
-
return
186
+
// To wait for the allocator to be re-initialized next time.
187
+
continue
179
188
}
180
189
case<-a.ctx.Done():
181
190
a.Reset(false)
@@ -185,9 +194,9 @@ func (a *Allocator) allocatorUpdater() {
185
194
}
186
195
}
187
196
188
-
// close is used to shutdown the primary election loop.
197
+
// Close is used to close the allocator and shutdown all the daemon loops.
189
198
// tso service call this function to shutdown the loop here, but pd manages its own loop.
190
-
func (a*Allocator) close() {
199
+
func (a*Allocator) Close() {
191
200
log.Info("closing the allocator", a.logFields...)
192
201
a.cancel()
193
202
a.wg.Wait()
@@ -207,18 +216,14 @@ func (a *Allocator) IsInitialize() bool {
207
216
208
217
// UpdateTSO is used to update the TSO in memory and the time window in etcd.
209
218
func (a*Allocator) UpdateTSO() (errerror) {
210
-
// When meet network partition, we need to manually retry to update the tso,
211
-
// next request succeeds with the new endpoint, according to https://github.com/etcd-io/etcd/issues/8711
212
-
maxRetryCount:=3
213
-
forrangemaxRetryCount {
219
+
fori:=rangemaxUpdateTSORetryCount {
214
220
err=a.timestampOracle.updateTimestamp()
215
221
iferr==nil {
216
222
returnnil
217
223
}
218
-
log.Warn("try to update the tso but failed", errs.ZapError(err))
219
-
// Etcd client retry with roundRobinQuorumBackoff https://github.com/etcd-io/etcd/blob/d62cdeee4863001b09e772ed013eb1342a1d0f89/client/v3/client.go#L488
220
-
// And its default interval is 25ms, so we sleep 50ms here. https://github.com/etcd-io/etcd/blob/d62cdeee4863001b09e772ed013eb1342a1d0f89/client/v3/options.go#L53
0 commit comments