Skip to content

Commit

Permalink
br: skip update stats cache for br (#47597)
Browse files Browse the repository at this point in the history
close #47596
  • Loading branch information
Leavrth authored Oct 13, 2023
1 parent f770b7f commit a9e6e82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 4 additions & 3 deletions br/pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type Client struct {

// statHandler and dom are used for analyze table after restore.
// it will backup stats with #dump.DumpStatsToJSON
// and restore stats with #dump.LoadStatsFromJSON
// and restore stats with #dump.LoadStatsFromJSONNoUpdate
statsHandler *handle.Handle
dom *domain.Domain

Expand Down Expand Up @@ -1757,7 +1757,7 @@ func (rc *Client) execChecksum(
func (rc *Client) GoUpdateMetaAndLoadStats(ctx context.Context, inCh <-chan *CreatedTable, errCh chan<- error) chan *CreatedTable {
log.Info("Start to update meta then load stats")
outCh := DefaultOutputTableChan()
workers := utils.NewWorkerPool(1, "UpdateStats")
workers := utils.NewWorkerPool(16, "UpdateStats")
go concurrentHandleTablesCh(ctx, inCh, outCh, errCh, workers, func(c context.Context, tbl *CreatedTable) error {
oldTable := tbl.OldTable
// Not need to return err when failed because of update analysis-meta
Expand All @@ -1780,7 +1780,8 @@ func (rc *Client) GoUpdateMetaAndLoadStats(ctx context.Context, inCh <-chan *Cre
zap.Int64("new id", tbl.Table.ID),
)
start := time.Now()
if err := rc.statsHandler.LoadStatsFromJSON(ctx, rc.dom.InfoSchema(), oldTable.Stats, 0); err != nil {
// NOTICE: skip updating cache after load stats from json
if err := rc.statsHandler.LoadStatsFromJSONNoUpdate(ctx, rc.dom.InfoSchema(), oldTable.Stats, 0); err != nil {
log.Error("analyze table failed", zap.Any("table", oldTable.Stats), zap.Error(err))
}
log.Info("restore stat done",
Expand Down
12 changes: 11 additions & 1 deletion statistics/handle/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,17 @@ func (h *Handle) tableStatsToJSON(dbName string, tableInfo *model.TableInfo, phy
}

// LoadStatsFromJSON will load statistic from JSONTable, and save it to the storage.
// In final, it will also udpate the stats cache.
func (h *Handle) LoadStatsFromJSON(ctx context.Context, is infoschema.InfoSchema,
jsonTbl *storage.JSONTable, concurrencyForPartition uint8) error {
if err := h.LoadStatsFromJSONNoUpdate(ctx, is, jsonTbl, concurrencyForPartition); err != nil {
return errors.Trace(err)
}
return errors.Trace(h.Update(is))
}

// LoadStatsFromJSONNoUpdate will load statistic from JSONTable, and save it to the storage.
func (h *Handle) LoadStatsFromJSONNoUpdate(ctx context.Context, is infoschema.InfoSchema,
jsonTbl *storage.JSONTable, concurrencyForPartition uint8) error {
nCPU := uint8(runtime.GOMAXPROCS(0))
if concurrencyForPartition == 0 {
Expand Down Expand Up @@ -282,7 +292,7 @@ func (h *Handle) LoadStatsFromJSON(ctx context.Context, is infoschema.InfoSchema
}
}
}
return errors.Trace(h.Update(is))
return nil
}

func (h *Handle) loadStatsFromJSON(tableInfo *model.TableInfo, physicalID int64, jsonTbl *storage.JSONTable) error {
Expand Down

0 comments on commit a9e6e82

Please sign in to comment.