-
Notifications
You must be signed in to change notification settings - Fork 228
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
implement rollback for pipelined dml #1235
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d5197cf
impl rollback for p-dml
you06 5b41fdf
add test to ensure the rollback locks cannot be read
you06 2f65a8c
remove TODO comment
you06 8e93a9e
address comment
you06 229d77b
Merge branch 'master' into p-dml/rollback
cfzjywxk efc590c
Merge branch 'master' into p-dml/rollback
ekexium 907fd9b
Merge branch 'master' into p-dml/rollback
you06 a460148
resolve conflict
you06 19aa152
Merge branch 'master' into p-dml/rollback
you06 49e0717
lint
you06 d3cee28
Merge branch 'master' into p-dml/rollback
cfzjywxk 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 |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
"time" | ||
|
||
"github.com/docker/go-units" | ||
"github.com/golang/protobuf/proto" //nolint:staticcheck | ||
"github.com/opentracing/opentracing-go" | ||
"github.com/pingcap/errors" | ||
"github.com/pingcap/kvproto/pkg/kvrpcpb" | ||
|
@@ -314,7 +315,7 @@ func (c *twoPhaseCommitter) commitFlushedMutations(bo *retry.Backoffer) error { | |
|
||
// async resolve the rest locks. | ||
commitBo := retry.NewBackofferWithVars(c.store.Ctx(), CommitSecondaryMaxBackoff, c.txn.vars) | ||
go c.resolveFlushedLocks(commitBo, c.pipelinedCommitInfo.pipelinedStart, c.pipelinedCommitInfo.pipelinedEnd) | ||
c.resolveFlushedLocks(commitBo, c.pipelinedCommitInfo.pipelinedStart, c.pipelinedCommitInfo.pipelinedEnd, true) | ||
return nil | ||
} | ||
|
||
|
@@ -334,6 +335,18 @@ func (c *twoPhaseCommitter) buildPipelinedResolveHandler(commit bool, resolved * | |
maxBackOff = CommitSecondaryMaxBackoff | ||
} | ||
regionCache := c.store.GetRegionCache() | ||
// the handler function runs in a different goroutine, should copy the required values before it to avoid race. | ||
kvContext := &kvrpcpb.Context{ | ||
Priority: c.priority, | ||
SyncLog: c.syncLog, | ||
ResourceGroupTag: c.resourceGroupTag, | ||
DiskFullOpt: c.txn.diskFullOpt, | ||
TxnSource: c.txn.txnSource, | ||
RequestSource: PipelinedRequestSource, | ||
ResourceControlContext: &kvrpcpb.ResourceControlContext{ | ||
ResourceGroupName: c.resourceGroupName, | ||
}, | ||
} | ||
return func(ctx context.Context, r kv.KeyRange) (rangetask.TaskStat, error) { | ||
start := r.StartKey | ||
res := rangetask.TaskStat{} | ||
|
@@ -342,9 +355,7 @@ func (c *twoPhaseCommitter) buildPipelinedResolveHandler(commit bool, resolved * | |
StartVersion: c.startTS, | ||
CommitVersion: commitVersion, | ||
} | ||
req := tikvrpc.NewRequest(tikvrpc.CmdResolveLock, lreq, kvrpcpb.Context{ | ||
RequestSource: PipelinedRequestSource, | ||
}) | ||
req := tikvrpc.NewRequest(tikvrpc.CmdResolveLock, lreq, *proto.Clone(kvContext).(*kvrpcpb.Context)) | ||
bo := retry.NewBackoffer(ctx, maxBackOff) | ||
loc, err := regionCache.LocateKey(bo, start) | ||
if err != nil { | ||
|
@@ -392,22 +403,31 @@ func (c *twoPhaseCommitter) buildPipelinedResolveHandler(commit bool, resolved * | |
}, nil | ||
} | ||
|
||
func (c *twoPhaseCommitter) resolveFlushedLocks(bo *retry.Backoffer, start, end []byte) { | ||
// TODO: implement cleanup. | ||
// resolveFlushedLocks resolves all locks in the given range [start, end) with the given status. | ||
// The resolve process is running in another goroutine so this function won't block. | ||
func (c *twoPhaseCommitter) resolveFlushedLocks(bo *retry.Backoffer, start, end []byte, commit bool) { | ||
const RESOLVE_CONCURRENCY = 8 | ||
var resolved atomic.Uint64 | ||
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. I'm not sure if we need to choose lower concurrency for rollback. |
||
handler, err := c.buildPipelinedResolveHandler(true, &resolved) | ||
handler, err := c.buildPipelinedResolveHandler(commit, &resolved) | ||
if err != nil { | ||
logutil.Logger(bo.GetCtx()).Error("[pipelined dml] build buildPipelinedResolveHandler error", zap.Error(err)) | ||
return | ||
} | ||
runner := rangetask.NewRangeTaskRunner("pipelined-dml-commit", c.store, RESOLVE_CONCURRENCY, handler) | ||
if err = runner.RunOnRange(bo.GetCtx(), start, end); err != nil { | ||
logutil.Logger(bo.GetCtx()).Error("[pipelined dml] commit transaction secondaries failed", | ||
zap.Uint64("resolved regions", resolved.Load()), | ||
zap.Error(err)) | ||
} else { | ||
logutil.BgLogger().Info("[pipelined dml] commit transaction secondaries done", | ||
zap.Uint64("resolved regions", resolved.Load())) | ||
status := "rollback" | ||
if commit { | ||
status = "commit" | ||
} | ||
runner := rangetask.NewRangeTaskRunner("pipelined-dml-"+status, c.store, RESOLVE_CONCURRENCY, handler) | ||
go func() { | ||
if err = runner.RunOnRange(bo.GetCtx(), start, end); err != nil { | ||
logutil.Logger(bo.GetCtx()).Error("[pipelined dml] resolve flushed locks failed", | ||
zap.String("txn-status", status), | ||
zap.Uint64("resolved regions", resolved.Load()), | ||
zap.Error(err)) | ||
} else { | ||
logutil.BgLogger().Info("[pipelined dml] resolve flushed locks done", | ||
zap.String("txn-status", status), | ||
zap.Uint64("resolved regions", resolved.Load())) | ||
} | ||
}() | ||
} |
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
Oops, something went wrong.
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.
As dicussed in above comments, this may not be a perfect solution, we still need to find a way to avoid race completely.
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.
Maybe set
txn.committer
tonil
which disable further accessing to rollbacked committer.