server/schedule/labeler: support ttl for region label#4695
server/schedule/labeler: support ttl for region label#4695ti-chi-bot merged 21 commits intotikv:masterfrom
Conversation
Signed-off-by: shirly <AndreMouche@126.com>
|
[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. DetailsReviewer can indicate their review by submitting an approval review. |
|
/wip |
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Codecov Report
@@ Coverage Diff @@
## master #4695 +/- ##
==========================================
+ Coverage 75.21% 75.24% +0.02%
==========================================
Files 294 294
Lines 28325 28416 +91
==========================================
+ Hits 21306 21382 +76
- Misses 5142 5155 +13
- Partials 1877 1879 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
|
|
||
| var backgroundJobInterval = 10 * time.Second | ||
|
|
||
| const regionLabelGCInterval = time.Hour |
There was a problem hiding this comment.
maybe a shorter time?There is earlistExpireTime, most of the time do not need to do any thing.
There was a problem hiding this comment.
I think we needn't check the earlistExpireTime too frequently because lots of labels expired in 1 hour shouldn't be a normal phenomenon?
|
|
||
| func (l *RegionLabeler) getAndCheckRule(id string, now time.Time) *LabelRule { | ||
| l.Lock() | ||
| defer l.Unlock() |
There was a problem hiding this comment.
can release the lock before save to storage?
There was a problem hiding this comment.
sorry we can't , since the rule is a pointer get from labelRules, Without lock it could be updated in the other goroutine(s) which is not thread safe.
| l.RLock() | ||
| defer l.RUnlock() | ||
| return l.labelRules[id] | ||
| return l.getAndCheckRule(id, time.Now()) |
There was a problem hiding this comment.
Can we reduce the passing of the now parameter, which currently seems unnecessary?
There was a problem hiding this comment.
sorry, we can't. since we should check if there exist expired labels before return the current rule.
| continue | ||
| } | ||
| if len(rule.Labels) == 0 { | ||
| err = l.storage.DeleteRegionRule(key) |
There was a problem hiding this comment.
What will happen if we fail to delete in storage but successfully in memory?
There was a problem hiding this comment.
It will just log the error info and the iteam wouldn't be deleted until the next restart. However, if there is something wrong with the storage last for long, the restart of the server would be long with too many expired items.
| return rule | ||
| } | ||
| if len(rule.Labels) == 0 { | ||
| l.storage.DeleteRule(id) |
There was a problem hiding this comment.
Here It will do nothing here and the item wouldn't be deleted in the storage until restart. However, if there is something wrong with the storage last for long, the restart of the server would be long with too many expired items.
|
|
||
| labeler.checkAndClearExpiredLabels() | ||
|
|
||
| labeler.RLock() |
There was a problem hiding this comment.
Because there is a goroutine(The GC function) running which may change the labeler.labelRules concurrently
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
Signed-off-by: shirly <AndreMouche@126.com>
|
Manual test: tidb+pd+tikv set region-label with List region-label in tidb-client |
Signed-off-by: shirly <AndreMouche@126.com>
| delete(l.labelRules, id) | ||
| return nil | ||
| } | ||
| l.storage.SaveRegionRule(id, rule) |
There was a problem hiding this comment.
Because there exist expired label which need to be cleared.
| storage: storage, | ||
| labelRules: make(map[string]*LabelRule), | ||
| ctx: ctx, | ||
| minExpire: nil, |
There was a problem hiding this comment.
| minExpire: nil, |
|
/merge |
|
@disksing: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests DetailsInstructions 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. DetailsCommit hash: e73ce60 |
Signed-off-by: shirly AndreMouche@126.com
What problem does this PR solve?
Issue Number: Close #4694
What is changed and how it works?
usage , post a rule with ttl
Check List
Tests
Release note