@@ -146,6 +146,7 @@ func walkLeafMetaFile(
146146
147147// Table wraps the schema and files of a table.
148148type Table struct {
149+ << << << < HEAD
149150 DB * model.DBInfo
150151 Info * model.TableInfo
151152 Crc64Xor uint64
@@ -159,6 +160,18 @@ type Table struct {
159160// NoChecksum checks whether the table has a calculated checksum.
160161func (tbl * Table ) NoChecksum () bool {
161162 return tbl .Crc64Xor == 0 && tbl .TotalKvs == 0 && tbl .TotalBytes == 0
163+ == == == =
164+ DB * model .DBInfo
165+ Info * model .TableInfo
166+ Crc64Xor uint64
167+ TotalKvs uint64
168+ TotalBytes uint64
169+ Files []* backuppb.File
170+ TotalKvsMap map [int64 ]uint64
171+ TiFlashReplicas int
172+ Stats * util.JSONTable
173+ StatsFileIndexes []* backuppb.StatsFileIndex
174+ >> >> >> > e589efdb9a8 (br : fix stats meta count is zero if no checksum 8.5 (#63420 ))
162175}
163176
164177// MetaReader wraps a reader to read both old and new version of backupmeta.
@@ -233,6 +246,41 @@ func (*MetaReader) ArchiveSize(_ context.Context, files []*backuppb.File) uint64
233246 return total
234247}
235248
249+ << << << < HEAD
250+ == == == =
251+ type ChecksumStats struct {
252+ Crc64Xor uint64
253+ TotalKvs uint64
254+ TotalBytes uint64
255+ }
256+
257+ func (stats ChecksumStats ) ChecksumExists () bool {
258+ if stats .Crc64Xor == 0 && stats .TotalKvs == 0 && stats .TotalBytes == 0 {
259+ return false
260+ }
261+ return true
262+ }
263+
264+ func CalculateTotalKvsOnFiles (files []* backuppb .File ) uint64 {
265+ totalKvs := uint64 (0 )
266+ for _, file := range files {
267+ totalKvs + = file .TotalKvs
268+ }
269+ return totalKvs
270+ }
271+
272+ // CalculateChecksumStatsOnFiles returns the ChecksumStats for the given files
273+ func CalculateChecksumStatsOnFiles (files []* backuppb.File ) ChecksumStats {
274+ var stats ChecksumStats
275+ for _ , file := range files {
276+ stats .Crc64Xor ^= file .Crc64Xor
277+ stats .TotalKvs += file .TotalKvs
278+ stats .TotalBytes += file .TotalBytes
279+ }
280+ return stats
281+ }
282+
283+ >> >> >> > e589efdb9a8 (br : fix stats meta count is zero if no checksum 8.5 (#63420 ))
236284// ReadDDLs reads the ddls from the backupmeta.
237285// This function is compatible with the old backupmeta.
238286func (reader * MetaReader ) ReadDDLs (ctx context .Context ) ([]byte , error ) {
@@ -363,13 +411,19 @@ func (reader *MetaReader) ReadSchemasFiles(ctx context.Context, output chan<- *T
363411 }
364412 if tableInfo != nil {
365413 if fileMap != nil {
414+ << << << < HEAD
366415 if files , ok := fileMap [tableInfo .ID ]; ok {
416+ == == == =
417+ if files , ok := fileMap [table .Info .ID ]; ok {
418+ table .TotalKvsMap [table .Info .ID ] = CalculateTotalKvsOnFiles (files )
419+ >> >> >> > e589efdb9a8 (br : fix stats meta count is zero if no checksum 8.5 (#63420 ))
367420 table .Files = append (table .Files , files ... )
368421 }
369422 if tableInfo .Partition != nil {
370423 // Partition table can have many table IDs (partition IDs).
371424 for _ , p := range tableInfo .Partition .Definitions {
372425 if files , ok := fileMap [p .ID ]; ok {
426+ table .TotalKvsMap [p .ID ] = CalculateTotalKvsOnFiles (files )
373427 table .Files = append (table .Files , files ... )
374428 }
375429 }
@@ -395,6 +449,47 @@ func (reader *MetaReader) ReadSchemasFiles(ctx context.Context, output chan<- *T
395449 }
396450}
397451
452+ << << << < HEAD
453+ == == == =
454+ func parseSchemaFile (s * backuppb.Schema ) (* Table , error ) {
455+ dbInfo := & model.DBInfo {}
456+ if err := json .Unmarshal (s .Db , dbInfo ); err != nil {
457+ return nil , errors .Trace (err )
458+ }
459+
460+ var tableInfo * model.TableInfo
461+ if s .Table != nil {
462+ tableInfo = & model.TableInfo {}
463+ if err := json .Unmarshal (s .Table , tableInfo ); err != nil {
464+ return nil , errors .Trace (err )
465+ }
466+ }
467+ var stats * util.JSONTable
468+ if s .Stats != nil {
469+ stats = & util.JSONTable {}
470+ if err := json .Unmarshal (s .Stats , stats ); err != nil {
471+ return nil , errors .Trace (err )
472+ }
473+ }
474+ var statsFileIndexes []* backuppb.StatsFileIndex
475+ if len (s .StatsIndex ) > 0 {
476+ statsFileIndexes = s .StatsIndex
477+ }
478+
479+ return & Table {
480+ DB : dbInfo ,
481+ Info : tableInfo ,
482+ Crc64Xor : s .Crc64Xor ,
483+ TotalKvs : s .TotalKvs ,
484+ TotalBytes : s .TotalBytes ,
485+ TotalKvsMap : make (map [int64 ]uint64 ),
486+ TiFlashReplicas : int (s .TiflashReplicas ),
487+ Stats : stats ,
488+ StatsFileIndexes : statsFileIndexes ,
489+ }, nil
490+ }
491+
492+ >> >> >> > e589efdb9a8 (br : fix stats meta count is zero if no checksum 8.5 (#63420 ))
398493func receiveBatch (
399494 ctx context .Context , errCh chan error , ch < - chan interface {}, maxBatchSize int ,
400495 collectItem func (interface {}) error ,
0 commit comments