1
1
//! Wrapper for frontiered trace.
2
2
//!
3
- //! Wraps a trace with a frontier so that all exposed timestamps are first advanced by the frontier.
4
- //! This ensures that even for traces that have been advanced, all views provided through cursors
5
- //! present deterministic times, independent of the compaction strategy.
3
+ //! Wraps a trace with `since` and `upper` frontiers so that all exposed timestamps are first advanced
4
+ //! by the `since` frontier and restricted by the `upper` frontier. This presents a deterministic trace
5
+ //! on the interval `[since, upper)`, presenting only accumulations up to `since` (rather than partially
6
+ //! accumulated updates) and no updates at times greater or equal to `upper` (even as parts of batches
7
+ //! that span that time).
6
8
7
9
use timely:: progress:: Timestamp ;
8
10
use timely:: progress:: { Antichain , frontier:: AntichainRef } ;
17
19
Tr : TraceReader ,
18
20
{
19
21
trace : Tr ,
20
- frontier : Antichain < Tr :: Time > ,
22
+ /// Frontier to which all update times will be advanced.
23
+ since : Antichain < Tr :: Time > ,
24
+ /// Frontier after which all update times will be suppressed.
25
+ until : Antichain < Tr :: Time > ,
21
26
}
22
27
23
28
impl < Tr > Clone for TraceFrontier < Tr >
28
33
fn clone ( & self ) -> Self {
29
34
TraceFrontier {
30
35
trace : self . trace . clone ( ) ,
31
- frontier : self . frontier . clone ( ) ,
36
+ since : self . since . clone ( ) ,
37
+ until : self . until . clone ( ) ,
32
38
}
33
39
}
34
40
}
51
57
type Cursor = CursorFrontier < Tr :: Cursor > ;
52
58
53
59
fn map_batches < F : FnMut ( & Self :: Batch ) > ( & self , mut f : F ) {
54
- let frontier = self . frontier . borrow ( ) ;
55
- self . trace . map_batches ( |batch| f ( & Self :: Batch :: make_from ( batch. clone ( ) , frontier) ) )
60
+ let since = self . since . borrow ( ) ;
61
+ let until = self . until . borrow ( ) ;
62
+ self . trace . map_batches ( |batch| f ( & Self :: Batch :: make_from ( batch. clone ( ) , since, until) ) )
56
63
}
57
64
58
65
fn set_logical_compaction ( & mut self , frontier : AntichainRef < Tr :: Time > ) { self . trace . set_logical_compaction ( frontier) }
62
69
fn get_physical_compaction ( & mut self ) -> AntichainRef < Tr :: Time > { self . trace . get_physical_compaction ( ) }
63
70
64
71
fn cursor_through ( & mut self , upper : AntichainRef < Tr :: Time > ) -> Option < ( Self :: Cursor , <Self :: Cursor as Cursor >:: Storage ) > {
65
- let frontier = self . frontier . borrow ( ) ;
66
- self . trace . cursor_through ( upper) . map ( |( x, y) | ( CursorFrontier :: new ( x, frontier) , y) )
72
+ let since = self . since . borrow ( ) ;
73
+ let until = self . until . borrow ( ) ;
74
+ self . trace . cursor_through ( upper) . map ( |( x, y) | ( CursorFrontier :: new ( x, since, until) , y) )
67
75
}
68
76
}
69
77
@@ -73,10 +81,11 @@ where
73
81
Tr :: Time : Timestamp ,
74
82
{
75
83
/// Makes a new trace wrapper
76
- pub fn make_from ( trace : Tr , frontier : AntichainRef < Tr :: Time > ) -> Self {
84
+ pub fn make_from ( trace : Tr , since : AntichainRef < Tr :: Time > , until : AntichainRef < Tr :: Time > ) -> Self {
77
85
TraceFrontier {
78
86
trace,
79
- frontier : frontier. to_owned ( ) ,
87
+ since : since. to_owned ( ) ,
88
+ until : until. to_owned ( ) ,
80
89
}
81
90
}
82
91
}
@@ -86,10 +95,11 @@ where
86
95
#[ derive( Clone ) ]
87
96
pub struct BatchFrontier < B : BatchReader > {
88
97
batch : B ,
89
- frontier : Antichain < B :: Time > ,
98
+ since : Antichain < B :: Time > ,
99
+ until : Antichain < B :: Time > ,
90
100
}
91
101
92
- impl < B : BatchReader > BatchReader for BatchFrontier < B >
102
+ impl < B > BatchReader for BatchFrontier < B >
93
103
where
94
104
B : BatchReader ,
95
105
B :: Time : Timestamp +Lattice ,
@@ -102,7 +112,7 @@ where
102
112
type Cursor = BatchCursorFrontier < B > ;
103
113
104
114
fn cursor ( & self ) -> Self :: Cursor {
105
- BatchCursorFrontier :: new ( self . batch . cursor ( ) , self . frontier . borrow ( ) )
115
+ BatchCursorFrontier :: new ( self . batch . cursor ( ) , self . since . borrow ( ) , self . until . borrow ( ) )
106
116
}
107
117
fn len ( & self ) -> usize { self . batch . len ( ) }
108
118
fn description ( & self ) -> & Description < B :: Time > { & self . batch . description ( ) }
@@ -114,25 +124,28 @@ where
114
124
B :: Time : Timestamp +Lattice ,
115
125
{
116
126
/// Makes a new batch wrapper
117
- pub fn make_from ( batch : B , frontier : AntichainRef < B :: Time > ) -> Self {
127
+ pub fn make_from ( batch : B , since : AntichainRef < B :: Time > , until : AntichainRef < B :: Time > ) -> Self {
118
128
BatchFrontier {
119
129
batch,
120
- frontier : frontier. to_owned ( ) ,
130
+ since : since. to_owned ( ) ,
131
+ until : until. to_owned ( ) ,
121
132
}
122
133
}
123
134
}
124
135
125
136
/// Wrapper to provide cursor to nested scope.
126
137
pub struct CursorFrontier < C : Cursor > {
127
138
cursor : C ,
128
- frontier : Antichain < C :: Time > ,
139
+ since : Antichain < C :: Time > ,
140
+ until : Antichain < C :: Time >
129
141
}
130
142
131
143
impl < C : Cursor > CursorFrontier < C > where C :: Time : Clone {
132
- fn new ( cursor : C , frontier : AntichainRef < C :: Time > ) -> Self {
144
+ fn new ( cursor : C , since : AntichainRef < C :: Time > , until : AntichainRef < C :: Time > ) -> Self {
133
145
CursorFrontier {
134
146
cursor,
135
- frontier : frontier. to_owned ( ) ,
147
+ since : since. to_owned ( ) ,
148
+ until : until. to_owned ( ) ,
136
149
}
137
150
}
138
151
}
@@ -157,12 +170,15 @@ where
157
170
158
171
#[ inline]
159
172
fn map_times < L : FnMut ( & Self :: Time , & Self :: R ) > ( & mut self , storage : & Self :: Storage , mut logic : L ) {
160
- let frontier = self . frontier . borrow ( ) ;
173
+ let since = self . since . borrow ( ) ;
174
+ let until = self . until . borrow ( ) ;
161
175
let mut temp: C :: Time = <C :: Time as timely:: progress:: Timestamp >:: minimum ( ) ;
162
176
self . cursor . map_times ( storage, |time, diff| {
163
177
temp. clone_from ( time) ;
164
- temp. advance_by ( frontier) ;
165
- logic ( & temp, diff) ;
178
+ temp. advance_by ( since) ;
179
+ if !until. less_equal ( & temp) {
180
+ logic ( & temp, diff) ;
181
+ }
166
182
} )
167
183
}
168
184
@@ -181,14 +197,16 @@ where
181
197
/// Wrapper to provide cursor to nested scope.
182
198
pub struct BatchCursorFrontier < B : BatchReader > {
183
199
cursor : B :: Cursor ,
184
- frontier : Antichain < B :: Time > ,
200
+ since : Antichain < B :: Time > ,
201
+ until : Antichain < B :: Time > ,
185
202
}
186
203
187
204
impl < B : BatchReader > BatchCursorFrontier < B > where B :: Time : Clone {
188
- fn new ( cursor : B :: Cursor , frontier : AntichainRef < B :: Time > ) -> Self {
205
+ fn new ( cursor : B :: Cursor , since : AntichainRef < B :: Time > , until : AntichainRef < B :: Time > ) -> Self {
189
206
BatchCursorFrontier {
190
207
cursor,
191
- frontier : frontier. to_owned ( ) ,
208
+ since : since. to_owned ( ) ,
209
+ until : until. to_owned ( ) ,
192
210
}
193
211
}
194
212
}
@@ -212,12 +230,15 @@ where
212
230
213
231
#[ inline]
214
232
fn map_times < L : FnMut ( & Self :: Time , & Self :: R ) > ( & mut self , storage : & Self :: Storage , mut logic : L ) {
215
- let frontier = self . frontier . borrow ( ) ;
233
+ let since = self . since . borrow ( ) ;
234
+ let until = self . until . borrow ( ) ;
216
235
let mut temp: B :: Time = <B :: Time as timely:: progress:: Timestamp >:: minimum ( ) ;
217
236
self . cursor . map_times ( & storage. batch , |time, diff| {
218
237
temp. clone_from ( time) ;
219
- temp. advance_by ( frontier) ;
220
- logic ( & temp, diff) ;
238
+ temp. advance_by ( since) ;
239
+ if !until. less_equal ( & temp) {
240
+ logic ( & temp, diff) ;
241
+ }
221
242
} )
222
243
}
223
244
0 commit comments