Skip to content

Commit

Permalink
placement, schedule: add some logs for placement rule and operator (#…
Browse files Browse the repository at this point in the history
…2225) (#2232)

Signed-off-by: disksing <i@disksing.com>
  • Loading branch information
sre-bot authored Mar 12, 2020
1 parent a7b6d4f commit 2fd8085
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions server/cluster/cluster_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (c *RaftCluster) HandleAskSplit(request *pdpb.AskSplitRequest) (*pdpb.AskSp
NewPeerIds: peerIDs,
}

log.Info("alloc ids for region split", zap.Uint64("region-id", newRegionID), zap.Uint64s("peer-ids", peerIDs))

return split, nil
}

Expand Down Expand Up @@ -124,6 +126,8 @@ func (c *RaftCluster) HandleAskBatchSplit(request *pdpb.AskBatchSplitRequest) (*
NewRegionId: newRegionID,
NewPeerIds: peerIDs,
})

log.Info("alloc ids for region split", zap.Uint64("region-id", newRegionID), zap.Uint64s("peer-ids", peerIDs))
}

recordRegions = append(recordRegions, reqRegion.GetId())
Expand Down
12 changes: 10 additions & 2 deletions server/schedule/operator/create_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package operator

import (
"encoding/hex"
"fmt"
"math/rand"

Expand Down Expand Up @@ -82,8 +83,15 @@ func CreateSplitRegionOperator(desc string, region *core.RegionInfo, kind OpKind
Policy: policy,
SplitKeys: keys,
}
brief := fmt.Sprintf("split: region %v", region.GetID())
return NewOperator(desc, brief, region.GetID(), region.GetRegionEpoch(), kind, step)
brief := fmt.Sprintf("split: region %v use policy %s", region.GetID(), policy)
if len(keys) > 0 {
hexKeys := make([]string, len(keys))
for i := range keys {
hexKeys[i] = hex.EncodeToString(keys[i])
}
brief += fmt.Sprintf(" and keys %v", hexKeys)
}
return NewOperator(desc, brief, region.GetID(), region.GetRegionEpoch(), kind|OpSplit, step)
}

// CreateMergeRegionOperator creates an operator that merge two region into one.
Expand Down
3 changes: 3 additions & 0 deletions server/schedule/operator/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type OpKind uint32
const (
OpLeader OpKind = 1 << iota // Include leader transfer.
OpRegion // Include peer movement.
OpSplit // Include region split.
OpAdmin // Initiated by admin.
OpHotRegion // Initiated by hot region scheduler.
OpAdjacent // Initiated by adjacent region scheduler.
Expand All @@ -39,6 +40,7 @@ const (
var flagToName = map[OpKind]string{
OpLeader: "leader",
OpRegion: "region",
OpSplit: "split",
OpAdmin: "admin",
OpHotRegion: "hot-region",
OpAdjacent: "adjacent",
Expand All @@ -51,6 +53,7 @@ var flagToName = map[OpKind]string{
var nameToFlag = map[string]OpKind{
"leader": OpLeader,
"region": OpRegion,
"split": OpSplit,
"admin": OpAdmin,
"hot-region": OpHotRegion,
"adjacent": OpAdjacent,
Expand Down
6 changes: 6 additions & 0 deletions server/schedule/placement/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package placement

import (
"encoding/hex"
"encoding/json"
"sort"
)

Expand Down Expand Up @@ -54,6 +55,11 @@ type Rule struct {
LocationLabels []string `json:"location_labels,omitempty"` // used to make peers isolated physically
}

func (r Rule) String() string {
b, _ := json.Marshal(r)
return string(b)
}

// Key returns (groupID, ID) as the global unique key of a rule.
func (r Rule) Key() [2]string {
return [2]string{r.GroupID, r.ID}
Expand Down
3 changes: 3 additions & 0 deletions server/schedule/placement/rule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ func (m *RuleManager) SetRule(rule *Rule) error {
}
return err
}

log.Info("placement rule updated", zap.Stringer("rule", rule))
m.ruleList = buildRuleList(m.rules)
return nil
}
Expand All @@ -197,6 +199,7 @@ func (m *RuleManager) DeleteRule(group, id string) error {
m.rules[key] = old
return err
}
log.Info("placement rule removed", zap.Stringer("rule", old))
m.ruleList = buildRuleList(m.rules)
return nil
}
Expand Down

0 comments on commit 2fd8085

Please sign in to comment.