Add config flag for deleting old data

Keeping it is very useful for testing.
This commit is contained in:
Christian Kamm 2022-01-03 10:33:26 +01:00
parent f0c26bb8fb
commit d5395a3b75
4 changed files with 49 additions and 40 deletions

View File

@ -24,3 +24,4 @@ retry_query_sleep_secs = 5
retry_connection_sleep_secs = 30
fatal_connection_timeout_secs = 600
allow_invalid_certs = false
delete_old_data = true

View File

@ -24,3 +24,4 @@ retry_query_sleep_secs = 5
retry_connection_sleep_secs = 30
fatal_connection_timeout_secs = 600
allow_invalid_certs = false
delete_old_data = true

View File

@ -82,6 +82,8 @@ pub struct PostgresConfig {
pub fatal_connection_timeout_secs: u64,
/// Allow invalid TLS certificates, passed to native_tls danger_accept_invalid_certs
pub allow_invalid_certs: bool,
/// Delete old data automatically, keeping only the current data snapshot
pub delete_old_data: bool,
}
#[derive(Clone, Debug, Deserialize)]

View File

@ -170,7 +170,10 @@ struct SlotsProcessing {
}
impl SlotsProcessing {
fn new(tables: &Vec<String>) -> Self {
fn new(tables: &Vec<String>, delete_old_data: bool) -> Self {
let cleanup_table_sql = Vec::<String>::new();
if delete_old_data {
// Delete:
// 1. account writes that came before the newest rooted write
// 2. account writes that came after the newest rooted write but before
@ -211,7 +214,9 @@ impl SlotsProcessing {
.collect();
// Delete old slots
cleanup_table_sql.push("DELETE FROM slot WHERE slot + 100000 < $newest_final_slot".into());
cleanup_table_sql
.push("DELETE FROM slot WHERE slot + 100000 < $newest_final_slot".into());
}
Self { cleanup_table_sql }
}
@ -264,7 +269,7 @@ impl SlotsProcessing {
.context("updating preceding non-rooted slots")?;
// Keep only the newest rooted account write and also
// wipe old slots
// wipe old slots (if configured)
for cleanup_sql in &self.cleanup_table_sql {
let query = query_dyn!(cleanup_sql, newest_final_slot = update.slot)?;
let _ = query
@ -407,7 +412,7 @@ pub async fn init(
.iter()
.map(|table| table.table_name().to_string())
.collect();
let slots_processing = SlotsProcessing::new(&table_names);
let slots_processing = SlotsProcessing::new(&table_names, config.delete_old_data);
for _ in 0..config.slot_update_connection_count {
let postgres_slot =
postgres_connection(config, metric_con_retries.clone(), metric_con_live.clone())