-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 CANCEL/DROP LOAD DATA JOB #42137
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b1c25db
--wip-- [skip ci]
lance6716 c990190
rename
lance6716 6e2418c
--wip-- [skip ci]
lance6716 430838c
Merge branch 'master' of github.com:pingcap/tidb into cancel-drop-ld
lance6716 78441b7
fix errdoc
lance6716 23af006
add some test
lance6716 dfe5cec
make bazel
lance6716 2f5f576
add missing file
lance6716 1c4233c
--wip-- [skip ci]
lance6716 f2f8030
fix some test
lance6716 f5c1643
fix UT
lance6716 27ec1c2
log when error
lance6716 e1eed46
add more test
lance6716 c60933e
Merge branch 'master' of github.com:pingcap/tidb into cancel-drop-ld
lance6716 eb94497
fix UT
lance6716 24bd2b9
fix another test
lance6716 2f9da8d
fix another test
lance6716 05a97b2
Merge branch 'master' of github.com:pingcap/tidb into cancel-drop-ld
lance6716 76d23f7
fix unfound merge conflict
lance6716 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
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
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package asyncloaddata_test | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
"time" | ||
|
||
"github.com/fsouza/fake-gcs-server/fakestorage" | ||
. "github.com/pingcap/tidb/executor/asyncloaddata" | ||
"github.com/pingcap/tidb/parser/auth" | ||
"github.com/pingcap/tidb/testkit" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func (s *mockGCSSuite) TestOperateRunningJob() { | ||
s.tk.MustExec("DROP DATABASE IF EXISTS test_operate;") | ||
s.tk.MustExec("CREATE DATABASE test_operate;") | ||
s.tk.MustExec("CREATE TABLE test_operate.t (i INT PRIMARY KEY);") | ||
s.server.CreateObject(fakestorage.Object{ | ||
ObjectAttrs: fakestorage.ObjectAttrs{ | ||
BucketName: "test-operate", | ||
Name: "t.tsv", | ||
}, | ||
Content: []byte("1\n2\n3\n4\n5\n6\n7\n8\n9\n10"), | ||
}) | ||
|
||
backup := HeartBeatInSec | ||
HeartBeatInSec = 1 | ||
s.T().Cleanup(func() { | ||
HeartBeatInSec = backup | ||
}) | ||
|
||
s.enableFailpoint("github.com/pingcap/tidb/executor/AfterCreateLoadDataJob", `sleep(1000)`) | ||
s.enableFailpoint("github.com/pingcap/tidb/executor/AfterStartJob", `sleep(1000)`) | ||
s.enableFailpoint("github.com/pingcap/tidb/executor/AfterCommitOneTask", `sleep(1000)`) | ||
sql := fmt.Sprintf(`LOAD DATA INFILE 'gs://test-operate/t.tsv?endpoint=%s' | ||
INTO TABLE test_operate.t;`, gcsEndpoint) | ||
|
||
// DROP can happen anytime | ||
user := &auth.UserIdentity{ | ||
AuthUsername: "test-load-3", | ||
AuthHostname: "test-host", | ||
} | ||
s.tk.Session().GetSessionVars().User = user | ||
tk2 := testkit.NewTestKit(s.T(), s.store) | ||
tk2.Session().GetSessionVars().User = user | ||
tk2.MustExec("SET SESSION tidb_dml_batch_size = 1;") | ||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
tk2.MustContainErrMsg(sql, "failed to keepalive") | ||
}() | ||
|
||
// TODO: remove this sleep after moving mysql.load_data_jobs to bootstrap | ||
time.Sleep(3 * time.Second) | ||
rows := s.tk.MustQuery("SHOW LOAD DATA JOBS;").Rows() | ||
require.Greater(s.T(), len(rows), 0) | ||
jobID := rows[len(rows)-1][0].(string) | ||
s.tk.MustExec("DROP LOAD DATA JOB " + jobID) | ||
wg.Wait() | ||
|
||
// test CANCEL | ||
|
||
sql = fmt.Sprintf(`LOAD DATA INFILE 'gs://test-operate/t.tsv?endpoint=%s' | ||
REPLACE INTO TABLE test_operate.t;`, gcsEndpoint) | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
tk2.MustContainErrMsg(sql, "failed to keepalive") | ||
}() | ||
|
||
time.Sleep(3 * time.Second) | ||
rows = s.tk.MustQuery("SHOW LOAD DATA JOBS;").Rows() | ||
require.Greater(s.T(), len(rows), 0) | ||
jobID = rows[len(rows)-1][0].(string) | ||
s.tk.MustExec("CANCEL LOAD DATA JOB " + jobID) | ||
wg.Wait() | ||
rows = s.tk.MustQuery("SHOW LOAD DATA JOB " + jobID).Rows() | ||
require.Len(s.T(), rows, 1) | ||
row := rows[0] | ||
e := expectedRecord{ | ||
jobID: jobID, | ||
dataSource: "gs://test-operate/t.tsv", | ||
targetTable: "`test_operate`.`t`", | ||
importMode: "logical", | ||
createdBy: "test-load-3@test-host", | ||
jobState: "loading", | ||
jobStatus: "canceled", | ||
sourceFileSize: row[10].(string), | ||
loadedFileSize: row[11].(string), | ||
resultCode: "0", | ||
resultMessage: "canceled by user", | ||
} | ||
e.checkIgnoreTimes(s.T(), row) | ||
|
||
// cancel again is OK | ||
|
||
err := s.tk.ExecToErr("CANCEL LOAD DATA JOB " + jobID) | ||
require.ErrorContains(s.T(), err, "The current job status cannot perform the operation. need status running or paused, but got canceled") | ||
rows = s.tk.MustQuery("SHOW LOAD DATA JOB " + jobID).Rows() | ||
require.Len(s.T(), rows, 1) | ||
row = rows[0] | ||
e.checkIgnoreTimes(s.T(), row) | ||
} |
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
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.
make
failed
a status in job table?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.
currently we only have expected_status. but no actual_status, so these lines is to calculate actual_status from other columns. I plan to add actual_status later when implement PAUSE/RESUME LOAD DATA JOBS, to let PAUSE don't return until actual_status is paused 😂