From 2982e61beeff62dd63d446f6c1a35a7f9b744475 Mon Sep 17 00:00:00 2001 From: tangenta Date: Tue, 15 Aug 2023 16:18:37 +0800 Subject: [PATCH 1/3] This is an automated cherry-pick of #46055 Signed-off-by: ti-chi-bot --- ddl/index_cop.go | 2 +- ddl/ingest/BUILD.bazel | 5 +++ ddl/ingest/integration_test.go | 69 ++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/ddl/index_cop.go b/ddl/index_cop.go index 8098855cb79ef..d90b88cae8fd9 100644 --- a/ddl/index_cop.go +++ b/ddl/index_cop.go @@ -482,7 +482,7 @@ func getRestoreData(tblInfo *model.TableInfo, targetIdx, pkIdx *model.IndexInfo, func buildDAGPB(sCtx sessionctx.Context, tblInfo *model.TableInfo, colInfos []*model.ColumnInfo) (*tipb.DAGRequest, error) { dagReq := &tipb.DAGRequest{} - dagReq.TimeZoneName, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location()) + _, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location()) sc := sCtx.GetSessionVars().StmtCtx dagReq.Flags = sc.PushDownFlags() for i := range colInfos { diff --git a/ddl/ingest/BUILD.bazel b/ddl/ingest/BUILD.bazel index 12e8156165139..bc8bef28c2fe0 100644 --- a/ddl/ingest/BUILD.bazel +++ b/ddl/ingest/BUILD.bazel @@ -62,7 +62,12 @@ go_test( ], embed = [":ingest"], flaky = True, +<<<<<<< HEAD shard_count = 12, +======= + race = "on", + shard_count = 15, +>>>>>>> 5a305400a94 (ddl: use the correct timezone to encode record for adding index (#46055)) deps = [ "//config", "//ddl/internal/session", diff --git a/ddl/ingest/integration_test.go b/ddl/ingest/integration_test.go index 4bf36a02fedb5..32395340a7a23 100644 --- a/ddl/ingest/integration_test.go +++ b/ddl/ingest/integration_test.go @@ -189,3 +189,72 @@ func TestAddIndexCancelOnNoneState(t *testing.T) { require.NoError(t, err) require.True(t, available) } +<<<<<<< HEAD +======= + +func TestAddIndexIngestRecoverPartition(t *testing.T) { + port := config.GetGlobalConfig().Port + tc := testkit.NewDistExecutionContext(t, 3) + defer tc.Close() + defer injectMockBackendMgr(t, tc.Store)() + tk := testkit.NewTestKit(t, tc.Store) + tk.MustExec("use test;") + tk.MustExec("create table t (a int primary key, b int) partition by hash(a) partitions 8;") + tk.MustExec("insert into t values (2, 3), (3, 3), (5, 5);") + + partCnt := 0 + changeOwner0To1 := func(job *model.Job, _ int64) { + partCnt++ + if partCnt == 3 { + tc.SetOwner(1) + // TODO(tangenta): mock multiple backends in a better way. + //nolint: forcetypeassert + ingest.LitBackCtxMgr.(*ingest.MockBackendCtxMgr).ResetSessCtx() + bc, _ := ingest.LitBackCtxMgr.Load(job.ID) + bc.GetCheckpointManager().Close() + bc.AttachCheckpointManager(nil) + config.GetGlobalConfig().Port = port + 1 + } + } + changeOwner1To2 := func(job *model.Job, _ int64) { + partCnt++ + if partCnt == 6 { + tc.SetOwner(2) + //nolint: forcetypeassert + ingest.LitBackCtxMgr.(*ingest.MockBackendCtxMgr).ResetSessCtx() + bc, _ := ingest.LitBackCtxMgr.Load(job.ID) + bc.GetCheckpointManager().Close() + bc.AttachCheckpointManager(nil) + config.GetGlobalConfig().Port = port + 2 + } + } + tc.SetOwner(0) + hook0 := &callback.TestDDLCallback{} + hook0.OnUpdateReorgInfoExported = changeOwner0To1 + hook1 := &callback.TestDDLCallback{} + hook1.OnUpdateReorgInfoExported = changeOwner1To2 + tc.GetDomain(0).DDL().SetHook(hook0) + tc.GetDomain(1).DDL().SetHook(hook1) + tk.MustExec("alter table t add index idx(b);") + tk.MustExec("admin check table t;") +} + +func TestAddIndexIngestTimezone(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test;") + defer injectMockBackendMgr(t, store)() + + tk.MustExec("SET time_zone = '-06:00';") + tk.MustExec("create table t (`src` varchar(48),`t` timestamp,`timezone` varchar(100));") + tk.MustExec("insert into t values('2000-07-29 23:15:30','2000-07-29 23:15:30','-6:00');") + tk.MustExec("alter table t add index idx(t);") + tk.MustExec("admin check table t;") + + tk.MustExec("alter table t drop index idx;") + tk.MustExec("SET time_zone = 'Asia/Shanghai';") + tk.MustExec("insert into t values('2000-07-29 23:15:30','2000-07-29 23:15:30', '+8:00');") + tk.MustExec("alter table t add index idx(t);") + tk.MustExec("admin check table t;") +} +>>>>>>> 5a305400a94 (ddl: use the correct timezone to encode record for adding index (#46055)) From c0bbfaaa71f40a70909fc4e9701655c0af5ca078 Mon Sep 17 00:00:00 2001 From: tangenta Date: Tue, 22 Aug 2023 11:43:08 +0800 Subject: [PATCH 2/3] resolve conflict --- ddl/ingest/BUILD.bazel | 5 ---- ddl/ingest/integration_test.go | 50 ---------------------------------- 2 files changed, 55 deletions(-) diff --git a/ddl/ingest/BUILD.bazel b/ddl/ingest/BUILD.bazel index bc8bef28c2fe0..12e8156165139 100644 --- a/ddl/ingest/BUILD.bazel +++ b/ddl/ingest/BUILD.bazel @@ -62,12 +62,7 @@ go_test( ], embed = [":ingest"], flaky = True, -<<<<<<< HEAD shard_count = 12, -======= - race = "on", - shard_count = 15, ->>>>>>> 5a305400a94 (ddl: use the correct timezone to encode record for adding index (#46055)) deps = [ "//config", "//ddl/internal/session", diff --git a/ddl/ingest/integration_test.go b/ddl/ingest/integration_test.go index 32395340a7a23..ca1871f0dcfde 100644 --- a/ddl/ingest/integration_test.go +++ b/ddl/ingest/integration_test.go @@ -189,55 +189,6 @@ func TestAddIndexCancelOnNoneState(t *testing.T) { require.NoError(t, err) require.True(t, available) } -<<<<<<< HEAD -======= - -func TestAddIndexIngestRecoverPartition(t *testing.T) { - port := config.GetGlobalConfig().Port - tc := testkit.NewDistExecutionContext(t, 3) - defer tc.Close() - defer injectMockBackendMgr(t, tc.Store)() - tk := testkit.NewTestKit(t, tc.Store) - tk.MustExec("use test;") - tk.MustExec("create table t (a int primary key, b int) partition by hash(a) partitions 8;") - tk.MustExec("insert into t values (2, 3), (3, 3), (5, 5);") - - partCnt := 0 - changeOwner0To1 := func(job *model.Job, _ int64) { - partCnt++ - if partCnt == 3 { - tc.SetOwner(1) - // TODO(tangenta): mock multiple backends in a better way. - //nolint: forcetypeassert - ingest.LitBackCtxMgr.(*ingest.MockBackendCtxMgr).ResetSessCtx() - bc, _ := ingest.LitBackCtxMgr.Load(job.ID) - bc.GetCheckpointManager().Close() - bc.AttachCheckpointManager(nil) - config.GetGlobalConfig().Port = port + 1 - } - } - changeOwner1To2 := func(job *model.Job, _ int64) { - partCnt++ - if partCnt == 6 { - tc.SetOwner(2) - //nolint: forcetypeassert - ingest.LitBackCtxMgr.(*ingest.MockBackendCtxMgr).ResetSessCtx() - bc, _ := ingest.LitBackCtxMgr.Load(job.ID) - bc.GetCheckpointManager().Close() - bc.AttachCheckpointManager(nil) - config.GetGlobalConfig().Port = port + 2 - } - } - tc.SetOwner(0) - hook0 := &callback.TestDDLCallback{} - hook0.OnUpdateReorgInfoExported = changeOwner0To1 - hook1 := &callback.TestDDLCallback{} - hook1.OnUpdateReorgInfoExported = changeOwner1To2 - tc.GetDomain(0).DDL().SetHook(hook0) - tc.GetDomain(1).DDL().SetHook(hook1) - tk.MustExec("alter table t add index idx(b);") - tk.MustExec("admin check table t;") -} func TestAddIndexIngestTimezone(t *testing.T) { store := testkit.CreateMockStore(t) @@ -257,4 +208,3 @@ func TestAddIndexIngestTimezone(t *testing.T) { tk.MustExec("alter table t add index idx(t);") tk.MustExec("admin check table t;") } ->>>>>>> 5a305400a94 (ddl: use the correct timezone to encode record for adding index (#46055)) From be14c87c67486e894c79b7dc31df466b36841ffa Mon Sep 17 00:00:00 2001 From: tangenta Date: Tue, 22 Aug 2023 12:03:12 +0800 Subject: [PATCH 3/3] update bazel --- ddl/ingest/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddl/ingest/BUILD.bazel b/ddl/ingest/BUILD.bazel index 12e8156165139..7355bd25db3ac 100644 --- a/ddl/ingest/BUILD.bazel +++ b/ddl/ingest/BUILD.bazel @@ -62,7 +62,7 @@ go_test( ], embed = [":ingest"], flaky = True, - shard_count = 12, + shard_count = 13, deps = [ "//config", "//ddl/internal/session",