-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: show backfill type in
admin show ddl jobs
(#38733)
ref #35983
- Loading branch information
Showing
5 changed files
with
127 additions
and
54 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2022 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 addindextest_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/ddl/ingest" | ||
"github.com/pingcap/tidb/testkit" | ||
"github.com/pingcap/tidb/tests/realtikvtest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAddIndexIngestMemoryUsage(t *testing.T) { | ||
store := realtikvtest.CreateMockStoreAndSetup(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("drop database if exists addindexlit;") | ||
tk.MustExec("create database addindexlit;") | ||
tk.MustExec("use addindexlit;") | ||
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`) | ||
|
||
tk.MustExec("create table t (a int, b int, c int);") | ||
var sb strings.Builder | ||
sb.WriteString("insert into t values ") | ||
size := 100 | ||
for i := 0; i < size; i++ { | ||
sb.WriteString(fmt.Sprintf("(%d, %d, %d)", i, i, i)) | ||
if i != size-1 { | ||
sb.WriteString(",") | ||
} | ||
} | ||
sb.WriteString(";") | ||
tk.MustExec(sb.String()) | ||
require.Equal(t, int64(0), ingest.LitMemRoot.CurrentUsage()) | ||
tk.MustExec("alter table t add index idx(a);") | ||
tk.MustExec("alter table t add unique index idx1(b);") | ||
tk.MustExec("admin check table t;") | ||
require.Equal(t, int64(0), ingest.LitMemRoot.CurrentUsage()) | ||
} | ||
|
||
func TestAddIndexIngestLimitOneBackend(t *testing.T) { | ||
store := realtikvtest.CreateMockStoreAndSetup(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("drop database if exists addindexlit;") | ||
tk.MustExec("create database addindexlit;") | ||
tk.MustExec("use addindexlit;") | ||
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`) | ||
tk.MustExec("create table t (a int, b int);") | ||
tk.MustExec("insert into t values (1, 1), (2, 2), (3, 3);") | ||
|
||
tk2 := testkit.NewTestKit(t, store) | ||
tk2.MustExec("use addindexlit;") | ||
tk2.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`) | ||
tk2.MustExec("create table t2 (a int, b int);") | ||
tk2.MustExec("insert into t2 values (1, 1), (2, 2), (3, 3);") | ||
|
||
// Mock there is a running ingest job. | ||
ingest.LitBackCtxMgr.Store(65535, &ingest.BackendContext{}) | ||
wg := &sync.WaitGroup{} | ||
wg.Add(2) | ||
go func() { | ||
tk.MustExec("alter table t add index idx(a);") | ||
wg.Done() | ||
}() | ||
go func() { | ||
tk2.MustExec("alter table t2 add index idx_b(b);") | ||
wg.Done() | ||
}() | ||
wg.Wait() | ||
rows := tk.MustQuery("admin show ddl jobs 2;").Rows() | ||
require.Len(t, rows, 2) | ||
require.False(t, strings.Contains(rows[0][3].(string) /* job_type */, "ingest")) | ||
require.False(t, strings.Contains(rows[1][3].(string) /* job_type */, "ingest")) | ||
require.Equal(t, rows[0][7].(string) /* row_count */, "3") | ||
require.Equal(t, rows[1][7].(string) /* row_count */, "3") | ||
|
||
// Remove the running ingest job. | ||
ingest.LitBackCtxMgr.Delete(65535) | ||
tk.MustExec("alter table t add index idx_a(a);") | ||
rows = tk.MustQuery("admin show ddl jobs 1;").Rows() | ||
require.Len(t, rows, 1) | ||
require.True(t, strings.Contains(rows[0][3].(string) /* job_type */, "ingest")) | ||
require.Equal(t, rows[0][7].(string) /* row_count */, "3") | ||
} |
This file was deleted.
Oops, something went wrong.