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

store/tikv: refactor copIterator #2804

Merged
merged 17 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions executor/distsql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/util/testkit"
)

Expand Down Expand Up @@ -65,3 +68,56 @@ func taskGoroutineExists() bool {
str := buf.String()
return strings.Contains(str, "pickAndExecTask")
}

func (s *testSuite) TestCopClientSend(c *C) {
if _, ok := s.store.GetClient().(*tikv.CopClient); !ok {
// Make sure the store is tikv store.
return
}
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table copclient (id int primary key)")

// Insert 1000 rows.
var values []string
for i := 0; i < 1000; i++ {
values = append(values, fmt.Sprintf("(%d)", i))
}
tk.MustExec("insert copclient values " + strings.Join(values, ","))

// Get table ID for split.
dom := sessionctx.GetDomain(tk.Se)
is := dom.InfoSchema()
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("copclient"))
c.Assert(err, IsNil)
tblID := tbl.Meta().ID

// Split the table.
cli := tikv.GetMockTiKVClient(s.store)
cli.Cluster.SplitTable(cli.MvccStore, tblID, 100)
tikv.ClearRegionCache(s.store)

// Send coprocessor request when the table split.
rss, err := tk.Se.Execute("select sum(id) from copclient")
c.Assert(err, IsNil)
rs := rss[0]
defer rs.Close()
row, err := rs.Next()
c.Assert(err, IsNil)
c.Assert(row.Data[0].GetMysqlDecimal().String(), Equals, "499500")

// Split one region.
key := tablecodec.EncodeRowKeyWithHandle(tblID, 500)
region, _ := cli.Cluster.GetRegionByKey([]byte(key))
peerID := cli.Cluster.AllocID()
cli.Cluster.Split(region.GetId(), cli.Cluster.AllocID(), key, []uint64{peerID}, peerID)

// Check again.
rss, err = tk.Se.Execute("select sum(id) from copclient")
c.Assert(err, IsNil)
rs = rss[0]
defer rs.Close()
row, err = rs.Next()
c.Assert(err, IsNil)
c.Assert(row.Data[0].GetMysqlDecimal().String(), Equals, "499500")
}
Loading