This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Incremental BR: support DDL #155
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ff40d82
support backup&restore ddl
20cf2b7
integration tests
40c2b3c
update kvproto
e5ae264
fix integration tests
07de065
reduce cyclomatic complexity of `runRestore`
3e485c0
fix test
ff544b8
resovle conflicts
4d5d966
Merge branch 'master' into restore-ddl
a468099
add unit test
957f6bb
fix tests
c9301b1
disable fast checksum in incremental br
60187d7
fix no valid key error
a78f3ca
address lint
39efe6d
address comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"github.com/pingcap/kvproto/pkg/import_sstpb" | ||
"github.com/pingcap/kvproto/pkg/pdpb" | ||
"github.com/pingcap/log" | ||
"github.com/pingcap/tidb/tablecodec" | ||
"github.com/pingcap/tidb/util/codec" | ||
"go.uber.org/zap" | ||
) | ||
|
@@ -104,10 +105,17 @@ SplitRegions: | |
} | ||
for regionID, keys := range splitKeyMap { | ||
var newRegions []*RegionInfo | ||
newRegions, err = rs.splitAndScatterRegions(ctx, regionMap[regionID], keys) | ||
region := regionMap[regionID] | ||
newRegions, err = rs.splitAndScatterRegions(ctx, region, keys) | ||
if err != nil { | ||
if strings.Contains(err.Error(), "no valid key") { | ||
continue | ||
for _, key := range keys { | ||
log.Error("no valid key", | ||
zap.Binary("startKey", region.Region.StartKey), | ||
zap.Binary("endKey", region.Region.EndKey), | ||
zap.Binary("key", codec.EncodeBytes([]byte{}, key))) | ||
} | ||
return errors.Trace(err) | ||
} | ||
interval = 2 * interval | ||
if interval > SplitMaxRetryInterval { | ||
|
@@ -119,12 +127,13 @@ SplitRegions: | |
} | ||
continue SplitRegions | ||
} | ||
log.Debug("split regions", zap.Stringer("region", region.Region), zap.ByteStrings("keys", keys)) | ||
scatterRegions = append(scatterRegions, newRegions...) | ||
onSplit(keys) | ||
} | ||
break | ||
} | ||
if err != nil && !strings.Contains(err.Error(), "no valid key") { | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
log.Info("splitting regions done, wait for scattering regions", | ||
|
@@ -254,7 +263,7 @@ func getSplitKeys(rewriteRules *RewriteRules, ranges []Range, regions []*RegionI | |
checkKeys = append(checkKeys, rule.GetNewKeyPrefix()) | ||
} | ||
for _, rg := range ranges { | ||
checkKeys = append(checkKeys, rg.EndKey) | ||
checkKeys = append(checkKeys, truncateRowKey(rg.EndKey)) | ||
} | ||
for _, key := range checkKeys { | ||
if region := needSplit(key, regions); region != nil { | ||
|
@@ -263,7 +272,10 @@ func getSplitKeys(rewriteRules *RewriteRules, ranges []Range, regions []*RegionI | |
splitKeys = make([][]byte, 0, 1) | ||
} | ||
splitKeyMap[region.Region.GetId()] = append(splitKeys, key) | ||
log.Debug("get key for split region", zap.Binary("key", key), zap.Stringer("region", region.Region)) | ||
log.Debug("get key for split region", | ||
zap.Binary("key", key), | ||
zap.Binary("startKey", region.Region.StartKey), | ||
zap.Binary("endKey", region.Region.EndKey)) | ||
} | ||
} | ||
return splitKeyMap | ||
|
@@ -289,6 +301,15 @@ func needSplit(splitKey []byte, regions []*RegionInfo) *RegionInfo { | |
return nil | ||
} | ||
|
||
func truncateRowKey(key []byte) []byte { | ||
if bytes.HasPrefix(key, []byte("t")) && | ||
len(key) > tablecodec.RecordRowKeyLen && | ||
bytes.HasPrefix(key[9:], []byte("_r")) { | ||
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.
|
||
return key[:tablecodec.RecordRowKeyLen] | ||
} | ||
return key | ||
} | ||
|
||
func beforeEnd(key []byte, end []byte) bool { | ||
return bytes.Compare(key, end) < 0 || len(end) == 0 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How can it occur? Could you add some comments?
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.
The record backup range has appended a "\000" to the end key, TiKV truncates this suffix and BR does not. Will fixed it in this PR.