Skip to content

Commit b3d423e

Browse files
committed
store: Limit for how many prune runs we keep status info
1 parent 4a15ec4 commit b3d423e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

graph/src/env/store.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ pub struct EnvVarsStore {
111111
/// blocks) than its history limit. The default value is 1.2 and the
112112
/// value must be at least 1.01
113113
pub history_slack_factor: f64,
114+
/// For how many prune runs per deployment to keep status information.
115+
/// Set by `GRAPH_STORE_HISTORY_KEEP_STATUS`. The default is 5
116+
pub prune_keep_history: usize,
114117
/// How long to accumulate changes into a batch before a write has to
115118
/// happen. Set by the environment variable
116119
/// `GRAPH_STORE_WRITE_BATCH_DURATION` in seconds. The default is 300s.
@@ -184,6 +187,7 @@ impl TryFrom<InnerStore> for EnvVarsStore {
184187
rebuild_threshold: x.rebuild_threshold.0,
185188
delete_threshold: x.delete_threshold.0,
186189
history_slack_factor: x.history_slack_factor.0,
190+
prune_keep_history: x.prune_keep_status,
187191
write_batch_duration: Duration::from_secs(x.write_batch_duration_in_secs),
188192
write_batch_size: x.write_batch_size * 1_000,
189193
create_gin_indexes: x.create_gin_indexes,
@@ -257,6 +261,8 @@ pub struct InnerStore {
257261
delete_threshold: ZeroToOneF64,
258262
#[envconfig(from = "GRAPH_STORE_HISTORY_SLACK_FACTOR", default = "1.2")]
259263
history_slack_factor: HistorySlackF64,
264+
#[envconfig(from = "GRAPH_STORE_HISTORY_KEEP_STATUS", default = "5")]
265+
prune_keep_status: usize,
260266
#[envconfig(from = "GRAPH_STORE_WRITE_BATCH_DURATION", default = "300")]
261267
write_batch_duration_in_secs: u64,
262268
#[envconfig(from = "GRAPH_STORE_WRITE_BATCH_SIZE", default = "10000")]

node/src/manager/commands/prune.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,16 @@ pub async fn status(
341341
let runs = match runs.len() {
342342
0 => unreachable!("we checked that runs is not empty"),
343343
1 => format!("There is only one prune run #{}", runs[0]),
344+
2 => format!("Only prune runs #{} and #{} exist", runs[0], runs[1]),
344345
_ => format!(
345-
"Only prune runs #{} up to #{} exist",
346+
"Only prune runs #{} and #{} up to #{} exist",
346347
runs[0],
348+
runs[1],
347349
runs.last().unwrap()
348350
),
349351
};
350352
return Err(anyhow!(
351-
"No information about prune run #{run} found for deployment {deployment}. {runs}"
353+
"No information about prune run #{run} found for deployment {deployment}.\n {runs}"
352354
));
353355
};
354356
println!("prune {deployment} (run #{run})");

store/postgres/src/relational/prune.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ mod status {
508508
};
509509
use graph::{
510510
components::store::{PruneRequest, PruningStrategy, StoreResult},
511+
env::ENV_VARS,
511512
prelude::StoreError,
512513
};
513514

@@ -676,6 +677,15 @@ mod status {
676677
.unwrap_or(0)
677678
+ 1;
678679

680+
// Delete old prune state. Keep the initial run and the last
681+
// `prune_keep_history` runs (including this one)
682+
diesel::delete(ps::table)
683+
.filter(ps::id.eq(layout.site.id))
684+
.filter(ps::run.gt(1))
685+
.filter(ps::run.lt(run - (ENV_VARS.store.prune_keep_history - 1) as i32))
686+
.execute(conn)
687+
.map_err(StoreError::from)?;
688+
679689
Ok(Tracker { layout, run })
680690
}
681691

0 commit comments

Comments
 (0)