@@ -520,6 +520,7 @@ impl<RT: Runtime> LeaderRetentionManager<RT> {
520
520
let mut index_entry_chunks = reader
521
521
. load_documents ( TimestampRange :: new ( cursor..min_snapshot_ts) ?, Order :: Asc )
522
522
. try_chunks ( * RETENTION_READ_CHUNK )
523
+ . map_err ( |e| e. 1 )
523
524
. map ( move |chunk| async move {
524
525
let chunk = chunk?. to_vec ( ) ;
525
526
let mut entries_to_delete = vec ! [ ] ;
@@ -638,7 +639,8 @@ impl<RT: Runtime> LeaderRetentionManager<RT> {
638
639
all_indexes,
639
640
persistence_version,
640
641
)
641
- . try_chunks ( * RETENTION_DELETE_CHUNK ) ;
642
+ . try_chunks ( * RETENTION_DELETE_CHUNK )
643
+ . map_err ( |e| e. 1 ) ;
642
644
pin_mut ! ( expired_chunks) ;
643
645
while let Some ( delete_chunk) = expired_chunks. try_next ( ) . await ? {
644
646
tracing:: trace!(
@@ -694,6 +696,7 @@ impl<RT: Runtime> LeaderRetentionManager<RT> {
694
696
Arc :: new ( NoopRetentionValidator ) ,
695
697
)
696
698
. try_chunks ( * RETENTION_READ_CHUNK )
699
+ . map_err ( |e| e. 1 )
697
700
. map ( move |chunk| async move {
698
701
let chunk = chunk?. to_vec ( ) ;
699
702
let mut entries_to_delete: Vec < ( Timestamp , InternalDocumentId ) > = vec ! [ ] ;
@@ -795,7 +798,8 @@ impl<RT: Runtime> LeaderRetentionManager<RT> {
795
798
796
799
tracing:: trace!( "delete_documents: about to grab chunks" ) ;
797
800
let expired_chunks = Self :: expired_documents ( rt, reader, cursor, min_snapshot_ts)
798
- . try_chunks ( * RETENTION_DELETE_CHUNK ) ;
801
+ . try_chunks ( * RETENTION_DELETE_CHUNK )
802
+ . map_err ( |e| e. 1 ) ;
799
803
pin_mut ! ( expired_chunks) ;
800
804
while let Some ( delete_chunk) = expired_chunks. try_next ( ) . await ? {
801
805
tracing:: trace!(
@@ -1521,13 +1525,45 @@ mod tests {
1521
1525
TableName ,
1522
1526
} ,
1523
1527
} ;
1524
- use futures:: TryStreamExt ;
1528
+ use errors:: ErrorMetadataAnyhowExt ;
1529
+ use futures:: {
1530
+ pin_mut,
1531
+ stream,
1532
+ TryStreamExt ,
1533
+ } ;
1525
1534
use maplit:: {
1526
1535
btreemap,
1527
1536
btreeset,
1528
1537
} ;
1529
1538
1530
1539
use super :: LeaderRetentionManager ;
1540
+ use crate :: retention:: {
1541
+ snapshot_invalid_error,
1542
+ RetentionType ,
1543
+ } ;
1544
+
1545
+ #[ convex_macro:: test_runtime]
1546
+ async fn test_chunks_is_out_of_retention ( _rt : TestRuntime ) -> anyhow:: Result < ( ) > {
1547
+ let throws = || -> anyhow:: Result < ( ) > {
1548
+ anyhow:: bail!( snapshot_invalid_error(
1549
+ Timestamp :: must( 1 ) ,
1550
+ Timestamp :: must( 30 ) ,
1551
+ RetentionType :: Document
1552
+ ) ) ;
1553
+ } ;
1554
+ let stream_throws = stream:: once ( async move { throws ( ) } ) ;
1555
+ // IMPORTANT: the map_err is required here and whenever we use try_chunks.
1556
+ // Otherwise the error gets re-wrapped and loses context.
1557
+ let chunks = stream_throws. try_chunks ( 1 ) . map_err ( |e| e. 1 ) ;
1558
+ let chunk_throws = async move || -> anyhow:: Result < ( ) > {
1559
+ pin_mut ! ( chunks) ;
1560
+ chunks. try_next ( ) . await ?;
1561
+ anyhow:: Ok ( ( ) )
1562
+ } ;
1563
+ let err = chunk_throws ( ) . await . unwrap_err ( ) ;
1564
+ assert ! ( err. is_out_of_retention( ) ) ;
1565
+ Ok ( ( ) )
1566
+ }
1531
1567
1532
1568
#[ convex_macro:: test_runtime]
1533
1569
async fn test_expired_index_entries ( _rt : TestRuntime ) -> anyhow:: Result < ( ) > {
0 commit comments