Skip to content

Commit

Permalink
*: followers in information_schema.placement_policies should show…
Browse files Browse the repository at this point in the history
… default count when followers not set (pingcap#31927)

close pingcap#31702
  • Loading branch information
lcwangchao authored Jan 25, 2022
1 parent 8c5b04a commit 172701c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ddl/placement_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ func (s *testDBSuite6) TestAlterPlacementPolicy(c *C) {
// test for normal cases
tk.MustExec("alter placement policy x PRIMARY_REGION=\"bj\" REGIONS=\"bj,sh\"")
tk.MustQuery("show placement where target='POLICY x'").Check(testkit.Rows("POLICY x PRIMARY_REGION=\"bj\" REGIONS=\"bj,sh\" NULL"))
tk.MustQuery("select * from information_schema.placement_policies where policy_name = 'x'").Check(testkit.Rows(strconv.FormatInt(policy.ID, 10) + " def x bj bj,sh 0 0"))
tk.MustQuery("select * from information_schema.placement_policies where policy_name = 'x'").Check(testkit.Rows(strconv.FormatInt(policy.ID, 10) + " def x bj bj,sh 2 0"))
checkExistTableBundlesInPD(c, s.dom, "test", "tp")

tk.MustExec("alter placement policy x " +
"PRIMARY_REGION=\"bj\" " +
"REGIONS=\"bj\" " +
"SCHEDULE=\"EVEN\"")
tk.MustQuery("show placement where target='POLICY x'").Check(testkit.Rows("POLICY x PRIMARY_REGION=\"bj\" REGIONS=\"bj\" SCHEDULE=\"EVEN\" NULL"))
tk.MustQuery("select * from INFORMATION_SCHEMA.PLACEMENT_POLICIES WHERE POLICY_NAME='x'").Check(testkit.Rows(strconv.FormatInt(policy.ID, 10) + " def x bj bj EVEN 0 0"))
tk.MustQuery("select * from INFORMATION_SCHEMA.PLACEMENT_POLICIES WHERE POLICY_NAME='x'").Check(testkit.Rows(strconv.FormatInt(policy.ID, 10) + " def x bj bj EVEN 2 0"))
checkExistTableBundlesInPD(c, s.dom, "test", "tp")

tk.MustExec("alter placement policy x " +
Expand Down Expand Up @@ -435,7 +435,7 @@ func (s *testDBSuite6) TestAlterPlacementPolicy(c *C) {
"CATALOG_NAME,POLICY_NAME," +
"PRIMARY_REGION,REGIONS,CONSTRAINTS,LEADER_CONSTRAINTS,FOLLOWER_CONSTRAINTS,LEARNER_CONSTRAINTS," +
"SCHEDULE,FOLLOWERS,LEARNERS FROM INFORMATION_SCHEMA.placement_policies WHERE POLICY_NAME='x'").Check(
testkit.Rows("def x [+disk=ssd] [+region=sh] 0 3"),
testkit.Rows("def x [+disk=ssd] [+region=sh] 2 3"),
)
checkExistTableBundlesInPD(c, s.dom, "test", "tp")

Expand Down
8 changes: 7 additions & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,12 @@ func (e *memtableRetriever) setDataFromPlacementPolicies(sctx sessionctx.Context
// also convert them to LeaderConstraints and FollowerConstraints
// for better user experience searching for particular constraints

// Followers == 0 means not set, so the default value 2 will be used
followerCnt := policy.PlacementSettings.Followers
if followerCnt == 0 {
followerCnt = 2
}

row := types.MakeDatums(
policy.ID,
infoschema.CatalogVal, // CATALOG
Expand All @@ -2895,7 +2901,7 @@ func (e *memtableRetriever) setDataFromPlacementPolicies(sctx sessionctx.Context
policy.PlacementSettings.FollowerConstraints,
policy.PlacementSettings.LearnerConstraints,
policy.PlacementSettings.Schedule,
policy.PlacementSettings.Followers,
followerCnt,
policy.PlacementSettings.Learners,
)
rows = append(rows, row)
Expand Down

0 comments on commit 172701c

Please sign in to comment.