@@ -575,10 +575,10 @@ impl<RT: Runtime> SubscriptionClient for ApplicationSubscriptionClient<RT> {
575
575
}
576
576
}
577
577
578
- pub enum ExtendValidityResult {
579
- /// The subscription's validity can be extended to the requested timestamp .
580
- Extended ,
581
- /// The subscription may no longer be valid at the requested timestamp .
578
+ pub enum SubscriptionValidity {
579
+ /// The subscription is valid .
580
+ Valid ,
581
+ /// The subscription may no longer be valid.
582
582
/// This result can be returned spuriously even if there were no conflicting
583
583
/// writes.
584
584
Invalid {
@@ -590,10 +590,14 @@ pub enum ExtendValidityResult {
590
590
591
591
#[ async_trait]
592
592
pub trait SubscriptionTrait : Send + Sync {
593
- fn wait_for_invalidation ( & self ) -> BoxFuture < ' static , anyhow:: Result < ( ) > > ;
594
-
595
- /// See comments on [`ExtendValidityResult`]
596
- async fn extend_validity ( & self , new_ts : Timestamp ) -> anyhow:: Result < ExtendValidityResult > ;
593
+ /// Returns a future that completes after the subscription becomes invalid.
594
+ /// The future yields the invalidation timestamp, if known; this is the same
595
+ /// thing as [`SubscriptionValidity`]'s `invalid_ts`.
596
+ fn wait_for_invalidation ( & self ) -> BoxFuture < ' static , anyhow:: Result < Option < Timestamp > > > ;
597
+
598
+ /// Checks if the subscription is still valid as of `new_ts`. See comments
599
+ /// on [`SubscriptionValidity`].
600
+ async fn extend_validity ( & self , new_ts : Timestamp ) -> anyhow:: Result < SubscriptionValidity > ;
597
601
}
598
602
599
603
struct ApplicationSubscription {
@@ -608,15 +612,15 @@ struct ApplicationSubscription {
608
612
609
613
#[ async_trait]
610
614
impl SubscriptionTrait for ApplicationSubscription {
611
- fn wait_for_invalidation ( & self ) -> BoxFuture < ' static , anyhow:: Result < ( ) > > {
615
+ fn wait_for_invalidation ( & self ) -> BoxFuture < ' static , anyhow:: Result < Option < Timestamp > > > {
612
616
self . inner . wait_for_invalidation ( ) . map ( Ok ) . boxed ( )
613
617
}
614
618
615
619
#[ fastrace:: trace]
616
- async fn extend_validity ( & self , new_ts : Timestamp ) -> anyhow:: Result < ExtendValidityResult > {
620
+ async fn extend_validity ( & self , new_ts : Timestamp ) -> anyhow:: Result < SubscriptionValidity > {
617
621
if new_ts < self . initial_ts {
618
622
// new_ts is before the initial subscription timestamp.
619
- return Ok ( ExtendValidityResult :: Invalid { invalid_ts : None } ) ;
623
+ return Ok ( SubscriptionValidity :: Invalid { invalid_ts : None } ) ;
620
624
}
621
625
622
626
// The inner subscription is periodically updated by the subscription
@@ -625,18 +629,18 @@ impl SubscriptionTrait for ApplicationSubscription {
625
629
// Subscription is no longer valid. We could check validity from end_ts
626
630
// to new_ts, but this is likely to fail and is potentially unbounded amount of
627
631
// work, so we return false here. This is valid per the function contract.
628
- return Ok ( ExtendValidityResult :: Invalid {
632
+ return Ok ( SubscriptionValidity :: Invalid {
629
633
invalid_ts : self . inner . invalid_ts ( ) ,
630
634
} ) ;
631
635
} ;
632
636
633
637
let current_token = Token :: new ( self . reads . clone ( ) , current_ts) ;
634
638
Ok ( match self . log . refresh_token ( current_token, new_ts) ? {
635
- Ok ( _new_token) => ExtendValidityResult :: Extended ,
639
+ Ok ( _new_token) => SubscriptionValidity :: Valid ,
636
640
Err ( invalid_ts) => {
637
641
// Subscription validity can't be extended. Note that returning false
638
642
// here also doesn't mean there is a conflict.
639
- ExtendValidityResult :: Invalid { invalid_ts }
643
+ SubscriptionValidity :: Invalid { invalid_ts }
640
644
} ,
641
645
} )
642
646
}
0 commit comments