From 33e948941c8a19493fbdfc879ce29ea3d1e97834 Mon Sep 17 00:00:00 2001 From: xhe Date: Sat, 1 Jan 2022 15:53:51 +0800 Subject: [PATCH] placement: remove isolation level and constraints completely (#31189) close pingcap/tidb#31052 --- ddl/placement/bundle_test.go | 2 +- ddl/placement/rule.go | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/ddl/placement/bundle_test.go b/ddl/placement/bundle_test.go index 9309db9d17..94c51795f2 100644 --- a/ddl/placement/bundle_test.go +++ b/ddl/placement/bundle_test.go @@ -352,7 +352,7 @@ func (s *testBundleSuite) TestString(c *C) { c.Assert(err, IsNil) bundle.Rules = append(rules1, rules2...) - c.Assert(bundle.String(), Equals, `{"group_id":"TiDB_DDL_1","group_index":0,"group_override":false,"rules":[{"group_id":"","id":"","start_key":"","end_key":"","role":"voter","count":3,"label_constraints":[{"key":"zone","op":"in","values":["sh"]}],"location_labels":["region","zone","rack","host"]},{"group_id":"","id":"","start_key":"","end_key":"","role":"voter","count":4,"label_constraints":[{"key":"zone","op":"notIn","values":["sh"]},{"key":"zone","op":"in","values":["bj"]}],"location_labels":["region","zone","rack","host"]}]}`) + c.Assert(bundle.String(), Equals, "{\"group_id\":\"TiDB_DDL_1\",\"group_index\":0,\"group_override\":false,\"rules\":[{\"group_id\":\"\",\"id\":\"\",\"start_key\":\"\",\"end_key\":\"\",\"role\":\"voter\",\"count\":3,\"label_constraints\":[{\"key\":\"zone\",\"op\":\"in\",\"values\":[\"sh\"]}]},{\"group_id\":\"\",\"id\":\"\",\"start_key\":\"\",\"end_key\":\"\",\"role\":\"voter\",\"count\":4,\"label_constraints\":[{\"key\":\"zone\",\"op\":\"notIn\",\"values\":[\"sh\"]},{\"key\":\"zone\",\"op\":\"in\",\"values\":[\"bj\"]}]}]}") c.Assert(failpoint.Enable("github.com/pingcap/tidb/ddl/placement/MockMarshalFailure", `return(true)`), IsNil) defer func() { diff --git a/ddl/placement/rule.go b/ddl/placement/rule.go index 74a3130167..c8528ef2df 100644 --- a/ddl/placement/rule.go +++ b/ddl/placement/rule.go @@ -38,27 +38,24 @@ const ( // Rule is the core placement rule struct. Check https://github.com/tikv/pd/blob/master/server/schedule/placement/rule.go. type Rule struct { - GroupID string `json:"group_id"` - ID string `json:"id"` - Index int `json:"index,omitempty"` - Override bool `json:"override,omitempty"` - StartKeyHex string `json:"start_key"` - EndKeyHex string `json:"end_key"` - Role PeerRoleType `json:"role"` - Count int `json:"count"` - Constraints Constraints `json:"label_constraints,omitempty"` - LocationLabels []string `json:"location_labels,omitempty"` - IsolationLevel string `json:"isolation_level,omitempty"` + GroupID string `json:"group_id"` + ID string `json:"id"` + Index int `json:"index,omitempty"` + Override bool `json:"override,omitempty"` + StartKeyHex string `json:"start_key"` + EndKeyHex string `json:"end_key"` + Role PeerRoleType `json:"role"` + Count int `json:"count"` + Constraints Constraints `json:"label_constraints,omitempty"` } // NewRule constructs *Rule from role, count, and constraints. It is here to // consistent the behavior of creating new rules. func NewRule(role PeerRoleType, replicas uint64, cnst Constraints) *Rule { return &Rule{ - Role: role, - Count: int(replicas), - Constraints: cnst, - LocationLabels: []string{"region", "zone", "rack", "host"}, + Role: role, + Count: int(replicas), + Constraints: cnst, } } @@ -119,8 +116,7 @@ func NewRules(role PeerRoleType, replicas uint64, cnstr string) ([]*Rule, error) } // Clone is used to duplicate a RuleOp for safe modification. -// Note that it is a shallow copy: LocationLabels and Constraints -// is not cloned. +// Note that it is a shallow copy: Constraints is not cloned. func (r *Rule) Clone() *Rule { n := &Rule{} *n = *r