Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Jun 12, 2024
1 parent 7f61697 commit b2a676e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
1 change: 1 addition & 0 deletions tools/pd-simulator/simulator/cases/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var IDAllocator idAllocator
var CaseMap = map[string]func(*config.SimConfig) *Case{
"balance-leader": newBalanceLeader,
"redundant-balance-region": newRedundantBalanceRegion,
"scale-in-out": newScaleInOut,
"region-split": newRegionSplit,
"region-merge": newRegionMerge,
"hot-read": newHotRead,
Expand Down
36 changes: 20 additions & 16 deletions tools/pd-simulator/simulator/cases/scale_tikv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 TiKV Project Authors.
// 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.
Expand All @@ -17,20 +17,22 @@ package cases
import (
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/tikv/pd/pkg/core"
sc "github.com/tikv/pd/tools/pd-simulator/simulator/config"
"github.com/tikv/pd/tools/pd-simulator/simulator/info"
"github.com/tikv/pd/tools/pd-simulator/simulator/simutil"
)

func newScaleInOut() *Case {
func newScaleInOut(config *sc.SimConfig) *Case {
var simCase Case

storeNum := simutil.CaseConfigure.StoreNum
regionNum := simutil.CaseConfigure.RegionNum
if storeNum == 0 || regionNum == 0 {
storeNum, regionNum = 6, 4000
totalStore := config.TotalStore
totalRegion := config.TotalRegion
replica := int(config.ServerConfig.Replication.MaxReplicas)
if totalStore == 0 || totalRegion == 0 {
totalStore, totalRegion = 6, 4000
}

for i := 0; i < storeNum; i++ {
for i := 0; i < totalStore; i++ {
s := &Store{
ID: IDAllocator.nextID(),
Status: metapb.StoreState_Up,
Expand All @@ -41,11 +43,13 @@ func newScaleInOut() *Case {
simCase.Stores = append(simCase.Stores, s)
}

for i := 0; i < regionNum; i++ {
peers := []*metapb.Peer{
{Id: IDAllocator.nextID(), StoreId: uint64(i%storeNum + 1)},
{Id: IDAllocator.nextID(), StoreId: uint64((i+1)%storeNum + 1)},
{Id: IDAllocator.nextID(), StoreId: uint64((i+2)%storeNum + 1)},
for i := 0; i < totalRegion; i++ {
peers := make([]*metapb.Peer, 0, replica)
for j := 0; j < replica; j++ {
peers = append(peers, &metapb.Peer{
Id: simutil.IDAllocator.NextID(),
StoreId: uint64((i+j)%totalStore + 1),
})
}
simCase.Regions = append(simCase.Regions, Region{
ID: IDAllocator.nextID(),
Expand All @@ -54,25 +58,25 @@ func newScaleInOut() *Case {
})
}

scaleInTick := int64(regionNum * 3 / storeNum)
scaleInTick := int64(totalRegion * 3 / totalStore)
addEvent := &AddNodesDescriptor{}
addEvent.Step = func(tick int64) uint64 {
if tick == scaleInTick {
return uint64(storeNum + 1)
return uint64(totalStore + 1)
}
return 0
}

removeEvent := &DeleteNodesDescriptor{}
removeEvent.Step = func(tick int64) uint64 {
if tick == scaleInTick*2 {
return uint64(storeNum + 1)
return uint64(totalStore + 1)
}
return 0
}
simCase.Events = []EventDescriptor{addEvent, removeEvent}

simCase.Checker = func(regions *core.RegionsInfo, stats []info.StoreStats) bool {
simCase.Checker = func(_ *core.RegionsInfo, _ []info.StoreStats) bool {
return false
}
return &simCase
Expand Down
1 change: 0 additions & 1 deletion tools/pd-simulator/simulator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func NewNode(s *cases.Store, pdAddr string, config *sc.SimConfig) (*Node, error)
StoreStats: pdpb.StoreStats{
StoreId: s.ID,
Capacity: uint64(config.RaftStore.Capacity),
Available: uint64(config.RaftStore.Capacity),
StartTime: uint32(time.Now().Unix()),
Available: uint64(config.RaftStore.Capacity),
},
Expand Down

0 comments on commit b2a676e

Please sign in to comment.