11use crate :: single_disk_farm:: {
2- BackgroundTaskError , Handlers , PlotMetadataHeader , SectorPlottingDetails , SectorUpdate ,
3- RESERVED_PLOT_METADATA ,
2+ BackgroundTaskError , Handlers , PlotMetadataHeader , SectorExpirationDetails ,
3+ SectorPlottingDetails , SectorUpdate , RESERVED_PLOT_METADATA ,
44} ;
55use crate :: thread_pool_manager:: PlottingThreadPoolManager ;
66use crate :: utils:: AsyncJoinOnDrop ;
@@ -482,6 +482,7 @@ pub(super) struct PlottingSchedulerOptions<NC> {
482482 pub ( super ) last_archived_segment_index : SegmentIndex ,
483483 pub ( super ) min_sector_lifetime : HistorySize ,
484484 pub ( super ) node_client : NC ,
485+ pub ( super ) handlers : Arc < Handlers > ,
485486 pub ( super ) sectors_metadata : Arc < RwLock < Vec < SectorMetadataChecksummed > > > ,
486487 pub ( super ) sectors_to_plot_sender : mpsc:: Sender < SectorToPlot > ,
487488 pub ( super ) initial_plotting_finished : Option < oneshot:: Sender < ( ) > > ,
@@ -503,6 +504,7 @@ where
503504 last_archived_segment_index,
504505 min_sector_lifetime,
505506 node_client,
507+ handlers,
506508 sectors_metadata,
507509 sectors_to_plot_sender,
508510 initial_plotting_finished,
@@ -550,6 +552,7 @@ where
550552 target_sector_count,
551553 min_sector_lifetime,
552554 & node_client,
555+ & handlers,
553556 sectors_metadata,
554557 & last_archived_segment,
555558 archived_segments_receiver,
@@ -695,6 +698,7 @@ async fn send_plotting_notifications<NC>(
695698 target_sector_count : SectorIndex ,
696699 min_sector_lifetime : HistorySize ,
697700 node_client : & NC ,
701+ handlers : & Handlers ,
698702 sectors_metadata : Arc < RwLock < Vec < SectorMetadataChecksummed > > > ,
699703 last_archived_segment : & Atomic < SegmentHeader > ,
700704 mut archived_segments_receiver : mpsc:: Receiver < ( ) > ,
@@ -771,6 +775,18 @@ where
771775 %expires_at,
772776 "Sector expires soon #1, scheduling replotting"
773777 ) ;
778+
779+ handlers. sector_update . call_simple ( & (
780+ sector_index,
781+ SectorUpdate :: Expiration (
782+ if expires_at <= archived_segment_header. segment_index ( ) {
783+ SectorExpirationDetails :: Expired
784+ } else {
785+ SectorExpirationDetails :: AboutToExpire
786+ } ,
787+ ) ,
788+ ) ) ;
789+
774790 // Time to replot
775791 sectors_to_replot. push ( SectorToReplot {
776792 sector_index,
@@ -827,24 +843,35 @@ where
827843 metadata; qed",
828844 ) ;
829845
846+ let expires_at = expiration_history_size. segment_index ( ) ;
847+
830848 trace ! (
831849 %sector_index,
832850 %history_size,
833- sector_expire_at = %expiration_history_size . segment_index ( ) ,
851+ sector_expire_at = %expires_at ,
834852 "Determined sector expiration segment index"
835853 ) ;
836854 // +1 means we will start replotting a bit before it actually expires to avoid
837855 // storing expired sectors
838- if expiration_history_size. segment_index ( )
839- <= ( archived_segment_header. segment_index ( ) + SegmentIndex :: ONE )
840- {
841- let expires_at = expiration_history_size. segment_index ( ) ;
856+ if expires_at <= ( archived_segment_header. segment_index ( ) + SegmentIndex :: ONE ) {
842857 debug ! (
843858 %sector_index,
844859 %history_size,
845860 %expires_at,
846861 "Sector expires soon #2, scheduling replotting"
847862 ) ;
863+
864+ handlers. sector_update . call_simple ( & (
865+ sector_index,
866+ SectorUpdate :: Expiration (
867+ if expires_at <= archived_segment_header. segment_index ( ) {
868+ SectorExpirationDetails :: Expired
869+ } else {
870+ SectorExpirationDetails :: AboutToExpire
871+ } ,
872+ ) ,
873+ ) ) ;
874+
848875 // Time to replot
849876 sectors_to_replot. push ( SectorToReplot {
850877 sector_index,
@@ -854,12 +881,19 @@ where
854881 trace ! (
855882 %sector_index,
856883 %history_size,
857- sector_expire_at = %expiration_history_size . segment_index ( ) ,
884+ sector_expire_at = %expires_at ,
858885 "Sector expires later, remembering sector expiration"
859886 ) ;
887+
888+ handlers. sector_update . call_simple ( & (
889+ sector_index,
890+ SectorUpdate :: Expiration ( SectorExpirationDetails :: Determined {
891+ expires_at,
892+ } ) ,
893+ ) ) ;
894+
860895 // Store expiration so we don't have to recalculate it later
861- sectors_expire_at
862- . insert ( sector_index, expiration_history_size. segment_index ( ) ) ;
896+ sectors_expire_at. insert ( sector_index, expires_at) ;
863897 }
864898 }
865899 }
0 commit comments