Skip to content

Commit

Permalink
statistics: temporarily skip handling errors for DDL events (#58609)
Browse files Browse the repository at this point in the history
ref #58545
  • Loading branch information
Rustin170506 authored Dec 31, 2024
1 parent 284a3ee commit 068b9a8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/statistics/handle/ddl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion pkg/statistics/handle/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions pkg/statistics/handle/ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 068b9a8

Please sign in to comment.