@@ -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"
@@ -124,8 +125,13 @@ func (s *statsUsageImpl) DumpStatsDeltaToKV(dumpAll bool) error {
124
125
// For a partitioned table, we will update its global-stats as well.
125
126
func (s * statsUsageImpl ) dumpTableStatCountToKV (is infoschema.InfoSchema , physicalTableID int64 , delta variable.TableDelta ) (updated bool , err error ) {
126
127
statsVersion := uint64 (0 )
128
+ isLocked := false
127
129
defer func () {
128
- if err == nil && statsVersion != 0 {
130
+ // Only record the historical stats meta when the table is not locked because all stats meta are stored in the locked table.
131
+ if err == nil && statsVersion != 0 && ! isLocked {
132
+ failpoint .Inject ("panic-when-record-historical-stats-meta" , func () {
133
+ panic ("panic when record historical stats meta" )
134
+ })
129
135
s .statsHandle .RecordHistoricalStatsMeta (physicalTableID , statsVersion , "flush stats" , false )
130
136
}
131
137
}()
@@ -166,7 +172,12 @@ func (s *statsUsageImpl) dumpTableStatCountToKV(is infoschema.InfoSchema, physic
166
172
isPartitionLocked = true
167
173
}
168
174
tableOrPartitionLocked := isTableLocked || isPartitionLocked
175
+ << << << < HEAD
169
176
if err = storage .UpdateStatsMeta (sctx , statsVersion , delta ,
177
+ == == == =
178
+ isLocked = tableOrPartitionLocked
179
+ if err = storage .UpdateStatsMeta (utilstats .StatsCtx , sctx , statsVersion , delta ,
180
+ >> >> >> > 5e73267 e719 (statistics : do not record historical stats meta if the table is locked (#57636 ))
170
181
physicalTableID , tableOrPartitionLocked ); err != nil {
171
182
return err
172
183
}
@@ -196,7 +207,12 @@ func (s *statsUsageImpl) dumpTableStatCountToKV(is infoschema.InfoSchema, physic
196
207
if _ , ok := lockedTables [physicalTableID ]; ok {
197
208
isTableLocked = true
198
209
}
210
+ << << << < HEAD
199
211
if err = storage .UpdateStatsMeta (sctx , statsVersion , delta ,
212
+ == == == =
213
+ isLocked = isTableLocked
214
+ if err = storage .UpdateStatsMeta (utilstats .StatsCtx , sctx , statsVersion , delta ,
215
+ >> >> >> > 5e73267 e719 (statistics : do not record historical stats meta if the table is locked (#57636 ))
200
216
physicalTableID , isTableLocked ); err != nil {
201
217
return err
202
218
}
0 commit comments