Skip to content

Commit

Permalink
Merge branch 'master' into bug-fix/20207
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Nov 5, 2020
2 parents 740385e + 8c418b9 commit 18396db
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 35 deletions.
6 changes: 6 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5846,6 +5846,12 @@ func buildPlacementSpecs(bundle *placement.Bundle, specs []*ast.PlacementSpec) (
case ast.PlacementRoleFollower:
role = placement.Follower
case ast.PlacementRoleLeader:
if spec.Replicas == 0 {
spec.Replicas = 1
}
if spec.Replicas > 1 {
err = errors.Errorf("replicas can only be 1 when the role is leader")
}
role = placement.Leader
case ast.PlacementRoleLearner:
role = placement.Learner
Expand Down
71 changes: 40 additions & 31 deletions ddl/placement_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,42 @@ PARTITION BY RANGE (c) (
_, err := tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+zone=sh"]'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+ zone = sh ", "- zone = bj "]'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='{"+ zone = sh ": 1}'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='{"+ zone = sh, -zone = bj ": 1}'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='{"+ zone = sh ": 1, "- zone = bj": 2}'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

_, err = tk.Exec(`alter table t1 alter partition p0
alter placement policy
constraints='{"+ zone = sh, -zone = bj ": 1}'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

Expand All @@ -89,52 +89,52 @@ drop placement policy
_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+ zone = sh "]'
role=leader
role=follower
replicas=3,
add placement policy
constraints='{"+ zone = sh, -zone = bj ": 1}'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+ zone = sh "]'
role=leader
role=follower
replicas=3,
add placement policy
constraints='{"+zone=sh,+zone=bj":1,"+zone=sh,+zone=bj":1}'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='{"+ zone = sh ": 1, "- zone = bj,+zone=sh": 2}'
role=leader
role=follower
replicas=3,
alter placement policy
constraints='{"+ zone = sh, -zone = bj ": 1}'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+zone=sh", "-zone=bj"]'
role=leader
role=follower
replicas=3,
add placement policy
constraints='{"+zone=sh": 1}'
role=leader
role=follower
replicas=3,
add placement policy
constraints='{"+zone=sh,+zone=bj":1,"+zone=sh,+zone=bj":1}'
role=leader
role=follower
replicas=3,
alter placement policy
constraints='{"+zone=sh": 1, "-zon =bj,+zone=sh": 1}'
role=leader
role=follower
replicas=3`)
c.Assert(err, IsNil)

Expand All @@ -158,103 +158,103 @@ drop placement policy
_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints=',,,'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*array or object.*")

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='[,,,'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*invalid character.*")

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='{,,,'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*invalid character.*")

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='{"+ zone = sh ": 1, "- zone = bj": 2}'
role=leader
role=follower
replicas=2`)
c.Assert(err, ErrorMatches, ".*should be larger or equal to the number of total replicas.*")

// checkPlacementSpecConstraint
_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='[",,,"]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*label constraint should be in format.*")

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+ "]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*label constraint should be in format.*")

// unknown operation
_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["0000"]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*label constraint should be in format.*")

// without =
_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+000"]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*label constraint should be in format.*")

// empty key
_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+ =zone1"]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*label constraint should be in format.*")

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+ = z"]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*label constraint should be in format.*")

// empty value
_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+zone="]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*label constraint should be in format.*")

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='["+z = "]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*label constraint should be in format.*")

_, err = tk.Exec(`alter table t1 alter partition p
add placement policy
constraints='["+zone=sh"]'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*Unknown partition.*")

_, err = tk.Exec(`alter table t1 alter partition p0
add placement policy
constraints='{"+ zone = sh, -zone = bj ": -1}'
role=leader
role=follower
replicas=3`)
c.Assert(err, ErrorMatches, ".*count should be positive.*")

Expand All @@ -271,9 +271,18 @@ add placement policy
_, err = tk.Exec(`alter table t1 alter partition p
add placement policy
constraints='["+zone=sh"]'
role=leader
role=follower
replicas=3`)
c.Assert(ddl.ErrPartitionMgmtOnNonpartitioned.Equal(err), IsTrue)

// issue 20751
tk.MustExec("drop table if exists t_part_pk_id")
tk.MustExec("create TABLE t_part_pk_id (c1 int,c2 int) partition by range(c1 div c2 ) (partition p0 values less than (2))")
_, err = tk.Exec(`alter table t_part_pk_id alter partition p0 add placement policy constraints='["+host=store1"]' role=leader;`)
c.Assert(err, IsNil)
_, err = tk.Exec(`alter table t_part_pk_id alter partition p0 add placement policy constraints='["+host=store1"]' role=leader replicas=3;`)
c.Assert(err, ErrorMatches, ".*replicas can only be 1 when the role is leader")
tk.MustExec("drop table t_part_pk_id")
}

