@@ -31,21 +31,19 @@ import (
31
31
"go.uber.org/zap"
32
32
)
33
33
34
- type handler struct {
34
+ type subscriber struct {
35
35
statsCache types.StatsCache
36
36
}
37
37
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 (
41
40
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
46
44
}
47
45
48
- func (h handler ) handle (
46
+ func (h subscriber ) handle (
49
47
ctx context.Context ,
50
48
sctx sessionctx.Context ,
51
49
change * notifier.SchemaChangeEvent ,
@@ -235,6 +233,19 @@ func (h handler) handle(
235
233
return errors .Trace (storage .UpdateStatsVersion (ctx , sctx ))
236
234
case model .ActionAddIndex :
237
235
// 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
+ }
238
249
default :
239
250
intest .Assert (false )
240
251
logutil .StatsLogger ().Error ("Unhandled schema change event" ,
@@ -243,7 +254,7 @@ func (h handler) handle(
243
254
return nil
244
255
}
245
256
246
- func (h handler ) insertStats4PhysicalID (
257
+ func (h subscriber ) insertStats4PhysicalID (
247
258
ctx context.Context ,
248
259
sctx sessionctx.Context ,
249
260
info * model.TableInfo ,
@@ -256,7 +267,7 @@ func (h handler) insertStats4PhysicalID(
256
267
return errors .Trace (h .recordHistoricalStatsMeta (ctx , sctx , id , startTS ))
257
268
}
258
269
259
- func (h handler ) recordHistoricalStatsMeta (
270
+ func (h subscriber ) recordHistoricalStatsMeta (
260
271
ctx context.Context ,
261
272
sctx sessionctx.Context ,
262
273
id int64 ,
@@ -287,7 +298,7 @@ func (h handler) recordHistoricalStatsMeta(
287
298
)
288
299
}
289
300
290
- func (h handler ) delayedDeleteStats4PhysicalID (
301
+ func (h subscriber ) delayedDeleteStats4PhysicalID (
291
302
ctx context.Context ,
292
303
sctx sessionctx.Context ,
293
304
id int64 ,
@@ -299,7 +310,7 @@ func (h handler) delayedDeleteStats4PhysicalID(
299
310
return errors .Trace (h .recordHistoricalStatsMeta (ctx , sctx , id , startTS ))
300
311
}
301
312
302
- func (h handler ) insertStats4Col (
313
+ func (h subscriber ) insertStats4Col (
303
314
ctx context.Context ,
304
315
sctx sessionctx.Context ,
305
316
physicalID int64 ,
0 commit comments