-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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: Add raw delete range API #6157
Changes from 12 commits
1946e20
9a925e1
ae1392b
c195b3d
220ef01
fcd208c
0d44811
6696040
a9b68ca
fec48ad
cd74685
7c28d87
28b9499
e5f809b
485e8f2
019fda6
a81270b
c88dac2
05d88e4
6132848
6bfd6e3
17771f2
2021743
006d18e
fc7786d
13d3a93
6214b7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
package tikv | ||
|
||
import ( | ||
"bytes" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a newline after this |
||
. "github.com/pingcap/check" | ||
"github.com/pingcap/tidb/store/mockstore/mocktikv" | ||
"golang.org/x/net/context" | ||
|
@@ -78,6 +79,38 @@ func (s *testRawKVSuite) mustScan(c *C, startKey string, limit int, expect ...st | |
} | ||
} | ||
|
||
func (s *testRawKVSuite) mustDeleteRange(c *C, startKey, endKey []byte, expected map[string]string) { | ||
err := s.client.DeleteRange(startKey, endKey) | ||
c.Assert(err, IsNil) | ||
|
||
for keyStr := range expected { | ||
key := []byte(keyStr) | ||
if bytes.Compare(startKey, key) <= 0 && bytes.Compare(key, endKey) < 0 { | ||
delete(expected, keyStr) | ||
} | ||
} | ||
|
||
s.checkData(c, expected) | ||
} | ||
|
||
func (s *testRawKVSuite) checkData(c *C, expected map[string]string) { | ||
keys, values, err := s.client.Scan([]byte(""), len(expected)+1) | ||
c.Assert(err, IsNil) | ||
|
||
c.Assert(len(expected), Equals, len(keys)) | ||
for i, key := range keys { | ||
c.Assert(expected[string(key)], Equals, string(values[i])) | ||
} | ||
} | ||
|
||
func (s *testRawKVSuite) split(c *C, regionKey, splitKey string) { | ||
loc, err := s.client.regionCache.LocateKey(s.bo, []byte(regionKey)) | ||
c.Assert(err, IsNil) | ||
|
||
newRegionID, peerID := s.cluster.AllocID(), s.cluster.AllocID() | ||
s.cluster.SplitRaw(loc.Region.id, newRegionID, []byte(splitKey), []uint64{peerID}, peerID) | ||
} | ||
|
||
func (s *testRawKVSuite) TestSimple(c *C) { | ||
s.mustNotExist(c, []byte("key")) | ||
s.mustPut(c, []byte("key"), []byte("value")) | ||
|
@@ -89,13 +122,10 @@ func (s *testRawKVSuite) TestSimple(c *C) { | |
} | ||
|
||
func (s *testRawKVSuite) TestSplit(c *C) { | ||
loc, err := s.client.regionCache.LocateKey(s.bo, []byte("k")) | ||
c.Assert(err, IsNil) | ||
s.mustPut(c, []byte("k1"), []byte("v1")) | ||
s.mustPut(c, []byte("k3"), []byte("v3")) | ||
|
||
newRegionID, peerID := s.cluster.AllocID(), s.cluster.AllocID() | ||
s.cluster.SplitRaw(loc.Region.id, newRegionID, []byte("k2"), []uint64{peerID}, peerID) | ||
s.split(c, "k", "k2") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let I prefer former, because when there are many |
||
|
||
s.mustGet(c, []byte("k1"), []byte("v1")) | ||
s.mustGet(c, []byte("k3"), []byte("v3")) | ||
|
@@ -115,16 +145,34 @@ func (s *testRawKVSuite) TestScan(c *C) { | |
s.mustScan(c, "k2", 3, "k3", "v3", "k5", "v5", "k7", "v7") | ||
} | ||
|
||
split := func(regionKey, splitKey string) { | ||
loc, err := s.client.regionCache.LocateKey(s.bo, []byte(regionKey)) | ||
c.Assert(err, IsNil) | ||
newRegionID, peerID := s.cluster.AllocID(), s.cluster.AllocID() | ||
s.cluster.SplitRaw(loc.Region.id, newRegionID, []byte(splitKey), []uint64{peerID}, peerID) | ||
} | ||
|
||
check() | ||
split("k", "k2") | ||
s.split(c, "k", "k2") | ||
check() | ||
split("k2", "k5") | ||
s.split(c, "k2", "k5") | ||
check() | ||
} | ||
|
||
func (s *testRawKVSuite) TestDeleteRange(c *C) { | ||
// Init data | ||
testData := map[string]string{} | ||
for _, i := range []byte("abcd") { | ||
for j := byte('0'); j <= byte('9'); j++ { | ||
key := []byte{i, j} | ||
value := []byte{'v', i, j} | ||
s.mustPut(c, key, value) | ||
|
||
testData[string(key)] = string(value) | ||
} | ||
} | ||
|
||
s.split(c, "b", "b") | ||
s.split(c, "c", "c") | ||
s.split(c, "d", "d") | ||
|
||
s.checkData(c, testData) | ||
s.mustDeleteRange(c, []byte("b"), []byte("c0"), testData) | ||
s.mustDeleteRange(c, []byte("c11"), []byte("c12"), testData) | ||
s.mustDeleteRange(c, []byte("d0"), []byte("d0"), testData) | ||
s.mustDeleteRange(c, []byte("c5"), []byte("d5"), testData) | ||
s.mustDeleteRange(c, []byte("a"), []byte("z"), testData) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add succ or error label?