@@ -50,7 +50,13 @@ use crate::{
50
50
} ,
51
51
} ;
52
52
53
- pub type DocumentLogEntry = ( Timestamp , InternalDocumentId , Option < ResolvedDocument > ) ;
53
+ #[ derive( Debug , Clone , PartialEq ) ]
54
+ pub struct DocumentLogEntry {
55
+ pub ts : Timestamp ,
56
+ pub id : InternalDocumentId ,
57
+ pub value : Option < ResolvedDocument > ,
58
+ pub prev_ts : Option < Timestamp > ,
59
+ }
54
60
55
61
pub type DocumentStream < ' a > = BoxStream < ' a , anyhow:: Result < DocumentLogEntry > > ;
56
62
@@ -161,14 +167,6 @@ impl PersistenceGlobalKey {
161
167
}
162
168
}
163
169
164
- #[ derive( Debug , Clone , PartialEq ) ]
165
- pub struct DatabaseDocumentUpdate {
166
- pub ts : Timestamp ,
167
- pub id : InternalDocumentId ,
168
- pub value : Option < ResolvedDocument > ,
169
- pub prev_ts : Option < Timestamp > ,
170
- }
171
-
172
170
#[ async_trait]
173
171
pub trait Persistence : Sync + Send + ' static {
174
172
/// Whether the persistence layer is freshely created or not.
@@ -179,7 +177,7 @@ pub trait Persistence: Sync + Send + 'static {
179
177
/// Writes documents and the respective derived indexes.
180
178
async fn write (
181
179
& self ,
182
- documents : Vec < DatabaseDocumentUpdate > ,
180
+ documents : Vec < DocumentLogEntry > ,
183
181
indexes : BTreeSet < ( Timestamp , DatabaseIndexUpdate ) > ,
184
182
conflict_strategy : ConflictStrategy ,
185
183
) -> anyhow:: Result < ( ) > ;
@@ -338,7 +336,7 @@ pub trait PersistenceReader: Send + Sync + 'static {
338
336
retention_validator : Arc < dyn RetentionValidator > ,
339
337
) -> DocumentStream < ' _ > {
340
338
self . load_documents ( range, order, page_size, retention_validator)
341
- . try_filter ( move |( _ , doc_id , _ ) | future:: ready ( doc_id . table ( ) == tablet_id) )
339
+ . try_filter ( move |doc | future:: ready ( doc . id . table ( ) == tablet_id) )
342
340
. boxed ( )
343
341
}
344
342
@@ -352,9 +350,7 @@ pub trait PersistenceReader: Send + Sync + 'static {
352
350
& self ,
353
351
ids : BTreeSet < ( InternalDocumentId , Timestamp ) > ,
354
352
retention_validator : Arc < dyn RetentionValidator > ,
355
- ) -> anyhow:: Result <
356
- BTreeMap < ( InternalDocumentId , Timestamp ) , ( Timestamp , Option < ResolvedDocument > ) > ,
357
- > ;
353
+ ) -> anyhow:: Result < BTreeMap < ( InternalDocumentId , Timestamp ) , DocumentLogEntry > > ;
358
354
359
355
/// Loads documentIds with respective timestamps that match the
360
356
/// index query criteria.
@@ -431,7 +427,7 @@ pub trait PersistenceReader: Send + Sync + 'static {
431
427
let max_repeatable =
432
428
self . get_persistence_global ( PersistenceGlobalKey :: MaxRepeatableTimestamp ) ;
433
429
let ( max_committed, max_repeatable) = try_join ! ( stream. try_next( ) , max_repeatable) ?;
434
- let max_committed_ts = max_committed. map ( |( ts , .. ) | ts) ;
430
+ let max_committed_ts = max_committed. map ( |entry| entry . ts ) ;
435
431
let max_repeatable_ts = max_repeatable. map ( Timestamp :: try_from) . transpose ( ) ?;
436
432
let max_ts = cmp:: max ( max_committed_ts, max_repeatable_ts) ; // note None < Some
437
433
Ok ( max_ts)
@@ -525,7 +521,7 @@ impl RepeatablePersistence {
525
521
* DEFAULT_DOCUMENTS_PAGE_SIZE ,
526
522
self . retention_validator . clone ( ) ,
527
523
) ;
528
- Box :: pin ( stream. try_filter ( |( ts , .. ) | future:: ready ( * ts <= * self . upper_bound ) ) )
524
+ Box :: pin ( stream. try_filter ( |entry | future:: ready ( entry . ts <= * self . upper_bound ) ) )
529
525
}
530
526
531
527
/// Same as `load_documents` but doesn't use the `RetentionValidator` from
@@ -543,15 +539,13 @@ impl RepeatablePersistence {
543
539
* DEFAULT_DOCUMENTS_PAGE_SIZE ,
544
540
retention_validator,
545
541
) ;
546
- Box :: pin ( stream. try_filter ( |( ts , .. ) | future:: ready ( * ts <= * self . upper_bound ) ) )
542
+ Box :: pin ( stream. try_filter ( |entry | future:: ready ( entry . ts <= * self . upper_bound ) ) )
547
543
}
548
544
549
545
pub async fn previous_revisions (
550
546
& self ,
551
547
ids : BTreeSet < ( InternalDocumentId , Timestamp ) > ,
552
- ) -> anyhow:: Result <
553
- BTreeMap < ( InternalDocumentId , Timestamp ) , ( Timestamp , Option < ResolvedDocument > ) > ,
554
- > {
548
+ ) -> anyhow:: Result < BTreeMap < ( InternalDocumentId , Timestamp ) , DocumentLogEntry > > {
555
549
for ( _, ts) in & ids {
556
550
// Reading documents <ts, so ts-1 needs to be repeatable.
557
551
anyhow:: ensure!( * ts <= self . upper_bound. succ( ) ?) ;
@@ -566,9 +560,7 @@ impl RepeatablePersistence {
566
560
& self ,
567
561
ids : BTreeSet < ( InternalDocumentId , Timestamp ) > ,
568
562
retention_validator : Arc < dyn RetentionValidator > ,
569
- ) -> anyhow:: Result <
570
- BTreeMap < ( InternalDocumentId , Timestamp ) , ( Timestamp , Option < ResolvedDocument > ) > ,
571
- > {
563
+ ) -> anyhow:: Result < BTreeMap < ( InternalDocumentId , Timestamp ) , DocumentLogEntry > > {
572
564
for ( _, ts) in & ids {
573
565
// Reading documents <ts, so ts-1 needs to be repeatable.
574
566
anyhow:: ensure!( * ts <= self . upper_bound. succ( ) ?) ;
0 commit comments