Skip to content

Commit 068b9a8

Browse files
authored
statistics: temporarily skip handling errors for DDL events (#58609)
ref #58545
1 parent 284a3ee commit 068b9a8

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

pkg/statistics/handle/ddl/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ go_test(
3131
timeout = "short",
3232
srcs = ["ddl_test.go"],
3333
flaky = True,
34-
shard_count = 20,
34+
shard_count = 21,
3535
deps = [
3636
":ddl",
3737
"//pkg/ddl/notifier",

pkg/statistics/handle/ddl/ddl.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"github.com/pingcap/tidb/pkg/ddl/notifier"
2222
"github.com/pingcap/tidb/pkg/sessionctx"
2323
"github.com/pingcap/tidb/pkg/statistics/handle/lockstats"
24+
statslogutil "github.com/pingcap/tidb/pkg/statistics/handle/logutil"
2425
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
2526
"github.com/pingcap/tidb/pkg/statistics/handle/types"
2627
"github.com/pingcap/tidb/pkg/statistics/handle/util"
28+
"go.uber.org/zap"
2729
)
2830

2931
type ddlHandlerImpl struct {
@@ -48,7 +50,16 @@ func NewDDLHandler(
4850

4951
// HandleDDLEvent begins to process a ddl task.
5052
func (h *ddlHandlerImpl) HandleDDLEvent(ctx context.Context, sctx sessionctx.Context, s *notifier.SchemaChangeEvent) error {
51-
return h.sub.handle(ctx, sctx, s)
53+
// Ideally, we shouldn't allow any errors to be ignored, but for now, some queries can fail.
54+
// Temporarily ignore the error and we need to check all queries to ensure they are correct.
55+
if err := h.sub.handle(ctx, sctx, s); err != nil {
56+
statslogutil.StatsLogger().Warn(
57+
"failed to handle DDL event",
58+
zap.String("event", s.String()),
59+
zap.Error(err),
60+
)
61+
}
62+
return nil
5263
}
5364

5465
// DDLEventCh returns ddl events channel in handle.

pkg/statistics/handle/ddl/ddl_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,3 +1380,18 @@ func TestExchangePartition(t *testing.T) {
13801380
require.Equal(t, int64(200), count)
13811381
require.Equal(t, int64(200), modifyCount)
13821382
}
1383+
1384+
func TestDumpStatsDeltaBeforeHandleDDLEvent(t *testing.T) {
1385+
store, dom := testkit.CreateMockStoreAndDomain(t)
1386+
tk := testkit.NewTestKit(t, store)
1387+
tk.MustExec("use test")
1388+
tk.MustExec("create table t (c1 int)")
1389+
// Insert some data.
1390+
tk.MustExec("insert into t values (1), (2), (3)")
1391+
h := dom.StatsHandle()
1392+
require.NoError(t, h.DumpStatsDeltaToKV(true))
1393+
// Find the DDL event.
1394+
event := findEvent(h.DDLEventCh(), model.ActionCreateTable)
1395+
err := statstestutil.HandleDDLEventWithTxn(h, event)
1396+
require.NoError(t, err)
1397+
}

0 commit comments

Comments
 (0)