From ed1bed3a363a1d8c48b2d49a81592cda16ee0ae0 Mon Sep 17 00:00:00 2001 From: GroovieGermanikus Date: Thu, 21 Dec 2023 20:00:42 +0100 Subject: [PATCH] cleanup also from amb table --- src/postgres.rs | 53 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/src/postgres.rs b/src/postgres.rs index 255c5b6..b4b342b 100644 --- a/src/postgres.rs +++ b/src/postgres.rs @@ -816,35 +816,50 @@ impl PostgresSession { cutoff_transaction_incl ); - // delete accounts_map_transaction { - let tx_to_delete = self.client.query_one( + let txs_to_delete = self.client.query_one( &format!( r" - SELECT count(*) as cnt_tx FROM banking_stage_results_2.accounts_map_transaction amt + SELECT count(*) as cnt_tx FROM banking_stage_results_2.transactions txs + WHERE txs.transaction_id <= {cutoff_transaction} + ", + cutoff_transaction = cutoff_transaction_incl + ), + &[]).await.unwrap(); + + let txs_to_delete: i64 = txs_to_delete.get("cnt_tx"); + + info!("would delete transactions: {}", txs_to_delete); + } + + { + let amt_to_delete = self.client.query_one( + &format!( + r" + SELECT count(*) as cnt_amt FROM banking_stage_results_2.accounts_map_transaction amt WHERE amt.transaction_id <= {cutoff_transaction} ", cutoff_transaction = cutoff_transaction_incl ), &[]).await.unwrap(); - let tx_to_delete: i64 = tx_to_delete.get("cnt_tx"); + let amt_to_delete: i64 = amt_to_delete.get("cnt_amt"); - info!("would delete transactions: {}", tx_to_delete); + info!("would delete accounts_map_transaction: {}", amt_to_delete); } { let amb_to_delete = self.client.query_one( &format!( r" - SELECT count(*) as cnt_ambs FROM banking_stage_results_2.accounts_map_blocks amb + SELECT count(*) as cnt_amb FROM banking_stage_results_2.accounts_map_blocks amb WHERE amb.slot < {cutoff_slot} ", cutoff_slot = cutoff_slot_excl ), &[]).await.unwrap(); - let amb_to_delete: i64 = amb_to_delete.get("cnt_ambs"); + let amb_to_delete: i64 = amb_to_delete.get("cnt_amb"); info!("would delete from accounts_map_blocks: {}", amb_to_delete); } @@ -895,7 +910,7 @@ impl PostgresSession { ", transaction_id = cutoff_transaction_incl ), &[]).await.unwrap(); info!( - "Deleted {} rows from transactions in {:.2}ms", + "Deleted {} rows from transactions in {:.3}s", deleted_rows, started.elapsed().as_secs_f32() ); @@ -909,7 +924,21 @@ impl PostgresSession { ", transaction_id = cutoff_transaction_incl ), &[]).await.unwrap(); info!( - "Deleted {} rows from accounts_map_transaction in {:.2}ms", + "Deleted {} rows from accounts_map_transaction in {:.3}s", + deleted_rows, + started.elapsed().as_secs_f32() + ); + } + { + let started = Instant::now(); + let deleted_rows = self.client.execute( + &format!( + r" + DELETE FROM banking_stage_results_2.accounts_map_blocks WHERE slot <= {cutoff_slot} + ", cutoff_slot = cutoff_slot_excl + ), &[]).await.unwrap(); + info!( + "Deleted {} rows from accounts_map_blocks in {:.3}s", deleted_rows, started.elapsed().as_secs_f32() ); @@ -923,7 +952,7 @@ impl PostgresSession { ", cutoff_slot = cutoff_slot_excl ), &[]).await.unwrap(); info!( - "Deleted {} rows from transaction_infos in {:.2}ms", + "Deleted {} rows from transaction_infos in {:.3}s", deleted_rows, started.elapsed().as_secs_f32() ); @@ -944,7 +973,7 @@ impl PostgresSession { .await .unwrap(); info!( - "Deleted {} rows from transaction_slot in {:.2}ms", + "Deleted {} rows from transaction_slot in {:.3}s", deleted_rows, started.elapsed().as_secs_f32() ); @@ -961,6 +990,8 @@ impl PostgresSession { self.log_rowcount(Level::Info, "transaction_infos").await; self.log_rowcount(Level::Info, "transaction_slot").await; } + + info!("Cleanup job completed."); } async fn log_rowcount(&self, level: Level, table: &str) {