Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Dec 11, 2024
1 parent 70bb1e1 commit 36973b8
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 137 deletions.
15 changes: 2 additions & 13 deletions pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,14 @@ type Cluster struct {
func NewCluster(ctx context.Context, opts *config.PersistOptions) *Cluster {
bc := core.NewBasicCluster()
c := &Cluster{
<<<<<<< HEAD
ctx: ctx,
BasicCluster: core.NewBasicCluster(),
BasicCluster: bc,
IDAllocator: mockid.NewIDAllocator(),
HotStat: statistics.NewHotStat(ctx),
HotStat: statistics.NewHotStat(ctx, bc),
HotBucketCache: buckets.NewBucketsCache(ctx),
PersistOptions: opts,
suspectRegions: map[uint64]struct{}{},
Storage: storage.NewStorageWithMemoryBackend(),
=======
ctx: ctx,
BasicCluster: bc,
IDAllocator: mockid.NewIDAllocator(),
HotStat: statistics.NewHotStat(ctx, bc),
HotBucketCache: buckets.NewBucketsCache(ctx),
PersistOptions: opts,
pendingProcessedRegions: map[uint64]struct{}{},
Storage: storage.NewStorageWithMemoryBackend(),
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
}
if c.PersistOptions.GetReplicationConfig().EnablePlacementRules {
c.initRuleManager()
Expand Down
21 changes: 6 additions & 15 deletions pkg/schedule/schedulers/hot_region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1657,13 +1657,10 @@ func TestHotCacheUpdateCache(t *testing.T) {
re := require.New(t)
cancel, _, tc, _ := prepareSchedulersTest()
defer cancel()
<<<<<<< HEAD
tc.SetHotRegionCacheHitsThreshold(0)
=======
for i := range 3 {
for i := 0; i < 3; i++ {
tc.PutStore(core.NewStoreInfo(&metapb.Store{Id: uint64(i + 1)}))
}
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))

// For read flow
addRegionInfo(tc, utils.Read, []testRegionInfo{
Expand Down Expand Up @@ -1730,13 +1727,10 @@ func TestHotCacheKeyThresholds(t *testing.T) {
{ // only a few regions
cancel, _, tc, _ := prepareSchedulersTest()
defer cancel()
<<<<<<< HEAD
tc.SetHotRegionCacheHitsThreshold(0)
=======
for i := range 6 {
for i := 0; i < 6; i++ {
tc.PutStore(core.NewStoreInfo(&metapb.Store{Id: uint64(i + 1)}))
}
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
addRegionInfo(tc, utils.Read, []testRegionInfo{
{1, []uint64{1, 2, 3}, 0, 1, 0},
{2, []uint64{1, 2, 3}, 0, 1 * units.KiB, 0},
Expand All @@ -1755,7 +1749,7 @@ func TestHotCacheKeyThresholds(t *testing.T) {
{ // many regions
cancel, _, tc, _ := prepareSchedulersTest()
defer cancel()
for i := range 3 {
for i := 0; i < 3; i++ {
tc.PutStore(core.NewStoreInfo(&metapb.Store{Id: uint64(i + 1)}))
}
regions := []testRegionInfo{}
Expand Down Expand Up @@ -1811,13 +1805,10 @@ func TestHotCacheByteAndKey(t *testing.T) {
re := require.New(t)
cancel, _, tc, _ := prepareSchedulersTest()
defer cancel()
<<<<<<< HEAD
tc.SetHotRegionCacheHitsThreshold(0)
=======
for i := range 3 {
for i := 0; i < 3; i++ {
tc.PutStore(core.NewStoreInfo(&metapb.Store{Id: uint64(i + 1)}))
}
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
statistics.ThresholdsUpdateInterval = 0
defer func() {
statistics.ThresholdsUpdateInterval = 8 * time.Second
Expand Down Expand Up @@ -1944,7 +1935,7 @@ func TestHotCacheCheckRegionFlow(t *testing.T) {
func checkHotCacheCheckRegionFlow(re *require.Assertions, testCase testHotCacheCheckRegionFlowCase, enablePlacementRules bool) {
cancel, _, tc, oc := prepareSchedulersTest()
defer cancel()
for i := range 3 {
for i := 0; i < 3; i++ {
tc.PutStore(core.NewStoreInfo(&metapb.Store{Id: uint64(i + 1)}))
}
tc.SetClusterVersion(versioninfo.MinSupportedVersion(versioninfo.Version4_0))
Expand Down Expand Up @@ -2022,7 +2013,7 @@ func TestHotCacheCheckRegionFlowWithDifferentThreshold(t *testing.T) {
func checkHotCacheCheckRegionFlowWithDifferentThreshold(re *require.Assertions, enablePlacementRules bool) {
cancel, _, tc, _ := prepareSchedulersTest()
defer cancel()
for i := range 3 {
for i := 0; i < 3; i++ {
tc.PutStore(core.NewStoreInfo(&metapb.Store{Id: uint64(i + 1)}))
}
tc.SetClusterVersion(versioninfo.MinSupportedVersion(versioninfo.Version4_0))
Expand Down
40 changes: 0 additions & 40 deletions pkg/statistics/hot_cache_test.go

This file was deleted.

10 changes: 2 additions & 8 deletions pkg/statistics/hot_peer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,9 @@ type hotPeerCache struct {
lastGCTime time.Time
}

<<<<<<< HEAD
// NewHotPeerCache creates a hotPeerCache
func NewHotPeerCache(ctx context.Context, kind utils.RWType) *hotPeerCache {
func NewHotPeerCache(ctx context.Context, cluster *core.BasicCluster, kind utils.RWType) *hotPeerCache {
return &hotPeerCache{
=======
// NewHotPeerCache creates a HotPeerCache
func NewHotPeerCache(ctx context.Context, cluster *core.BasicCluster, kind utils.RWType) *HotPeerCache {
return &HotPeerCache{
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
kind: kind,
cluster: cluster,
peersOfStore: make(map[uint64]*utils.TopN),
Expand Down Expand Up @@ -553,7 +547,7 @@ func (f *hotPeerCache) removeItem(item *HotPeerStat) {
}
}

func (f *HotPeerCache) gc() {
func (f *hotPeerCache) gc() {
if time.Since(f.lastGCTime) < f.topNTTL {
return
}
Expand Down
41 changes: 6 additions & 35 deletions pkg/statistics/hot_peer_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ import (
"github.com/tikv/pd/pkg/utils/typeutil"
)

<<<<<<< HEAD
func TestStoreTimeUnsync(t *testing.T) {
re := require.New(t)
cache := NewHotPeerCache(context.Background(), utils.Write)
intervals := []uint64{120, 60}
for _, interval := range intervals {
region := buildRegion(utils.Write, 3, interval)
checkAndUpdate(re, cache, region, 3)
{
stats := cache.RegionStats(0)
re.Len(stats, 3)
for _, s := range stats {
re.Len(s, 1)
}
}
}
}

=======
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
type operator int

const (
Expand Down Expand Up @@ -272,7 +252,7 @@ func getIDAllocator() *mockid.IDAllocator {

func buildRegion(cluster *core.BasicCluster, kind utils.RWType, peerCount int, interval uint64) (region *core.RegionInfo) {
peers := make([]*metapb.Peer, 0, peerCount)
for range peerCount {
for i := 0; i < peerCount; i++ {
id, _ := getIDAllocator().Alloc()
storeID, _ := getIDAllocator().Alloc()
peers = append(peers, &metapb.Peer{
Expand Down Expand Up @@ -698,12 +678,8 @@ func TestHotPeerCacheTopNThreshold(t *testing.T) {
cluster := core.NewBasicCluster()
cache := NewHotPeerCache(context.Background(), cluster, utils.Write)
now := time.Now()
<<<<<<< HEAD
for id := uint64(0); id < 100; id++ {
=======
storeID := uint64(1)
for id := range uint64(100) {
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
for id := uint64(0); id < 100; id++ {
meta := &metapb.Region{
Id: id,
Peers: []*metapb.Peer{{Id: id, StoreId: storeID}},
Expand Down Expand Up @@ -778,7 +754,7 @@ func TestDifferentReportInterval(t *testing.T) {
for _, interval := range []uint64{120, 60, 30} {
region = region.Clone(core.SetReportInterval(0, interval))
checkAndUpdate(re, cache, region, 3)
stats := cache.GetHotPeerStats(0)
stats := cache.RegionStats(0)
re.Len(stats, 3)
for _, s := range stats {
re.Len(s, 1)
Expand All @@ -787,19 +763,14 @@ func TestDifferentReportInterval(t *testing.T) {
}

func BenchmarkCheckRegionFlow(b *testing.B) {
<<<<<<< HEAD
cache := NewHotPeerCache(context.Background(), utils.Read)
region := buildRegion(utils.Read, 3, 10)
cluster := core.NewBasicCluster()
cache := NewHotPeerCache(context.Background(), cluster, utils.Read)
region := buildRegion(cluster, utils.Read, 3, 10)
peerInfos := make([]*core.PeerInfo, 0)
for _, peer := range region.GetPeers() {
peerInfo := core.NewPeerInfo(peer, region.GetLoads(), 10)
peerInfos = append(peerInfos, peerInfo)
}
=======
cluster := core.NewBasicCluster()
cache := NewHotPeerCache(context.Background(), cluster, utils.Read)
region := buildRegion(cluster, utils.Read, 3, 10)
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
b.ResetTimer()
for i := 0; i < b.N; i++ {
items := make([]*HotPeerStat, 0)
Expand Down
21 changes: 2 additions & 19 deletions pkg/statistics/utils/topn.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ func (tn *TopN) Put(item TopNItem) (isUpdate bool) {
for _, stn := range tn.topns {
isUpdate = stn.Put(item)
}
<<<<<<< HEAD
tn.ttlLst.Put(item.ID())
tn.maintain()
=======
tn.ttlLst.put(item.ID())
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
return
}

Expand All @@ -119,28 +114,16 @@ func (tn *TopN) Remove(id uint64) (item TopNItem) {
for _, stn := range tn.topns {
item = stn.Remove(id)
}
<<<<<<< HEAD
_ = tn.ttlLst.Remove(id)
tn.maintain()
return
}

func (tn *TopN) maintain() {
for _, id := range tn.ttlLst.TakeExpired() {
for _, stn := range tn.topns {
stn.Remove(id)
=======
_ = tn.ttlLst.remove(id)
return
}

func (tn *TopN) maintain() []uint64 {
ids := make([]uint64, 0)
for _, id := range tn.ttlLst.takeExpired() {
for _, id := range tn.ttlLst.TakeExpired() {
for _, stn := range tn.topns {
stn.remove(id)
stn.Remove(id)
ids = append(ids, id)
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
}
}
return ids
Expand Down
2 changes: 1 addition & 1 deletion server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func TestRegionHeartbeatHotStat(t *testing.T) {
cluster.coordinator = schedule.NewCoordinator(ctx, cluster, nil)
stores := newTestStores(4, "2.0.0")
for _, store := range stores {
cluster.PutStore(store)
cluster.PutStore(store.GetMeta())
}
peers := []*metapb.Peer{
{
Expand Down
7 changes: 1 addition & 6 deletions server/cluster/scheduling_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,8 @@ func newSchedulingController(parentCtx context.Context, basicCluster *core.Basic
BasicCluster: basicCluster,
opt: opt,
labelStats: statistics.NewLabelStatistics(),
<<<<<<< HEAD
hotStat: statistics.NewHotStat(parentCtx),
slowStat: statistics.NewSlowStat(parentCtx),
=======
hotStat: statistics.NewHotStat(parentCtx, basicCluster),
slowStat: statistics.NewSlowStat(),
>>>>>>> 20087e290 (statistics: add gc in hot peer cache (#8702))
slowStat: statistics.NewSlowStat(parentCtx),
regionStats: statistics.NewRegionStatistics(basicCluster, opt, ruleManager),
}
}
Expand Down

0 comments on commit 36973b8

Please sign in to comment.