@@ -42,21 +42,25 @@ impl<T: Debug + Clone> MemoryLog<T> {
4242 }
4343 }
4444
45+ pub fn head_and_tail ( & self ) -> ( u64 , u64 ) {
46+ ( self . head_offset , self . tail_offset )
47+ }
48+
4549 /// Appends this record to the tail and returns the offset of this append.
4650 /// When the current segment is full, this also create a new segment and
4751 /// writes the record to it.
4852 /// This function also handles retention by removing head segment
4953 pub fn append ( & mut self , size : usize , record : T ) -> ( u64 , u64 ) {
5054 let switch = self . apply_retention ( ) ;
51- let base_offset = self . active_segment . base_offset ( ) ;
55+ let segment_id = self . tail_offset ;
5256 let offset = self . active_segment . append ( record, size) ;
5357
5458 // For debugging during flux. Will be removed later
5559 if switch {
56- // println!("swch. segment = {}, next_offset = {}", base_offset , offset);
60+ // println!("swch. segment = {}, next_offset = {}", segment_id , offset);
5761 }
5862
59- ( base_offset , offset)
63+ ( segment_id , offset)
6064 }
6165
6266 fn apply_retention ( & mut self ) -> bool {
@@ -81,9 +85,9 @@ impl<T: Debug + Clone> MemoryLog<T> {
8185 }
8286
8387 pub fn next_offset ( & self ) -> ( u64 , u64 ) {
84- let base_offset = self . active_segment . base_offset ( ) ;
85- let relative_offset = base_offset + self . active_segment . len ( ) as u64 ;
86- ( base_offset , relative_offset )
88+ let segment_id = self . tail_offset ;
89+ let next_offset = self . active_segment . base_offset ( ) + self . active_segment . len ( ) as u64 ;
90+ ( segment_id , next_offset )
8791 }
8892
8993 /// Read a record from correct segment
0 commit comments