-
Notifications
You must be signed in to change notification settings - Fork 714
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: Auto fix gc_worker's service safepoint for upgraded clusters #3371
Merged
ti-chi-bot
merged 9 commits into
tikv:master
from
MyonKeminta:m/fix-gc-worker-ssp-for-upgraded-cluster
Jan 26, 2021
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fed4504
server: Auto fix gc_worker's service safepoint for upgraded clusters
MyonKeminta e70877e
format
MyonKeminta 8322306
fix TestLoadMinServiceGCSafePoint
MyonKeminta 96bf381
remove commentted code
MyonKeminta 5db9638
Address comments
MyonKeminta 3b8fa3f
Address comments
MyonKeminta 1903929
Address comments
MyonKeminta 0b05a28
Merge branch 'master' into m/fix-gc-worker-ssp-for-upgraded-cluster
ti-chi-bot 5fb63fc
Merge branch 'master' into m/fix-gc-worker-ssp-for-upgraded-cluster
ti-chi-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -501,10 +501,10 @@ func (s *Storage) RemoveServiceGCSafePoint(serviceID string) error { | |||||
return s.Remove(key) | ||||||
} | ||||||
|
||||||
func (s *Storage) initServiceGCSafePointForGCWorker() (*ServiceSafePoint, error) { | ||||||
func (s *Storage) initServiceGCSafePointForGCWorker(initialValue uint64) (*ServiceSafePoint, error) { | ||||||
ssp := &ServiceSafePoint{ | ||||||
ServiceID: gcWorkerServiceSafePointID, | ||||||
SafePoint: 0, | ||||||
SafePoint: initialValue, | ||||||
ExpiredAt: math.MaxInt64, | ||||||
} | ||||||
if err := s.SaveServiceGCSafePoint(ssp); err != nil { | ||||||
|
@@ -523,25 +523,49 @@ func (s *Storage) LoadMinServiceGCSafePoint(now time.Time) (*ServiceSafePoint, e | |||||
} | ||||||
if len(keys) == 0 { | ||||||
// There's no service safepoint. Store an initial value for GC worker. | ||||||
return s.initServiceGCSafePointForGCWorker() | ||||||
return s.initServiceGCSafePointForGCWorker(0) | ||||||
} | ||||||
|
||||||
min := &ServiceSafePoint{SafePoint: math.MaxUint64} | ||||||
var min uint64 = math.MaxUint64 | ||||||
hasGCWorker := false | ||||||
validMin := &ServiceSafePoint{SafePoint: math.MaxUint64} | ||||||
for i, key := range keys { | ||||||
ssp := &ServiceSafePoint{} | ||||||
if err := json.Unmarshal([]byte(values[i]), ssp); err != nil { | ||||||
return nil, err | ||||||
} | ||||||
if ssp.ServiceID == gcWorkerServiceSafePointID { | ||||||
hasGCWorker = true | ||||||
// If gc_worker's expire time is incorrectly set, fix it. | ||||||
if ssp.ExpiredAt != math.MaxInt64 { | ||||||
ssp.ExpiredAt = math.MaxInt64 | ||||||
err = s.SaveServiceGCSafePoint(ssp) | ||||||
if err != nil { | ||||||
return nil, errors.Trace(err) | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
if ssp.SafePoint < min { | ||||||
min = ssp.SafePoint | ||||||
} | ||||||
|
||||||
if ssp.ExpiredAt < now.Unix() { | ||||||
s.Remove(key) | ||||||
continue | ||||||
} | ||||||
if ssp.SafePoint < min.SafePoint { | ||||||
min = ssp | ||||||
if ssp.SafePoint < validMin.SafePoint { | ||||||
validMin = ssp | ||||||
} | ||||||
} | ||||||
|
||||||
return min, nil | ||||||
if !hasGCWorker { | ||||||
// If there exists some service safepoints but gc_worker is missing, init it with the min value among all | ||||||
// safepoints (including expired ones) | ||||||
return s.initServiceGCSafePointForGCWorker(min) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return validMin, nil | ||||||
} | ||||||
|
||||||
// GetAllServiceGCSafePoints returns all services GC safepoints | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ssp is expired, we may get a wrong
min
here. I suggest deletingmin
and keeping onlyvalidMin
.