1+ use anyhow:: Context ;
12use detail:: DeploymentDetail ;
23use diesel:: connection:: SimpleConnection ;
34use diesel:: pg:: PgConnection ;
@@ -905,7 +906,7 @@ impl DeploymentStore {
905906
906907 if let Some ( cursor) = firehose_cursor {
907908 if cursor != "" {
908- deployment:: update_firehose_cursor ( & conn, & site. deployment , & cursor) ?;
909+ deployment:: update_firehose_cursor ( & conn, & site. deployment , cursor) ?;
909910 }
910911 }
911912
@@ -920,6 +921,7 @@ impl DeploymentStore {
920921 conn : & PgConnection ,
921922 site : Arc < Site > ,
922923 block_ptr_to : BlockPtr ,
924+ firehose_cursor : Option < & str > ,
923925 ) -> Result < StoreEvent , StoreError > {
924926 let event = conn. transaction ( || -> Result < _ , StoreError > {
925927 // Don't revert past a graft point
@@ -940,6 +942,11 @@ impl DeploymentStore {
940942
941943 deployment:: revert_block_ptr ( & conn, & site. deployment , block_ptr_to. clone ( ) ) ?;
942944
945+ if let Some ( cursor) = firehose_cursor {
946+ deployment:: update_firehose_cursor ( & conn, & site. deployment , cursor)
947+ . context ( "updating firehose cursor" ) ?;
948+ }
949+
943950 // Revert the data
944951 let layout = self . layout ( & conn, site. clone ( ) ) ?;
945952
@@ -991,13 +998,18 @@ impl DeploymentStore {
991998 block_ptr_to. number
992999 ) ;
9931000 }
994- self . rewind_with_conn ( & conn, site, block_ptr_to)
1001+
1002+ // When rewinding, we reset the firehose cursor to the empty string. That way, on resume,
1003+ // Firehose will start from the block_ptr instead (with sanity check to ensure it's resume
1004+ // at the exact block).
1005+ self . rewind_with_conn ( & conn, site, block_ptr_to, Some ( "" ) )
9951006 }
9961007
9971008 pub ( crate ) fn revert_block_operations (
9981009 & self ,
9991010 site : Arc < Site > ,
10001011 block_ptr_to : BlockPtr ,
1012+ firehose_cursor : Option < & str > ,
10011013 ) -> Result < StoreEvent , StoreError > {
10021014 let conn = self . get_conn ( ) ?;
10031015 // Unwrap: If we are reverting then the block ptr is not `None`.
@@ -1008,7 +1020,7 @@ impl DeploymentStore {
10081020 panic ! ( "revert_block_operations must revert a single block only" ) ;
10091021 }
10101022
1011- self . rewind_with_conn ( & conn, site, block_ptr_to)
1023+ self . rewind_with_conn ( & conn, site, block_ptr_to, firehose_cursor )
10121024 }
10131025
10141026 pub ( crate ) async fn deployment_state_from_id (
@@ -1227,7 +1239,11 @@ impl DeploymentStore {
12271239 ) ;
12281240
12291241 // We ignore the StoreEvent that's being returned, we'll not use it.
1230- let _ = self . revert_block_operations ( site. clone ( ) , parent_ptr. clone ( ) ) ?;
1242+ //
1243+ // We reset the firehose cursor to the empty string. That way, on resume,
1244+ // Firehose will start from the block_ptr instead (with sanity checks to ensure it's resuming
1245+ // at the correct block).
1246+ let _ = self . revert_block_operations ( site. clone ( ) , parent_ptr. clone ( ) , Some ( "" ) ) ?;
12311247
12321248 // Unfail the deployment.
12331249 deployment:: update_deployment_status ( conn, deployment_id, prev_health, None ) ?;
0 commit comments