@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
"github.com/pingcap/errors"
25
+ "github.com/pingcap/failpoint"
25
26
"github.com/pingcap/tidb/pkg/infoschema"
26
27
"github.com/pingcap/tidb/pkg/metrics"
27
28
"github.com/pingcap/tidb/pkg/parser/model"
@@ -127,8 +128,13 @@ func (s *statsUsageImpl) DumpStatsDeltaToKV(dumpAll bool) error {
127
128
// For a partitioned table, we will update its global-stats as well.
128
129
func (s * statsUsageImpl ) dumpTableStatCountToKV (is infoschema.InfoSchema , physicalTableID int64 , delta variable.TableDelta ) (updated bool , err error ) {
129
130
statsVersion := uint64 (0 )
131
+ isLocked := false
130
132
defer func () {
131
- if err == nil && statsVersion != 0 {
133
+ // Only record the historical stats meta when the table is not locked because all stats meta are stored in the locked table.
134
+ if err == nil && statsVersion != 0 && ! isLocked {
135
+ failpoint .Inject ("panic-when-record-historical-stats-meta" , func () {
136
+ panic ("panic when record historical stats meta" )
137
+ })
132
138
s .statsHandle .RecordHistoricalStatsMeta (physicalTableID , statsVersion , "flush stats" , false )
133
139
}
134
140
}()
@@ -169,7 +175,12 @@ func (s *statsUsageImpl) dumpTableStatCountToKV(is infoschema.InfoSchema, physic
169
175
isPartitionLocked = true
170
176
}
171
177
tableOrPartitionLocked := isTableLocked || isPartitionLocked
178
+ << << << < HEAD
172
179
if err = storage .UpdateStatsMeta (sctx , statsVersion , delta ,
180
+ == == == =
181
+ isLocked = tableOrPartitionLocked
182
+ if err = storage .UpdateStatsMeta (utilstats .StatsCtx , sctx , statsVersion , delta ,
183
+ >> >> >> > 5e73267 e719 (statistics : do not record historical stats meta if the table is locked (#57636 ))
173
184
physicalTableID , tableOrPartitionLocked ); err != nil {
174
185
return err
175
186
}
@@ -199,7 +210,12 @@ func (s *statsUsageImpl) dumpTableStatCountToKV(is infoschema.InfoSchema, physic
199
210
if _ , ok := lockedTables [physicalTableID ]; ok {
200
211
isTableLocked = true
201
212
}
213
+ << << << < HEAD
202
214
if err = storage .UpdateStatsMeta (sctx , statsVersion , delta ,
215
+ == == == =
216
+ isLocked = isTableLocked
217
+ if err = storage .UpdateStatsMeta (utilstats .StatsCtx , sctx , statsVersion , delta ,
218
+ >> >> >> > 5e73267 e719 (statistics : do not record historical stats meta if the table is locked (#57636 ))
203
219
physicalTableID , isTableLocked ); err != nil {
204
220
return err
205
221
}
0 commit comments