@@ -15,6 +15,7 @@ use crate::error::Result;
1515use crate :: io:: buf:: { ZeroCopyBoxIoBuf , ZeroCopyBuf } ;
1616use crate :: io:: FileExt ;
1717use crate :: segment:: Frame ;
18+ use crate :: { LibsqlFooter , LIBSQL_MAGIC , LIBSQL_PAGE_SIZE , LIBSQL_WAL_VERSION } ;
1819
1920use super :: Segment ;
2021
@@ -157,6 +158,21 @@ where
157158 buf = read_buf. into_inner ( ) ;
158159 }
159160
161+ // update the footer at the end of the db file.
162+ let footer = LibsqlFooter {
163+ magic : LIBSQL_MAGIC . into ( ) ,
164+ version : LIBSQL_WAL_VERSION . into ( ) ,
165+ replication_index : last_replication_index. into ( ) ,
166+ } ;
167+
168+ let footer_offset = size_after as usize * LIBSQL_PAGE_SIZE as usize ;
169+ let ( _, ret) = db_file
170+ . write_all_at_async ( ZeroCopyBuf :: new_init ( footer) , footer_offset as u64 )
171+ . await ;
172+ ret?;
173+
174+ // todo: truncate if necessary
175+
160176 //// todo: make async
161177 db_file. sync_all ( ) ?;
162178
@@ -185,7 +201,7 @@ where
185201 Ok ( Some ( last_replication_index) )
186202 }
187203
188- /// returnsstream pages from the sealed segment list, and what's the lowest replication index
204+ /// returns a stream of pages from the sealed segment list, and what's the lowest replication index
189205 /// that was covered. If the returned index is less than start frame_no, the missing frames
190206 /// must be read somewhere else.
191207 pub async fn stream_pages_from < ' a > (
0 commit comments