func (s *testDBSuite1) TestPlacementPolicyCache(c *C) {
Expand Down
10 changes: 6 additions & 4 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3347,10 +3347,12 @@ func (builder *dataReaderBuilder) buildTableReaderFromHandles(ctx context.Contex
})
}
var b distsql.RequestBuilder
if _, ok := handles[0].(kv.PartitionHandle); ok {
b.SetPartitionsAndHandles(handles)
} else {
b.SetTableHandles(getPhysicalTableID(e.table), handles)
if len(handles) > 0 {
if _, ok := handles[0].(kv.PartitionHandle); ok {
b.SetPartitionsAndHandles(handles)
} else {
b.SetTableHandles(getPhysicalTableID(e.table), handles)
}
}
return builder.buildTableReaderBase(ctx, e, b)
}
Expand Down
12 changes: 12 additions & 0 deletions executor/index_lookup_merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,15 @@ func (s *testSuite9) TestIssue20400(c *C) {
tk.MustQuery("select /*+ inl_merge_join(t,s)*/ * from t left join s on t.a=s.a and t.a>1").Check(
testkit.Rows("1 <nil>"))
}

func (s *testSuite9) TestIssue20549(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("CREATE TABLE `t1` (`id` bigint(20) NOT NULL AUTO_INCREMENT, `t2id` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`), KEY `t2id` (`t2id`));")
tk.MustExec("INSERT INTO `t1` VALUES (1,NULL);")
tk.MustExec("CREATE TABLE `t2` (`id` bigint(20) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`));")
tk.MustQuery("SELECT /*+ INL_MERGE_JOIN(t1,t2) */ 1 from t1 left outer join t2 on t1.t2id=t2.id;").Check(
testkit.Rows("1"))
tk.MustQuery("SELECT /*+ HASH_JOIN(t1,t2) */ 1 from t1 left outer join t2 on t1.t2id=t2.id;\n").Check(
testkit.Rows("1"))
}
4 changes: 4 additions & 0 deletions store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ func (s *tikvStore) Close() error {
if s.coprCache != nil {
s.coprCache.cache.Close()
}

if err := s.kv.Close(); err != nil {
return errors.Trace(err)
}
return nil
}

Expand Down
11 changes: 11 additions & 0 deletions store/tikv/safepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type SafePointKV interface {
Put(k string, v string) error
Get(k string) (string, error)
GetWithPrefix(k string) ([]*mvccpb.KeyValue, error)
Close() error
}

// MockSafePointKV implements SafePointKV at mock test
Expand Down Expand Up @@ -90,6 +91,11 @@ func (w *MockSafePointKV) GetWithPrefix(prefix string) ([]*mvccpb.KeyValue, erro
return kvs, nil
}

// Close implements the Close method for SafePointKV
func (w *MockSafePointKV) Close() error {
return nil
}

// EtcdSafePointKV implements SafePointKV at runtime
type EtcdSafePointKV struct {
cli *clientv3.Client
Expand Down Expand Up @@ -140,6 +146,11 @@ func (w *EtcdSafePointKV) GetWithPrefix(k string) ([]*mvccpb.KeyValue, error) {
return resp.Kvs, nil
}

// Close implements the Close for SafePointKV
func (w *EtcdSafePointKV) Close() error {
return errors.Trace(w.cli.Close())
}

func saveSafePoint(kv SafePointKV, t uint64) error {
s := strconv.FormatUint(t, 10)
err := kv.Put(GcSavedSafePoint, s)
Expand Down

0 comments on commit 18396db

Please sign in to comment.