From ea6478485dc2cef234a4855ece6c5ab7d05598ee Mon Sep 17 00:00:00 2001 From: Rustin170506 Date: Mon, 30 Dec 2024 15:01:02 +0800 Subject: [PATCH 1/2] statistics: temporarily skip handling errors for DDL events Signed-off-by: Rustin170506 --- pkg/statistics/handle/ddl/ddl.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/statistics/handle/ddl/ddl.go b/pkg/statistics/handle/ddl/ddl.go index 2cc06ce54316d..dbc8be123b83e 100644 --- a/pkg/statistics/handle/ddl/ddl.go +++ b/pkg/statistics/handle/ddl/ddl.go @@ -21,9 +21,11 @@ import ( "github.com/pingcap/tidb/pkg/ddl/notifier" "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/statistics/handle/lockstats" + statslogutil "github.com/pingcap/tidb/pkg/statistics/handle/logutil" "github.com/pingcap/tidb/pkg/statistics/handle/storage" "github.com/pingcap/tidb/pkg/statistics/handle/types" "github.com/pingcap/tidb/pkg/statistics/handle/util" + "go.uber.org/zap" ) type ddlHandlerImpl struct { @@ -48,7 +50,16 @@ func NewDDLHandler( // HandleDDLEvent begins to process a ddl task. func (h *ddlHandlerImpl) HandleDDLEvent(ctx context.Context, sctx sessionctx.Context, s *notifier.SchemaChangeEvent) error { - return h.sub.handle(ctx, sctx, s) + // Ideally, we shouldn't allow any errors to be ignored, but for now, some queries can fail. + // Temporarily ignore the error and we need to check all queries to ensure they are correct. + if err := h.sub.handle(ctx, sctx, s); err != nil { + statslogutil.StatsLogger().Warn( + "failed to handle DDL event", + zap.String("event", s.String()), + zap.Error(err), + ) + } + return nil } // DDLEventCh returns ddl events channel in handle. From a00b8a8fbf7fdd997f890f0e3dcc90a2bd18d479 Mon Sep 17 00:00:00 2001 From: Rustin170506 Date: Mon, 30 Dec 2024 15:05:46 +0800 Subject: [PATCH 2/2] test: add uint tests Signed-off-by: Rustin170506 --- pkg/statistics/handle/ddl/BUILD.bazel | 2 +- pkg/statistics/handle/ddl/ddl_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/statistics/handle/ddl/BUILD.bazel b/pkg/statistics/handle/ddl/BUILD.bazel index 991a65647abe1..fdef8d1b713fd 100644 --- a/pkg/statistics/handle/ddl/BUILD.bazel +++ b/pkg/statistics/handle/ddl/BUILD.bazel @@ -31,7 +31,7 @@ go_test( timeout = "short", srcs = ["ddl_test.go"], flaky = True, - shard_count = 20, + shard_count = 21, deps = [ ":ddl", "//pkg/ddl/notifier", diff --git a/pkg/statistics/handle/ddl/ddl_test.go b/pkg/statistics/handle/ddl/ddl_test.go index aa3e88fd49b19..1ecd62335ddf1 100644 --- a/pkg/statistics/handle/ddl/ddl_test.go +++ b/pkg/statistics/handle/ddl/ddl_test.go @@ -1380,3 +1380,18 @@ func TestExchangePartition(t *testing.T) { require.Equal(t, int64(200), count) require.Equal(t, int64(200), modifyCount) } + +func TestDumpStatsDeltaBeforeHandleDDLEvent(t *testing.T) { + store, dom := testkit.CreateMockStoreAndDomain(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t (c1 int)") + // Insert some data. + tk.MustExec("insert into t values (1), (2), (3)") + h := dom.StatsHandle() + require.NoError(t, h.DumpStatsDeltaToKV(true)) + // Find the DDL event. + event := findEvent(h.DDLEventCh(), model.ActionCreateTable) + err := statstestutil.HandleDDLEventWithTxn(h, event) + require.NoError(t, err) +}