-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mcs: pick some updates and bug fixes (tikv#256)
* etcdutil, mcs: fix the issue loading label rules is too slow (tikv#7718) Signed-off-by: lhy1024 <[email protected]> * ci: run `make check` with longer timeout (tikv#7271) ref tikv#4399 Signed-off-by: lhy1024 <[email protected]> * mcs: add a switch to dynamically enable scheduling service (tikv#7595) ref tikv#5839 Signed-off-by: Ryan Leung <[email protected]> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> * schedule: prevent suddenly scheduling (tikv#7714) ref tikv#7671 Signed-off-by: Ryan Leung <[email protected]> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> * makefile: update golangci (tikv#7556) close tikv#7551 Signed-off-by: husharp <[email protected]> * fix conflict Signed-off-by: lhy1024 <[email protected]> --------- Signed-off-by: lhy1024 <[email protected]> Signed-off-by: husharp <[email protected]> Co-authored-by: Ryan Leung <[email protected]> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> Co-authored-by: Hu# <[email protected]>
- Loading branch information
1 parent
19a7726
commit 5bf0c14
Showing
23 changed files
with
443 additions
and
121 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2024 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package rule | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tikv/pd/pkg/keyspace" | ||
"github.com/tikv/pd/pkg/schedule/labeler" | ||
"github.com/tikv/pd/pkg/storage/endpoint" | ||
"github.com/tikv/pd/pkg/storage/kv" | ||
"github.com/tikv/pd/pkg/utils/etcdutil" | ||
"go.etcd.io/etcd/clientv3" | ||
"go.etcd.io/etcd/embed" | ||
) | ||
|
||
const ( | ||
clusterID = uint64(20240117) | ||
rulesNum = 16384 | ||
) | ||
|
||
func TestLoadLargeRules(t *testing.T) { | ||
re := require.New(t) | ||
ctx, client, clean := prepare(t) | ||
defer clean() | ||
runWatcherLoadLabelRule(ctx, re, client) | ||
} | ||
|
||
func BenchmarkLoadLargeRules(b *testing.B) { | ||
re := require.New(b) | ||
ctx, client, clean := prepare(b) | ||
defer clean() | ||
|
||
b.ResetTimer() // Resets the timer to ignore initialization time in the benchmark | ||
|
||
for n := 0; n < b.N; n++ { | ||
runWatcherLoadLabelRule(ctx, re, client) | ||
} | ||
} | ||
|
||
func runWatcherLoadLabelRule(ctx context.Context, re *require.Assertions, client *clientv3.Client) { | ||
storage := endpoint.NewStorageEndpoint(kv.NewMemoryKV(), nil) | ||
labelerManager, err := labeler.NewRegionLabeler(ctx, storage, time.Hour) | ||
re.NoError(err) | ||
ctx, cancel := context.WithCancel(ctx) | ||
rw := &Watcher{ | ||
ctx: ctx, | ||
cancel: cancel, | ||
rulesPathPrefix: endpoint.RulesPathPrefix(clusterID), | ||
ruleCommonPathPrefix: endpoint.RuleCommonPathPrefix(clusterID), | ||
ruleGroupPathPrefix: endpoint.RuleGroupPathPrefix(clusterID), | ||
regionLabelPathPrefix: endpoint.RegionLabelPathPrefix(clusterID), | ||
etcdClient: client, | ||
ruleStorage: storage, | ||
regionLabeler: labelerManager, | ||
} | ||
err = rw.initializeRegionLabelWatcher() | ||
re.NoError(err) | ||
re.Len(labelerManager.GetAllLabelRules(), rulesNum) | ||
cancel() | ||
} | ||
|
||
func prepare(t require.TestingT) (context.Context, *clientv3.Client, func()) { | ||
re := require.New(t) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
cfg := etcdutil.NewTestSingleConfig() | ||
cfg.Dir = os.TempDir() + "/test_etcd" | ||
os.RemoveAll(cfg.Dir) | ||
etcd, err := embed.StartEtcd(cfg) | ||
re.NoError(err) | ||
client, err := etcdutil.CreateEtcdClient(nil, cfg.LCUrls) | ||
re.NoError(err) | ||
<-etcd.Server.ReadyNotify() | ||
|
||
for i := 1; i < rulesNum+1; i++ { | ||
rule := &labeler.LabelRule{ | ||
ID: "test_" + strconv.Itoa(i), | ||
Labels: []labeler.RegionLabel{{Key: "test", Value: "test"}}, | ||
RuleType: labeler.KeyRange, | ||
Data: keyspace.MakeKeyRanges(uint32(i), true), | ||
} | ||
value, err := json.Marshal(rule) | ||
re.NoError(err) | ||
key := endpoint.RegionLabelPathPrefix(clusterID) + "/" + rule.ID | ||
_, err = clientv3.NewKV(client).Put(ctx, key, string(value)) | ||
re.NoError(err) | ||
} | ||
|
||
return ctx, client, func() { | ||
cancel() | ||
client.Close() | ||
etcd.Close() | ||
os.RemoveAll(cfg.Dir) | ||
} | ||
} |
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
Oops, something went wrong.