From c1b8865e6a7d567a22fd7fceeed9ccbb62a2064c Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 19 Jul 2024 18:19:30 +0800 Subject: [PATCH] This is an automated cherry-pick of #8415 close tikv/pd#8419 Signed-off-by: ti-chi-bot --- pkg/keyspace/keyspace.go | 9 ++++++-- pkg/schedule/labeler/rules.go | 36 ++++++++++++++++++++++++++++++++ server/cluster/cluster_worker.go | 4 ++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/pkg/keyspace/keyspace.go b/pkg/keyspace/keyspace.go index 1607676a37b..9eba14786d9 100644 --- a/pkg/keyspace/keyspace.go +++ b/pkg/keyspace/keyspace.go @@ -31,6 +31,11 @@ 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" ) @@ -331,7 +336,7 @@ func (manager *Manager) splitKeyspaceRegion(id uint32, waitRegionSplit bool) (er if waitRegionSplit { ranges := keyspaceRule.Data.([]*labeler.KeyRangeRule) if len(ranges) < 2 { - log.Warn("[keyspace] failed to split keyspace region with insufficient range", zap.Any("label-rule", keyspaceRule)) + 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 @@ -380,7 +385,7 @@ func (manager *Manager) splitKeyspaceRegion(id uint32, waitRegionSplit bool) (er log.Info("[keyspace] added region label for keyspace", zap.Uint32("keyspace-id", id), - zap.Any("label-rule", keyspaceRule), + logutil.ZapRedactString("label-rule", keyspaceRule.String()), zap.Duration("takes", time.Since(start)), ) return diff --git a/pkg/schedule/labeler/rules.go b/pkg/schedule/labeler/rules.go index 5726a9f904e..d3359c2e330 100644 --- a/pkg/schedule/labeler/rules.go +++ b/pkg/schedule/labeler/rules.go @@ -20,6 +20,7 @@ import ( "encoding/json" "fmt" "reflect" + "strings" "time" "github.com/pingcap/failpoint" @@ -38,6 +39,10 @@ type RegionLabel struct { expire *time.Time } +func (l *RegionLabel) String() string { + return fmt.Sprintf("key: %s, value: %s", l.Key, l.Value) +} + // LabelRule is the rule to assign labels to a region. // NOTE: This type is exported by HTTP API. Please pay more attention when modifying it. type LabelRule struct { @@ -49,6 +54,37 @@ type LabelRule struct { minExpire *time.Time } +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)) + b.WriteString(", labels: ") + for i, l := range rule.Labels { + if i == 0 { + b.WriteString("[") + } + b.WriteString(l.String()) + if i == len(rule.Labels)-1 { + b.WriteString("]") + } else { + b.WriteString(", ") + } + } + b.WriteString(", data: ") + ranges := rule.Data.([]*KeyRangeRule) + for i, r := range ranges { + if i == 0 { + b.WriteString("[") + } + b.WriteString(fmt.Sprintf("startKey: {%s}, endKey: {%s}", r.StartKeyHex, r.EndKeyHex)) + if i == len(ranges)-1 { + b.WriteString("]") + } else { + b.WriteString(", ") + } + } + return b.String() +} + // NewLabelRuleFromJSON creates a label rule from the JSON data. func NewLabelRuleFromJSON(data []byte) (*LabelRule, error) { lr := &LabelRule{} diff --git a/server/cluster/cluster_worker.go b/server/cluster/cluster_worker.go index 781b3079703..3980803bb21 100644 --- a/server/cluster/cluster_worker.go +++ b/server/cluster/cluster_worker.go @@ -227,7 +227,7 @@ func (c *RaftCluster) HandleBatchReportSplit(request *pdpb.ReportBatchSplitReque err := c.checkSplitRegions(regions) if err != nil { log.Warn("report batch split region is invalid", - zap.Stringer("region-meta", hrm), + logutil.ZapRedactStringer("region-meta", hrm), errs.ZapError(err)) return nil, err } @@ -236,7 +236,7 @@ func (c *RaftCluster) HandleBatchReportSplit(request *pdpb.ReportBatchSplitReque hrm = core.RegionsToHexMeta(regions[:last]) log.Info("region batch split, generate new regions", zap.Uint64("region-id", originRegion.GetId()), - zap.Stringer("origin", hrm), + logutil.ZapRedactStringer("origin", hrm), zap.Int("total", last)) return &pdpb.ReportBatchSplitResponse{}, nil }