5
5
"crypto/rand"
6
6
"encoding/json"
7
7
"fmt"
8
+ "github.com/samber/lo"
8
9
"io"
9
10
"os"
10
11
"path/filepath"
@@ -43,19 +44,19 @@ type ExternPrecommit2 func(ctx context.Context, sector storiface.SectorRef, cach
43
44
}
44
45
*/
45
46
type SealCalls struct {
46
- sectors * storageProvider
47
+ Sectors * storageProvider
47
48
48
49
/*// externCalls cointain overrides for calling alternative sealing logic
49
50
externCalls ExternalSealer*/
50
51
}
51
52
52
53
func NewSealCalls (st * paths.Remote , ls * paths.Local , si paths.SectorIndex ) * SealCalls {
53
54
return & SealCalls {
54
- sectors : & storageProvider {
55
+ Sectors : & storageProvider {
55
56
storage : st ,
56
57
localStore : ls ,
57
58
sindex : si ,
58
- storageReservations : xsync .NewIntegerMapOf [harmonytask.TaskID , * StorageReservation ](),
59
+ storageReservations : xsync .NewIntegerMapOf [harmonytask.TaskID , [] * StorageReservation ](),
59
60
},
60
61
}
61
62
}
@@ -64,7 +65,7 @@ type storageProvider struct {
64
65
storage * paths.Remote
65
66
localStore * paths.Local
66
67
sindex paths.SectorIndex
67
- storageReservations * xsync.MapOf [harmonytask.TaskID , * StorageReservation ]
68
+ storageReservations * xsync.MapOf [harmonytask.TaskID , [] * StorageReservation ]
68
69
}
69
70
70
71
func (l * storageProvider ) AcquireSector (ctx context.Context , taskID * harmonytask.TaskID , sector storiface.SectorRef , existing , allocate storiface.SectorFileType , sealing storiface.PathType ) (fspaths , ids storiface.SectorPaths , release func (dontDeclare ... storiface.SectorFileType ), err error ) {
@@ -74,7 +75,12 @@ func (l *storageProvider) AcquireSector(ctx context.Context, taskID *harmonytask
74
75
var ok bool
75
76
var resv * StorageReservation
76
77
if taskID != nil {
77
- resv , ok = l .storageReservations .Load (* taskID )
78
+ resvs , ok := l .storageReservations .Load (* taskID )
79
+ if ok {
80
+ resv , ok = lo .Find (resvs , func (res * StorageReservation ) bool {
81
+ return res .SectorRef .ID () == sector .ID
82
+ })
83
+ }
78
84
}
79
85
if ok && resv != nil {
80
86
if resv .Alloc != allocate || resv .Existing != existing {
@@ -144,7 +150,7 @@ func (l *storageProvider) AcquireSector(ctx context.Context, taskID *harmonytask
144
150
}
145
151
146
152
func (sb * SealCalls ) GenerateSDR (ctx context.Context , taskID harmonytask.TaskID , into storiface.SectorFileType , sector storiface.SectorRef , ticket abi.SealRandomness , commDcid cid.Cid ) error {
147
- paths , pathIDs , releaseSector , err := sb .sectors .AcquireSector (ctx , & taskID , sector , storiface .FTNone , into , storiface .PathSealing )
153
+ paths , pathIDs , releaseSector , err := sb .Sectors .AcquireSector (ctx , & taskID , sector , storiface .FTNone , into , storiface .PathSealing )
148
154
if err != nil {
149
155
return xerrors .Errorf ("acquiring sector paths: %w" , err )
150
156
}
@@ -223,7 +229,7 @@ func (sb *SealCalls) ensureOneCopy(ctx context.Context, sid abi.SectorID, pathID
223
229
224
230
log .Debugw ("ensureOneCopy" , "sector" , sid , "type" , fileType , "keep" , keepIn )
225
231
226
- if err := sb .sectors .storage .Remove (ctx , sid , fileType , true , keepIn ); err != nil {
232
+ if err := sb .Sectors .storage .Remove (ctx , sid , fileType , true , keepIn ); err != nil {
227
233
return err
228
234
}
229
235
}
@@ -237,7 +243,7 @@ func (sb *SealCalls) TreeRC(ctx context.Context, task *harmonytask.TaskID, secto
237
243
return cid .Undef , cid .Undef , xerrors .Errorf ("make phase1 output: %w" , err )
238
244
}
239
245
240
- fspaths , pathIDs , releaseSector , err := sb .sectors .AcquireSector (ctx , task , sector , storiface .FTCache , storiface .FTSealed , storiface .PathSealing )
246
+ fspaths , pathIDs , releaseSector , err := sb .Sectors .AcquireSector (ctx , task , sector , storiface .FTCache , storiface .FTSealed , storiface .PathSealing )
241
247
if err != nil {
242
248
return cid .Undef , cid .Undef , xerrors .Errorf ("acquiring sector paths: %w" , err )
243
249
}
@@ -352,7 +358,7 @@ func (sb *SealCalls) GenerateSynthPoRep() {
352
358
}
353
359
354
360
func (sb * SealCalls ) PoRepSnark (ctx context.Context , sn storiface.SectorRef , sealed , unsealed cid.Cid , ticket abi.SealRandomness , seed abi.InteractiveSealRandomness ) ([]byte , error ) {
355
- vproof , err := sb .sectors .storage .GeneratePoRepVanillaProof (ctx , sn , sealed , unsealed , ticket , seed )
361
+ vproof , err := sb .Sectors .storage .GeneratePoRepVanillaProof (ctx , sn , sealed , unsealed , ticket , seed )
356
362
if err != nil {
357
363
return nil , xerrors .Errorf ("failed to generate vanilla proof: %w" , err )
358
364
}
@@ -498,7 +504,7 @@ func (sb *SealCalls) makePhase1Out(unsCid cid.Cid, spt abi.RegisteredSealProof)
498
504
}
499
505
500
506
func (sb * SealCalls ) LocalStorage (ctx context.Context ) ([]storiface.StoragePath , error ) {
501
- return sb .sectors .localStore .Local (ctx )
507
+ return sb .Sectors .localStore .Local (ctx )
502
508
}
503
509
504
510
func changePathType (path string , newType storiface.SectorFileType ) (string , error ) {
@@ -526,7 +532,7 @@ func changePathType(path string, newType storiface.SectorFileType) (string, erro
526
532
return newPath , nil
527
533
}
528
534
func (sb * SealCalls ) FinalizeSector (ctx context.Context , sector storiface.SectorRef , keepUnsealed bool ) error {
529
- sectorPaths , pathIDs , releaseSector , err := sb .sectors .AcquireSector (ctx , nil , sector , storiface .FTCache , storiface .FTNone , storiface .PathSealing )
535
+ sectorPaths , pathIDs , releaseSector , err := sb .Sectors .AcquireSector (ctx , nil , sector , storiface .FTCache , storiface .FTNone , storiface .PathSealing )
530
536
if err != nil {
531
537
return xerrors .Errorf ("acquiring sector paths: %w" , err )
532
538
}
@@ -548,7 +554,7 @@ func (sb *SealCalls) FinalizeSector(ctx context.Context, sector storiface.Sector
548
554
549
555
defer func () {
550
556
// We don't pass FTUnsealed to Acquire, so releaseSector won't declare it. Do it here.
551
- if err := sb .sectors .sindex .StorageDeclareSector (ctx , storiface .ID (pathIDs .Unsealed ), sector .ID , storiface .FTUnsealed , true ); err != nil {
557
+ if err := sb .Sectors .sindex .StorageDeclareSector (ctx , storiface .ID (pathIDs .Unsealed ), sector .ID , storiface .FTUnsealed , true ); err != nil {
552
558
log .Errorf ("declare unsealed sector error: %+v" , err )
553
559
}
554
560
}()
@@ -666,11 +672,16 @@ func (sb *SealCalls) MoveStorage(ctx context.Context, sector storiface.SectorRef
666
672
667
673
var opts []storiface.AcquireOption
668
674
if taskID != nil {
669
- resv , ok := sb .sectors .storageReservations .Load (* taskID )
675
+ resvs , ok := sb .Sectors .storageReservations .Load (* taskID )
670
676
// if the reservation is missing MoveStorage will simply create one internally. This is fine as the reservation
671
677
// will only be missing when the node is restarting, which means that the missing reservations will get recreated
672
678
// anyways, and before we start claiming other tasks.
673
679
if ok {
680
+ if len (resvs ) != 1 {
681
+ return xerrors .Errorf ("task %d has %d reservations, expected 1" , taskID , len (resvs ))
682
+ }
683
+ resv := resvs [0 ]
684
+
674
685
defer resv .Release ()
675
686
676
687
if resv .Alloc != storiface .FTNone {
@@ -684,13 +695,13 @@ func (sb *SealCalls) MoveStorage(ctx context.Context, sector storiface.SectorRef
684
695
}
685
696
}
686
697
687
- err := sb .sectors .storage .MoveStorage (ctx , sector , toMove , opts ... )
698
+ err := sb .Sectors .storage .MoveStorage (ctx , sector , toMove , opts ... )
688
699
if err != nil {
689
700
return xerrors .Errorf ("moving storage: %w" , err )
690
701
}
691
702
692
703
for _ , fileType := range toMove .AllSet () {
693
- if err := sb .sectors .storage .RemoveCopies (ctx , sector .ID , fileType ); err != nil {
704
+ if err := sb .Sectors .storage .RemoveCopies (ctx , sector .ID , fileType ); err != nil {
694
705
return xerrors .Errorf ("rm copies (t:%s, s:%v): %w" , fileType , sector , err )
695
706
}
696
707
}
@@ -699,7 +710,7 @@ func (sb *SealCalls) MoveStorage(ctx context.Context, sector storiface.SectorRef
699
710
}
700
711
701
712
func (sb * SealCalls ) sectorStorageType (ctx context.Context , sector storiface.SectorRef , ft storiface.SectorFileType ) (sectorFound bool , ptype storiface.PathType , err error ) {
702
- stores , err := sb .sectors .sindex .StorageFindSector (ctx , sector .ID , ft , 0 , false )
713
+ stores , err := sb .Sectors .sindex .StorageFindSector (ctx , sector .ID , ft , 0 , false )
703
714
if err != nil {
704
715
return false , "" , xerrors .Errorf ("finding sector: %w" , err )
705
716
}
@@ -718,7 +729,7 @@ func (sb *SealCalls) sectorStorageType(ctx context.Context, sector storiface.Sec
718
729
719
730
// PreFetch fetches the sector file to local storage before SDR and TreeRC Tasks
720
731
func (sb * SealCalls ) PreFetch (ctx context.Context , sector storiface.SectorRef , task * harmonytask.TaskID ) (fsPath , pathID storiface.SectorPaths , releaseSector func (... storiface.SectorFileType ), err error ) {
721
- fsPath , pathID , releaseSector , err = sb .sectors .AcquireSector (ctx , task , sector , storiface .FTCache , storiface .FTNone , storiface .PathSealing )
732
+ fsPath , pathID , releaseSector , err = sb .Sectors .AcquireSector (ctx , task , sector , storiface .FTCache , storiface .FTNone , storiface .PathSealing )
722
733
if err != nil {
723
734
return storiface.SectorPaths {}, storiface.SectorPaths {}, nil , xerrors .Errorf ("acquiring sector paths: %w" , err )
724
735
}
@@ -754,7 +765,7 @@ func (sb *SealCalls) TreeD(ctx context.Context, sector storiface.SectorRef, unse
754
765
}
755
766
756
767
func (sb * SealCalls ) SyntheticProofs (ctx context.Context , task * harmonytask.TaskID , sector storiface.SectorRef , sealed cid.Cid , unsealed cid.Cid , randomness abi.SealRandomness , pieces []abi.PieceInfo ) error {
757
- fspaths , pathIDs , releaseSector , err := sb .sectors .AcquireSector (ctx , task , sector , storiface .FTCache | storiface .FTSealed , storiface .FTNone , storiface .PathSealing )
768
+ fspaths , pathIDs , releaseSector , err := sb .Sectors .AcquireSector (ctx , task , sector , storiface .FTCache | storiface .FTSealed , storiface .FTNone , storiface .PathSealing )
758
769
if err != nil {
759
770
return xerrors .Errorf ("acquiring sector paths: %w" , err )
760
771
}
0 commit comments