Skip to content

Commit 2cc97f3

Browse files
committed
statistics: rename subscriber and handle drop schema event (pingcap#58009)
ref pingcap#57871
1 parent 71bc625 commit 2cc97f3

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

pkg/statistics/handle/ddl/subscriber.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,19 @@ import (
3131
"go.uber.org/zap"
3232
)
3333

34-
type handler struct {
34+
type subscriber struct {
3535
statsCache types.StatsCache
3636
}
3737

38-
// NewHandlerAndRegister creates a new handler and registers it to the DDL
39-
// notifier.
40-
func NewHandlerAndRegister(
38+
// NewSubscriber creates a new subscriber.
39+
func NewSubscriber(
4140
statsCache types.StatsCache,
42-
registry *notifier.DDLNotifier,
43-
) {
44-
h := handler{statsCache: statsCache}
45-
registry.RegisterHandler(notifier.StatsMetaHandlerID, h.handle)
41+
) *subscriber {
42+
h := subscriber{statsCache: statsCache}
43+
return &h
4644
}
4745

48-
func (h handler) handle(
46+
func (h subscriber) handle(
4947
ctx context.Context,
5048
sctx sessionctx.Context,
5149
change *notifier.SchemaChangeEvent,
@@ -235,6 +233,19 @@ func (h handler) handle(
235233
return errors.Trace(storage.UpdateStatsVersion(ctx, sctx))
236234
case model.ActionAddIndex:
237235
// No need to update the stats meta for the adding index event.
236+
case model.ActionDropSchema:
237+
miniDBInfo := change.GetDropSchemaInfo()
238+
intest.Assert(miniDBInfo != nil)
239+
for _, table := range miniDBInfo.Tables {
240+
// Try best effort to update the stats meta version for gc.
241+
if err := h.delayedDeleteStats4PhysicalID(ctx, sctx, table.ID); err != nil {
242+
logutil.StatsLogger().Error(
243+
"Failed to update stats meta version for gc",
244+
zap.Int64("tableID", table.ID),
245+
zap.Error(err),
246+
)
247+
}
248+
}
238249
default:
239250
intest.Assert(false)
240251
logutil.StatsLogger().Error("Unhandled schema change event",
@@ -243,7 +254,7 @@ func (h handler) handle(
243254
return nil
244255
}
245256

246-
func (h handler) insertStats4PhysicalID(
257+
func (h subscriber) insertStats4PhysicalID(
247258
ctx context.Context,
248259
sctx sessionctx.Context,
249260
info *model.TableInfo,
@@ -256,7 +267,7 @@ func (h handler) insertStats4PhysicalID(
256267
return errors.Trace(h.recordHistoricalStatsMeta(ctx, sctx, id, startTS))
257268
}
258269

259-
func (h handler) recordHistoricalStatsMeta(
270+
func (h subscriber) recordHistoricalStatsMeta(
260271
ctx context.Context,
261272
sctx sessionctx.Context,
262273
id int64,
@@ -287,7 +298,7 @@ func (h handler) recordHistoricalStatsMeta(
287298
)
288299
}
289300

290-
func (h handler) delayedDeleteStats4PhysicalID(
301+
func (h subscriber) delayedDeleteStats4PhysicalID(
291302
ctx context.Context,
292303
sctx sessionctx.Context,
293304
id int64,
@@ -299,7 +310,7 @@ func (h handler) delayedDeleteStats4PhysicalID(
299310
return errors.Trace(h.recordHistoricalStatsMeta(ctx, sctx, id, startTS))
300311
}
301312

302-
func (h handler) insertStats4Col(
313+
func (h subscriber) insertStats4Col(
303314
ctx context.Context,
304315
sctx sessionctx.Context,
305316
physicalID int64,

0 commit comments

Comments
 (0)