@@ -28,6 +28,7 @@ import (
2828 berrors "github.com/pingcap/tidb/br/pkg/errors"
2929 "github.com/pingcap/tidb/br/pkg/glue"
3030 "github.com/pingcap/tidb/br/pkg/logutil"
31+ "github.com/pingcap/tidb/br/pkg/stream/backupmetas"
3132 "github.com/pingcap/tidb/br/pkg/utils/consts"
3233 "github.com/pingcap/tidb/br/pkg/utils/iter"
3334 "github.com/pingcap/tidb/pkg/objstore"
@@ -112,7 +113,8 @@ func (ms *StreamMetadataSet) LoadUntilAndCalculateShiftTS(
112113 err := FastUnmarshalMetaData (ctx , s ,
113114 0 ,
114115 until ,
115- ms .MetadataDownloadBatchSize , func (path string , raw []byte ) error {
116+ ms .MetadataDownloadBatchSize ,
117+ func (string ) bool { return false }, func (filename string , raw []byte ) error {
116118 m , err := ms .Helper .ParseToMetadataHard (raw )
117119 if err != nil {
118120 return err
@@ -136,15 +138,15 @@ func (ms *StreamMetadataSet) LoadUntilAndCalculateShiftTS(
136138 })
137139 }
138140 metadataMap .Lock ()
139- metadataMap .metas [path ] = & MetadataInfo {
141+ metadataMap .metas [filename ] = & MetadataInfo {
140142 MinTS : m .MinTs ,
141143 FileGroupInfos : fileGroupInfos ,
142144 }
143145 metadataMap .Unlock ()
144146 }
145147 // filter out the metadatas whose ts-range is overlap with [until, +inf)
146148 // and calculate their minimum begin-default-ts
147- ts , ok := UpdateShiftTS (m , until , mathutil .MaxUint )
149+ ts , ok := UpdateShiftTS (filename , m , until , mathutil .MaxUint )
148150 if ok {
149151 metadataMap .Lock ()
150152 if ts < metadataMap .shiftUntilTS {
@@ -164,12 +166,6 @@ func (ms *StreamMetadataSet) LoadUntilAndCalculateShiftTS(
164166 return metadataMap .shiftUntilTS , nil
165167}
166168
167- // LoadFrom loads data from an external storage into the stream metadata set. (Now only for test)
168- func (ms * StreamMetadataSet ) LoadFrom (ctx context.Context , s storeapi.Storage ) error {
169- _ , err := ms .LoadUntilAndCalculateShiftTS (ctx , s , math .MaxUint64 )
170- return err
171- }
172-
173169func (ms * StreamMetadataSet ) iterateDataFiles (f func (d * FileGroupInfo ) (shouldBreak bool )) {
174170 for _ , m := range ms .metadataInfos {
175171 if slices .ContainsFunc (m .FileGroupInfos , f ) {
@@ -295,7 +291,26 @@ func SetTSToFile(
295291 return truncateAndWrite (ctx , s , filename , []byte (content ))
296292}
297293
298- func UpdateShiftTS (m * pb.Metadata , startTS uint64 , restoreTS uint64 ) (uint64 , bool ) {
294+ func TryParseTaggedBackupMetaFileNameWrapper (filename string ) (backupmetas.ParsedName , error ) {
295+ baseName := strings .TrimSuffix (path .Base (filename ), metaSuffix )
296+ return backupmetas .TryParseTaggedBackupMetaFileName (baseName )
297+ }
298+
299+ func UpdateShiftTS (filename string , m * pb.Metadata , startTS , restoreTS uint64 ) (uint64 , bool ) {
300+ parsedName , err := TryParseTaggedBackupMetaFileNameWrapper (filename )
301+ if err == nil {
302+ ts , status := parsedName .CalculateShiftTS (startTS , restoreTS )
303+ switch status {
304+ case backupmetas .ShiftTSFound :
305+ return ts , true
306+ case backupmetas .ShiftTSNotFound :
307+ return 0 , false
308+ }
309+ }
310+ return UpdateShiftTSFromMetadata (m , startTS , restoreTS )
311+ }
312+
313+ func UpdateShiftTSFromMetadata (m * pb.Metadata , startTS uint64 , restoreTS uint64 ) (uint64 , bool ) {
299314 var (
300315 minBeginTS uint64
301316 isExist bool
0 commit comments