Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: followers in information_schema.placement_policies should show default count when followers not set #31927

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -2892,6 +2892,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 @@ -2903,7 +2909,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