-
Notifications
You must be signed in to change notification settings - Fork 499
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
Manage hot region label for the tikv created by auto-scaler #1801
Merged
Yisaer
merged 17 commits into
pingcap:master
from
Yisaer:add_label_for_auto_scale_out_tikv
Feb 27, 2020
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b49f33e
add tikv label syncer
610be18
release
f3a87d9
fix bug
023c56d
Merge branch 'master' into add_label_for_auto_scale_out_tikv
Yisaer 5af0d19
Merge branch 'master' into add_label_for_auto_scale_out_tikv
Yisaer d85d4a3
fix lint
f896259
Merge branch 'add_label_for_auto_scale_out_tikv' of https://github.co…
b376524
Merge branch 'master' into add_label_for_auto_scale_out_tikv
Yisaer ed78917
Update pkg/manager/member/tikv_scaler.go
Yisaer 881e5ff
Update pkg/manager/member/tikv_scaler.go
Yisaer 6777dc4
Update tikv_scaler.go
6e563c4
Merge branch 'master' into add_label_for_auto_scale_out_tikv
Yisaer c7b0a19
remove unnecessary method
8083282
Merge branch 'add_label_for_auto_scale_out_tikv' of https://github.co…
d0b205f
goimports
7970691
unify encode func
ed150d2
add todo
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,12 @@ import ( | |
"strconv" | ||
"time" | ||
|
||
"github.com/pingcap/advanced-statefulset/pkg/apis/apps/v1/helper" | ||
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1" | ||
"github.com/pingcap/tidb-operator/pkg/controller" | ||
"github.com/pingcap/tidb-operator/pkg/label" | ||
"github.com/pingcap/tidb-operator/pkg/pdapi" | ||
"github.com/pingcap/tidb-operator/pkg/util" | ||
apps "k8s.io/api/apps/v1" | ||
corelisters "k8s.io/client-go/listers/core/v1" | ||
glog "k8s.io/klog" | ||
|
@@ -48,7 +50,8 @@ func (tsd *tikvScaler) Scale(tc *v1alpha1.TidbCluster, oldSet *apps.StatefulSet, | |
} else if scaling < 0 { | ||
return tsd.ScaleIn(tc, oldSet, newSet) | ||
} | ||
return nil | ||
// we only sync auto scaler annotations when we are finishing syncing scaling | ||
return tsd.SyncAutoScalerAnn(tc, oldSet) | ||
} | ||
|
||
func (tsd *tikvScaler) ScaleOut(tc *v1alpha1.TidbCluster, oldSet *apps.StatefulSet, newSet *apps.StatefulSet) error { | ||
|
@@ -190,6 +193,55 @@ func (tsd *tikvScaler) ScaleIn(tc *v1alpha1.TidbCluster, oldSet *apps.StatefulSe | |
return fmt.Errorf("TiKV %s/%s not found in cluster", ns, podName) | ||
} | ||
|
||
// SyncAutoScalerAnn would reclaim the auto-scaling out slots if the target pod is no longer existed | ||
// For the auto-scaling slots, we would add the special hot region label to the store with pdapi. | ||
func (tsd *tikvScaler) SyncAutoScalerAnn(tc *v1alpha1.TidbCluster, actual *apps.StatefulSet) error { | ||
currentScalingSlots := util.GetAutoScalingOutSlots(tc, v1alpha1.TiKVMemberType) | ||
if currentScalingSlots.Len() < 1 { | ||
return nil | ||
} | ||
currentOrdinals := helper.GetPodOrdinals(tc.Spec.TiKV.Replicas, actual) | ||
|
||
// reclaim the auto-scaling out slots if the target pod is no longer existed | ||
if !currentOrdinals.HasAll(currentScalingSlots.List()...) { | ||
reclaimedSlots := currentScalingSlots.Difference(currentOrdinals) | ||
currentScalingSlots = currentScalingSlots.Delete(reclaimedSlots.List()...) | ||
if currentScalingSlots.Len() < 1 { | ||
delete(tc.Annotations, label.AnnTiKVAutoScalingOutOrdinals) | ||
return nil | ||
} | ||
v, err := util.Encode(currentScalingSlots.List()) | ||
if err != nil { | ||
return err | ||
} | ||
tc.Annotations[label.AnnTiKVAutoScalingOutOrdinals] = v | ||
return nil | ||
} | ||
|
||
// For the auto-scaling slots, we would add the special hot region label to the store with pdapi. | ||
pdClient := tsd.pdControl.GetPDClient(pdapi.Namespace(tc.Namespace), tc.Name, *tc.Spec.EnableTLSCluster) | ||
for k := range currentScalingSlots { | ||
podName := util.GetPodName(tc, v1alpha1.TiKVMemberType, k) | ||
for _, store := range tc.Status.TiKV.Stores { | ||
DanielZhangQD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if store.PodName == podName { | ||
id, err := strconv.ParseUint(store.ID, 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
ok, err := pdClient.SetStoreLabels(id, hostRegionLabel) | ||
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. Is it necessary to check if the label is already set? 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. Not necessary. |
||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
return fmt.Errorf("tc[%s/%s]'s pod[%s] failed to add special hot region label", tc.Namespace, tc.Name, podName) | ||
} | ||
break | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
type fakeTiKVScaler struct{} | ||
|
||
// NewFakeTiKVScaler returns a fake tikv Scaler | ||
|
@@ -215,3 +267,7 @@ func (fsd *fakeTiKVScaler) ScaleIn(_ *v1alpha1.TidbCluster, oldSet *apps.Statefu | |
setReplicasAndDeleteSlots(newSet, *oldSet.Spec.Replicas-1, nil) | ||
return nil | ||
} | ||
|
||
func (fsd *fakeTiKVScaler) SyncAutoScalerAnn(tc *v1alpha1.TidbCluster, actual *apps.StatefulSet) error { | ||
return nil | ||
} |
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.
describe the purpose of this special label here? why we need to add this special label on newly created TiKV instances. If PD has public docs about this label, we can link too.
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.
Nice catch, I will add
TODO
to mark there should be some docs about this label after I finish the entire auto-scaling document.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.
great! comments describing the purpose or reason behind will make it easier to understand the code.