Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Aug 27, 2024
1 parent dfda826 commit 209a7a9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 77 deletions.
75 changes: 1 addition & 74 deletions pkg/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ import (
"github.com/tikv/pd/pkg/slice"
"github.com/tikv/pd/pkg/storage/endpoint"
"github.com/tikv/pd/pkg/storage/kv"
<<<<<<< HEAD
=======
"github.com/tikv/pd/pkg/utils/etcdutil"
"github.com/tikv/pd/pkg/utils/logutil"
>>>>>>> 2d8e03f33 (*: fix redact log (#8415))
"github.com/tikv/pd/pkg/utils/syncutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -260,87 +256,18 @@ func (manager *Manager) splitKeyspaceRegion(id uint32) error {
if cl, ok := manager.cluster.(interface{ GetRegionLabeler() *labeler.RegionLabeler }); ok {
err := cl.GetRegionLabeler().SetLabelRule(keyspaceRule)
if err != nil {
<<<<<<< HEAD
log.Warn("[keyspace] failed to add region label for keyspace",
zap.Uint32("keyspaceID", id),
zap.Error(err),
)
=======
if err := cl.GetRegionLabeler().DeleteLabelRule(keyspaceRule.ID); err != nil {
log.Warn("[keyspace] failed to delete region label for keyspace",
zap.Uint32("keyspace-id", id),
zap.Error(err),
)
}
}
}()

if waitRegionSplit {
ranges := keyspaceRule.Data.([]*labeler.KeyRangeRule)
if len(ranges) < 2 {
log.Warn("[keyspace] failed to split keyspace region with insufficient range", logutil.ZapRedactString("label-rule", keyspaceRule.String()))
return ErrRegionSplitFailed
}
rawLeftBound, rawRightBound := ranges[0].StartKey, ranges[0].EndKey
txnLeftBound, txnRightBound := ranges[1].StartKey, ranges[1].EndKey

ticker := time.NewTicker(manager.config.GetCheckRegionSplitInterval())
timer := time.NewTimer(manager.config.GetWaitRegionSplitTimeout())
defer func() {
ticker.Stop()
timer.Stop()
}()
for {
select {
case <-ticker.C:
c := manager.cluster.GetBasicCluster()
region := c.GetRegionByKey(rawLeftBound)
if region == nil || !bytes.Equal(region.GetStartKey(), rawLeftBound) {
continue
}
region = c.GetRegionByKey(rawRightBound)
if region == nil || !bytes.Equal(region.GetStartKey(), rawRightBound) {
continue
}
region = c.GetRegionByKey(txnLeftBound)
if region == nil || !bytes.Equal(region.GetStartKey(), txnLeftBound) {
continue
}
region = c.GetRegionByKey(txnRightBound)
if region == nil || !bytes.Equal(region.GetStartKey(), txnRightBound) {
continue
}
// Note: we reset the ticker here to support updating configuration dynamically.
ticker.Reset(manager.config.GetCheckRegionSplitInterval())
case <-timer.C:
log.Warn("[keyspace] wait region split timeout",
zap.Uint32("keyspace-id", id),
zap.Error(err),
)
err = ErrRegionSplitTimeout
return
}
log.Info("[keyspace] wait region split successfully", zap.Uint32("keyspace-id", id))
break
>>>>>>> 2d8e03f33 (*: fix redact log (#8415))
}
log.Info("[keyspace] added region label for keyspace",
zap.Uint32("keyspaceID", id),
zap.Any("LabelRule", keyspaceRule),
logutil.ZapRedactString("label-rule", keyspaceRule.String()),
)
return nil
}
<<<<<<< HEAD
return errors.New("cluster does not support region label")
=======

log.Info("[keyspace] added region label for keyspace",
zap.Uint32("keyspace-id", id),
logutil.ZapRedactString("label-rule", keyspaceRule.String()),
zap.Duration("takes", time.Since(start)),
)
return
>>>>>>> 2d8e03f33 (*: fix redact log (#8415))
}

// LoadKeyspace returns the keyspace specified by name.
Expand Down
4 changes: 1 addition & 3 deletions pkg/schedule/labeler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package labeler
import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -53,8 +54,6 @@ type LabelRule struct {
minExpire *time.Time
}

<<<<<<< HEAD
=======
func (rule *LabelRule) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf("id: %s, index: %d, type: %s", rule.ID, rule.Index, rule.RuleType))
Expand Down Expand Up @@ -96,7 +95,6 @@ func NewLabelRuleFromJSON(data []byte) (*LabelRule, error) {
return lr, nil
}

>>>>>>> 2d8e03f33 (*: fix redact log (#8415))
const (
// KeyRange is the rule type that specifies a list of key ranges.
KeyRange = "key-range"
Expand Down

0 comments on commit 209a7a9

Please sign in to comment.