@@ -157,6 +157,32 @@ impl WriterConnectionPool {
157
157
}
158
158
}
159
159
160
+ pub async fn commit ( & mut self ) -> Result < ( ) , Error > {
161
+ let mut connections = Vec :: with_capacity ( self . num_connections ) ;
162
+ while let Some ( connection_or_error) = self . connection_rx . recv ( ) . await {
163
+ let mut connection = connection_or_error?;
164
+ query ( "COMMIT;" )
165
+ . execute ( & mut connection)
166
+ . await
167
+ . into_database ( "commit writer transaction" ) ?;
168
+ query ( "BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;" )
169
+ . execute ( & mut connection)
170
+ . await
171
+ . into_database ( "begin writer transaction" ) ?;
172
+
173
+ connections. push ( connection) ;
174
+ }
175
+
176
+ // Put all the connections back in the pool
177
+ for connection in connections {
178
+ self . connection_tx
179
+ . try_send ( Ok ( connection) )
180
+ . expect ( "channel closed" ) ;
181
+ }
182
+
183
+ Ok ( ( ) )
184
+ }
185
+
160
186
/// Finishes writing to the database, committing all changes.
161
187
///
162
188
/// # Errors
@@ -400,7 +426,7 @@ impl<'conn> MasWriter<'conn> {
400
426
#[ tracing:: instrument( name = "syn2mas.mas_writer.new" , skip_all) ]
401
427
pub async fn new (
402
428
mut conn : LockedMasDatabase < ' conn > ,
403
- index_restore_conn : PgConnection ,
429
+ mut index_restore_conn : PgConnection ,
404
430
mut writer_connections : Vec < PgConnection > ,
405
431
) -> Result < Self , Error > {
406
432
// Given that we don't have any concurrent transactions here,
@@ -511,6 +537,10 @@ impl<'conn> MasWriter<'conn> {
511
537
. into_database ( "begin MAS writer transaction" ) ?;
512
538
}
513
539
540
+ query ( "SET AUTOCOMMIT ON;" )
541
+ . execute ( index_restore_conn. as_mut ( ) )
542
+ . await
543
+ . into_database ( "set conn autocommit" ) ?;
514
544
let ( constraint_restore_tx, index_restore_tx, restorer_task) =
515
545
Self :: restore_task ( index_restore_conn) ;
516
546
@@ -655,6 +685,10 @@ impl<'conn> MasWriter<'conn> {
655
685
Ok ( ( ) )
656
686
}
657
687
688
+ pub async fn commit ( & mut self ) -> Result < ( ) , Error > {
689
+ self . writer_pool . commit ( ) . await
690
+ }
691
+
658
692
/// Finish writing to the MAS database, flushing and committing all changes.
659
693
///
660
694
/// # Errors
0 commit comments