github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/backup/check.go (about)

     1  // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
     2  
     3  package backup
     4  
     5  import (
     6  	"encoding/hex"
     7  
     8  	"github.com/google/btree"
     9  	"github.com/pingcap/log"
    10  	"go.uber.org/zap"
    11  
    12  	"github.com/pingcap/br/pkg/rtree"
    13  )
    14  
    15  // checkDupFiles checks if there are any files are duplicated.
    16  func checkDupFiles(rangeTree *rtree.RangeTree) {
    17  	// Name -> SHA256
    18  	files := make(map[string][]byte)
    19  	rangeTree.Ascend(func(i btree.Item) bool {
    20  		rg := i.(*rtree.Range)
    21  		for _, f := range rg.Files {
    22  			old, ok := files[f.Name]
    23  			if ok {
    24  				log.Error("dup file",
    25  					zap.String("Name", f.Name),
    26  					zap.String("SHA256_1", hex.EncodeToString(old)),
    27  					zap.String("SHA256_2", hex.EncodeToString(f.Sha256)),
    28  				)
    29  			} else {
    30  				files[f.Name] = f.Sha256
    31  			}
    32  		}
    33  		return true
    34  	})
    35  }