@@ -42,7 +42,7 @@ namespace fc::sector_storage {
42
42
}
43
43
44
44
WorkerAction schedNothing () {
45
- return WorkerAction () ;
45
+ return {} ;
46
46
}
47
47
48
48
void addCachePathsForSectorSize (
@@ -465,7 +465,8 @@ namespace fc::sector_storage {
465
465
const UnpaddedPieceSize &size,
466
466
const SealRandomness &randomness,
467
467
const CID &cid,
468
- const std::function<void (outcome::result<bool >)> &cb) {
468
+ const std::function<void (outcome::result<bool >)> &cb,
469
+ uint64_t priority) {
469
470
OUTCOME_CB (auto lock,
470
471
index_->storageLock (
471
472
sector.id ,
@@ -518,7 +519,7 @@ namespace fc::sector_storage {
518
519
callbackWrapper ([&wait](outcome::result<void > res) -> void {
519
520
wait.set_value (res);
520
521
}),
521
- kDefaultTaskPriority ,
522
+ priority ,
522
523
boost::none));
523
524
524
525
OUTCOME_CB1 (wait.get_future ().get ());
@@ -545,40 +546,10 @@ namespace fc::sector_storage {
545
546
return worker->readPiece (std::move (*output), sector, offset, size);
546
547
},
547
548
callbackWrapper (cb),
548
- kDefaultTaskPriority ,
549
+ priority ,
549
550
boost::none));
550
551
}
551
552
552
- outcome::result<bool > ManagerImpl::readPieceSync (
553
- PieceData output,
554
- const SectorRef §or,
555
- UnpaddedByteIndex offset,
556
- const UnpaddedPieceSize &size,
557
- const SealRandomness &randomness,
558
- const CID &cid) {
559
- std::promise<outcome::result<bool >> wait;
560
-
561
- readPiece (std::move (output),
562
- sector,
563
- offset,
564
- size,
565
- randomness,
566
- cid,
567
- [&wait](outcome::result<bool > res) { wait.set_value (res); });
568
-
569
- auto res = wait.get_future ().get ();
570
-
571
- if (res.has_error ()) {
572
- return res.error ();
573
- }
574
-
575
- if (res.value ()) {
576
- return outcome::success ();
577
- }
578
-
579
- return ManagerErrors::kCannotReadData ;
580
- }
581
-
582
553
void ManagerImpl::sealPreCommit1 (
583
554
const SectorRef §or,
584
555
const SealRandomness &ticket,
@@ -621,25 +592,6 @@ namespace fc::sector_storage {
621
592
work_id));
622
593
}
623
594
624
- outcome::result<PreCommit1Output> ManagerImpl::sealPreCommit1Sync (
625
- const SectorRef §or,
626
- const SealRandomness &ticket,
627
- const std::vector<PieceInfo> &pieces,
628
- uint64_t priority) {
629
- std::promise<outcome::result<PreCommit1Output>> wait;
630
-
631
- sealPreCommit1 (
632
- sector,
633
- ticket,
634
- pieces,
635
- [&wait](outcome::result<PreCommit1Output> res) -> void {
636
- wait.set_value (std::move (res));
637
- },
638
- priority);
639
-
640
- return wait.get_future ().get ();
641
- }
642
-
643
595
void ManagerImpl::sealPreCommit2 (
644
596
const SectorRef §or,
645
597
const PreCommit1Output &pre_commit_1_output,
@@ -679,23 +631,6 @@ namespace fc::sector_storage {
679
631
work_id))
680
632
}
681
633
682
- outcome::result<SectorCids> ManagerImpl::sealPreCommit2Sync (
683
- const SectorRef §or,
684
- const PreCommit1Output &pre_commit_1_output,
685
- uint64_t priority) {
686
- std::promise<outcome::result<SectorCids>> wait;
687
-
688
- sealPreCommit2 (
689
- sector,
690
- pre_commit_1_output,
691
- [&wait](outcome::result<SectorCids> res) -> void {
692
- wait.set_value (std::move (res));
693
- },
694
- priority);
695
-
696
- return wait.get_future ().get ();
697
- }
698
-
699
634
void ManagerImpl::sealCommit1 (
700
635
const SectorRef §or,
701
636
const SealRandomness &ticket,
@@ -738,27 +673,6 @@ namespace fc::sector_storage {
738
673
work_id));
739
674
}
740
675
741
- outcome::result<Commit1Output> ManagerImpl::sealCommit1Sync (
742
- const SectorRef §or,
743
- const SealRandomness &ticket,
744
- const InteractiveRandomness &seed,
745
- const std::vector<PieceInfo> &pieces,
746
- const SectorCids &cids,
747
- uint64_t priority) {
748
- std::promise<outcome::result<Commit1Output>> wait;
749
- sealCommit1 (
750
- sector,
751
- ticket,
752
- seed,
753
- pieces,
754
- cids,
755
- [&wait](const outcome::result<Commit1Output> &res) -> void {
756
- wait.set_value (res);
757
- },
758
- priority);
759
- return wait.get_future ().get ();
760
- }
761
-
762
676
void ManagerImpl::sealCommit2 (
763
677
const SectorRef §or,
764
678
const Commit1Output &commit_1_output,
@@ -768,7 +682,7 @@ namespace fc::sector_storage {
768
682
getWorkId (primitives::kTTCommit2 ,
769
683
std::make_tuple (sector, commit_1_output)));
770
684
771
- std::unique_ptr<TaskSelector> selector = std::make_unique<TaskSelector>();
685
+ auto selector = std::make_unique<TaskSelector>();
772
686
773
687
OUTCOME_CB1 (scheduler_->schedule (
774
688
sector,
@@ -784,23 +698,6 @@ namespace fc::sector_storage {
784
698
work_id));
785
699
}
786
700
787
- outcome::result<Proof> ManagerImpl::sealCommit2Sync (
788
- const SectorRef §or,
789
- const Commit1Output &commit_1_output,
790
- uint64_t priority) {
791
- std::promise<outcome::result<Proof>> wait;
792
-
793
- sealCommit2 (
794
- sector,
795
- commit_1_output,
796
- [&wait](const outcome::result<Proof> &res) -> void {
797
- wait.set_value (res);
798
- },
799
- priority);
800
-
801
- return wait.get_future ().get ();
802
- }
803
-
804
701
void ManagerImpl::finalizeSector (
805
702
const SectorRef §or,
806
703
const gsl::span<const Range> &keep_unsealed,
@@ -899,19 +796,128 @@ namespace fc::sector_storage {
899
796
boost::none));
900
797
}
901
798
902
- outcome::result< void > ManagerImpl::finalizeSectorSync (
799
+ void ManagerImpl::replicaUpdate (
903
800
const SectorRef §or,
904
- const gsl::span<const Range> &keep_unsealed,
801
+ const std::vector<PieceInfo> &pieces,
802
+ const std::function<void (outcome::result<ReplicaUpdateOut>)> &cb,
905
803
uint64_t priority) {
906
- std::promise<outcome::result<void >> waiter;
804
+ logger_->debug (" sector_storage::Manager is doing replica update" );
805
+ OUTCOME_CB (WorkId work_id,
806
+ getWorkId (primitives::kTTReplicaUpdate ,
807
+ std::make_tuple (sector, pieces)));
808
+
809
+ OUTCOME_CB (auto lock,
810
+ index_->storageLock (
811
+ sector.id ,
812
+ SectorFileType::FTUnsealed | SectorFileType::FTSealed
813
+ | SectorFileType::FTCache,
814
+ SectorFileType::FTUpdate | SectorFileType::FTUpdateCache));
907
815
908
- finalizeSector (
816
+ auto selector = std::make_unique<AllocateSelector>(
817
+ index_,
818
+ SectorFileType::FTUpdate | SectorFileType::FTUpdateCache,
819
+ PathType::kSealing );
820
+
821
+ OUTCOME_CB1 (scheduler_->schedule (
909
822
sector,
910
- keep_unsealed,
911
- [&waiter](outcome::result<void > res) -> void { waiter.set_value (res); },
912
- priority);
823
+ primitives::kTTReplicaUpdate ,
824
+ std::move (selector),
825
+ schedFetch (sector,
826
+ SectorFileType::FTUnsealed | SectorFileType::FTSealed
827
+ | SectorFileType::FTCache,
828
+ PathType::kSealing ,
829
+ AcquireMode::kCopy ),
830
+ [sector, pieces, lock = std::move (lock)](
831
+ const std::shared_ptr<Worker> &worker) -> outcome::result<CallId> {
832
+ return worker->replicaUpdate (sector, pieces);
833
+ },
834
+ callbackWrapper (cb),
835
+ priority,
836
+ work_id));
837
+ }
838
+
839
+ void ManagerImpl::proveReplicaUpdate1 (
840
+ const SectorRef §or,
841
+ const CID §or_key,
842
+ const CID &new_sealed,
843
+ const CID &new_unsealed,
844
+ const std::function<void (outcome::result<ReplicaVanillaProofs>)> &cb,
845
+ uint64_t priority) {
846
+ OUTCOME_CB (WorkId work_id,
847
+ getWorkId (primitives::kTTProveReplicaUpdate1 ,
848
+ std::make_tuple (
849
+ sector, sector_key, new_sealed, new_unsealed)));
850
+
851
+ OUTCOME_CB (
852
+ auto lock,
853
+ index_->storageLock (sector.id ,
854
+ SectorFileType::FTSealed | SectorFileType::FTUpdate
855
+ | SectorFileType::FTCache
856
+ | SectorFileType::FTUpdateCache,
857
+ SectorFileType::FTNone));
858
+
859
+ // NOTE: We set allowFetch to false in so that we always execute on a worker
860
+ // with direct access to the data. We want to do that because this step is
861
+ // generally very cheap / fast, and transferring data is not worth the
862
+ // effort
863
+ auto selector = std::make_unique<ExistingSelector>(
864
+ index_,
865
+ sector.id ,
866
+ SectorFileType::FTUpdate | SectorFileType::FTUpdateCache
867
+ | SectorFileType::FTSealed | SectorFileType::FTCache,
868
+ false );
869
+
870
+ OUTCOME_CB1 (scheduler_->schedule (
871
+ sector,
872
+ primitives::kTTProveReplicaUpdate1 ,
873
+ std::move (selector),
874
+ schedFetch (sector,
875
+ SectorFileType::FTSealed | SectorFileType::FTCache
876
+ | SectorFileType::FTUpdate
877
+ | SectorFileType::FTUpdateCache,
878
+ PathType::kSealing ,
879
+ AcquireMode::kCopy ),
880
+ [sector, sector_key, new_sealed, new_unsealed, lock = std::move (lock)](
881
+ const std::shared_ptr<Worker> &worker) -> outcome::result<CallId> {
882
+ return worker->proveReplicaUpdate1 (
883
+ sector, sector_key, new_sealed, new_unsealed);
884
+ },
885
+ callbackWrapper (cb),
886
+ priority,
887
+ work_id));
888
+ }
913
889
914
- return waiter.get_future ().get ();
890
+ void ManagerImpl::proveReplicaUpdate2 (
891
+ const SectorRef §or,
892
+ const CID §or_key,
893
+ const CID &new_sealed,
894
+ const CID &new_unsealed,
895
+ const Update1Output &update_1_output,
896
+ const std::function<void (outcome::result<ReplicaUpdateProof>)> &cb,
897
+ uint64_t priority) {
898
+ OUTCOME_CB (WorkId work_id,
899
+ getWorkId (primitives::kTTProveReplicaUpdate2 ,
900
+ std::make_tuple (sector,
901
+ sector_key,
902
+ new_sealed,
903
+ new_unsealed,
904
+ update_1_output)));
905
+
906
+ auto selector = std::make_unique<TaskSelector>();
907
+
908
+ OUTCOME_CB1 (scheduler_->schedule (
909
+ sector,
910
+ primitives::kTTProveReplicaUpdate2 ,
911
+ std::move (selector),
912
+ schedNothing (),
913
+ [sector, sector_key, new_sealed, new_unsealed, update_1_output](
914
+ const std::shared_ptr<Worker> &worker) -> outcome::result<CallId> {
915
+ return worker->proveReplicaUpdate2 (
916
+ sector, sector_key, new_sealed, new_unsealed, update_1_output);
917
+ },
918
+ callbackWrapper (cb),
919
+ priority,
920
+ work_id));
915
921
}
916
922
917
923
void ManagerImpl::addPiece (
0 commit comments