@@ -19,7 +19,6 @@ import (
19
19
"crypto/sha256"
20
20
"encoding/json"
21
21
"fmt"
22
- "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/db/gc/v3"
23
22
"io"
24
23
"os"
25
24
"path"
@@ -30,6 +29,9 @@ import (
30
29
"sync"
31
30
"time"
32
31
32
+ "github.com/matrixorigin/matrixone/pkg/objectio/ioutil"
33
+ "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/db/gc/v3"
34
+
33
35
"github.com/matrixorigin/matrixone/pkg/common/moerr"
34
36
"github.com/matrixorigin/matrixone/pkg/common/runtime"
35
37
"github.com/matrixorigin/matrixone/pkg/container/types"
@@ -39,7 +41,6 @@ import (
39
41
"github.com/matrixorigin/matrixone/pkg/objectio"
40
42
"github.com/matrixorigin/matrixone/pkg/sql/plan/function/ctl"
41
43
"github.com/matrixorigin/matrixone/pkg/util/executor"
42
- "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/blockio"
43
44
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common"
44
45
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/db/checkpoint"
45
46
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logtail"
@@ -305,7 +306,7 @@ func execBackup(
305
306
if err != nil {
306
307
return err
307
308
}
308
- key , err := blockio . EncodeLocationFromString (metaLoc )
309
+ key , err := objectio . StringToLocation (metaLoc )
309
310
if err != nil {
310
311
return err
311
312
}
@@ -372,7 +373,7 @@ func execBackup(
372
373
taeFileList = append (taeFileList , sizeList ... )
373
374
now = time .Now ()
374
375
if trimInfo != "" {
375
- cnLocation , err := blockio . EncodeLocationFromString (cnLoc )
376
+ cnLocation , err := objectio . StringToLocation (cnLoc )
376
377
if err != nil {
377
378
return err
378
379
}
@@ -426,32 +427,34 @@ func execBackup(
426
427
427
428
// CopyCheckpointDir copy checkpoint dir from srcFs to dstFs
428
429
// return taeFile list
429
- // copy : if copy is true,it means not to check the suffix name and copy all files.
430
+ // doCopy : if doCopy is true,it means not to check the suffix name and doCopy all files.
430
431
func copyFileAndGetMetaFiles (
431
432
ctx context.Context ,
432
433
srcFs , dstFs fileservice.FileService ,
433
434
dir string ,
434
435
backup types.TS ,
435
- decodeFunc func (string ) (types. TS , types. TS , string ) ,
436
- copy bool ,
437
- ) ([]* taeFile , []* checkpoint. MetaFile , []fileservice.DirEntry , error ) {
436
+ decoder func (string ) ioutil. TSRangeFile ,
437
+ doCopy bool ,
438
+ ) ([]* taeFile , []ioutil. TSRangeFile , []fileservice.DirEntry , error ) {
438
439
files , err := fileservice .SortedList (srcFs .List (ctx , dir ))
439
440
if err != nil {
440
441
return nil , nil , nil , err
441
442
}
442
443
taeFileList := make ([]* taeFile , 0 , len (files ))
443
- metaFiles := make ([]* checkpoint. MetaFile , 0 )
444
+ metaFiles := make ([]ioutil. TSRangeFile , 0 )
444
445
var checksum []byte
445
446
for i , file := range files {
446
447
if file .IsDir {
447
448
panic ("not support dir" )
448
449
}
449
- start , end , ext := decodeFunc (file .Name )
450
- if ! backup .IsEmpty () && start .GE (& backup ) {
450
+ meta := decoder (file .Name )
451
+ meta .SetIdx (i )
452
+
453
+ if ! backup .IsEmpty () && meta .GetStart ().GE (& backup ) {
451
454
logutil .Infof ("[Backup] skip file %v" , file .Name )
452
455
continue
453
456
}
454
- if copy || ext == blockio . AcctExt || ext == blockio . SnapshotExt {
457
+ if doCopy || meta . IsAcctExt () || meta . IsSnapshotExt () {
455
458
checksum , err = CopyFileWithRetry (ctx , srcFs , dstFs , file .Name , dir )
456
459
if err != nil {
457
460
return nil , nil , nil , err
@@ -465,19 +468,16 @@ func copyFileAndGetMetaFiles(
465
468
})
466
469
}
467
470
468
- if copy || ext == blockio .CheckpointExt || ext == blockio .GCFullExt {
469
- metaFile := checkpoint .NewMetaFile (i , start , end , file .Name )
470
- metaFiles = append (metaFiles , metaFile )
471
+ if doCopy || meta .IsCKPFile () || meta .IsFullGCExt () {
472
+ metaFiles = append (metaFiles , meta )
471
473
}
472
474
}
473
475
474
476
if len (metaFiles ) == 0 {
475
477
return taeFileList , metaFiles , files , nil
476
478
}
477
479
sort .Slice (metaFiles , func (i , j int ) bool {
478
- end1 := metaFiles [i ].GetEnd ()
479
- end2 := metaFiles [j ].GetEnd ()
480
- return end1 .LT (& end2 )
480
+ return metaFiles [i ].GetEnd ().LT (metaFiles [j ].GetEnd ())
481
481
})
482
482
483
483
return taeFileList , metaFiles , files , nil
@@ -492,17 +492,17 @@ func CopyGCDir(
492
492
var checksum []byte
493
493
494
494
taeFileList , metaFiles , files , err := copyFileAndGetMetaFiles (
495
- ctx , srcFs , dstFs , dir , backup , blockio .DecodeGCMetadataFileName , false )
495
+ ctx , srcFs , dstFs , dir , backup , ioutil .DecodeGCMetadataName , false ,
496
+ )
496
497
if err != nil {
497
498
return nil , err
498
499
}
499
500
500
- copyFiles := make ([]* checkpoint. MetaFile , 0 )
501
+ copyFiles := make ([]ioutil. TSRangeFile , 0 )
501
502
502
503
for _ , metaFile := range metaFiles {
503
- name := metaFile .GetName ()
504
504
window := gc .NewGCWindow (common .DebugAllocator , srcFs )
505
- err = window .ReadTable (ctx , gc . GCMetaDir + name , srcFs )
505
+ err = window .ReadTable (ctx , metaFile . GetGCFullName () , srcFs )
506
506
if err != nil {
507
507
return nil , err
508
508
}
@@ -519,7 +519,7 @@ func CopyGCDir(
519
519
}
520
520
filesList = append (filesList , & taeFile {
521
521
path : object .ObjectName ().String (),
522
- size : files [metaFile .GetIndex ()].Size ,
522
+ size : files [metaFile .GetIdx ()].Size ,
523
523
checksum : checksum ,
524
524
needCopy : true ,
525
525
ts : backup ,
@@ -534,13 +534,12 @@ func CopyGCDir(
534
534
for i , metaFile := range copyFiles {
535
535
name := metaFile .GetName ()
536
536
if i == len (metaFiles )- 1 {
537
- end := metaFile .GetEnd ()
538
- if ! min .IsEmpty () && end .LT (& min ) {
537
+ if ! min .IsEmpty () && metaFile .GetEnd ().LT (& min ) {
539
538
// It means that the gc consumption is too slow, and the gc water level needs to be raised.
540
539
// Otherwise, the gc will not work after the cluster is restored because it cannot find the checkpoint.
541
540
// The gc water level is determined by the name of the meta,
542
541
// so the name of the last gc meta needs to be modified.
543
- name = blockio . UpdateGCMetadataFileName (name , end , min )
542
+ name = ioutil . InheritGCMetadataName (name , metaFile . GetEnd (), & min )
544
543
}
545
544
}
546
545
checksum , err = CopyFileWithRetry (ctx , srcFs , dstFs , metaFile .GetName (), dir , name )
@@ -549,7 +548,7 @@ func CopyGCDir(
549
548
}
550
549
taeFileList = append (taeFileList , & taeFile {
551
550
path : dir + string (os .PathSeparator ) + name ,
552
- size : files [metaFile .GetIndex ()].Size ,
551
+ size : files [metaFile .GetIdx ()].Size ,
553
552
checksum : checksum ,
554
553
needCopy : true ,
555
554
ts : backup ,
@@ -563,11 +562,14 @@ func CopyCheckpointDir(
563
562
srcFs , dstFs fileservice.FileService ,
564
563
dir string , backup types.TS ,
565
564
) ([]* taeFile , types.TS , error ) {
566
- decodeFunc := func (name string ) (types.TS , types.TS , string ) {
567
- start , end , _ := blockio .DecodeCheckpointMetadataFileName (name )
568
- return start , end , ""
565
+ decoder := func (name string ) ioutil.TSRangeFile {
566
+ meta := ioutil .DecodeCKPMetaName (name )
567
+ meta .SetExt ("" )
568
+ return meta
569
569
}
570
- taeFileList , metaFiles , _ , err := copyFileAndGetMetaFiles (ctx , srcFs , dstFs , dir , backup , decodeFunc , true )
570
+ taeFileList , metaFiles , _ , err := copyFileAndGetMetaFiles (
571
+ ctx , srcFs , dstFs , dir , backup , decoder , true ,
572
+ )
571
573
if err != nil {
572
574
return nil , types.TS {}, err
573
575
}
@@ -577,7 +579,7 @@ func CopyCheckpointDir(
577
579
for i := len (metaFiles ) - 1 ; i >= 0 ; i -- {
578
580
ckpStart := metaFiles [i ].GetStart ()
579
581
if ckpStart .IsEmpty () {
580
- minTs = metaFiles [i ].GetEnd ()
582
+ minTs = * metaFiles [i ].GetEnd ()
581
583
break
582
584
}
583
585
}
0 commit comments