Skip to content

Commit 38718fd

Browse files
committed
feat(gc): FOREST_SNAPSHOT_GC_KEEP_STATE_TREE_EPOCHS env var
1 parent 08b2e2c commit 38718fd

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

docs/docs/users/reference/env_variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ process.
4848
| `FOREST_STATE_MIGRATION_DB_WRITE_BUFFER` | non-negative integer | 10000 | 100000 | The size of db write buffer for state migration (`~10MB` RAM per `10k` buffer) |
4949
| `FOREST_SNAPSHOT_GC_INTERVAL_EPOCHS` | non-negative integer | 20160 | 8000 | The interval in epochs for scheduling snapshot GC |
5050
| `FOREST_SNAPSHOT_GC_CHECK_INTERVAL_SECONDS` | non-negative integer | 300 | 60 | The interval in seconds for checking if snapshot GC should run |
51+
| `FOREST_SNAPSHOT_GC_KEEP_STATE_TREE_EPOCHS` | non-negative integer | 2000 | 20160 | The number of most recent epochs of state trees to keep after GC |
5152
| `FOREST_DISABLE_BAD_BLOCK_CACHE` | 1 or true | empty | 1 | Whether or not to disable bad block cache |
5253
| `FOREST_ZSTD_FRAME_CACHE_DEFAULT_MAX_SIZE` | positive integer | 268435456 | 536870912 | The default zstd frame cache max size in bytes |
5354
| `FOREST_JWT_DISABLE_EXP_VALIDATION` | 1 or true | empty | 1 | Whether or not to disable JWT expiration validation |

src/db/gc/snapshot.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,20 @@ where
100100
let chain_data_path = chain_path(config);
101101
let db_root_dir = db_root(&chain_data_path)?;
102102
let car_db_dir = db_root_dir.join(CAR_DB_DIR_NAME);
103-
let recent_state_roots = config.sync.recent_state_roots;
103+
let recent_state_roots = std::env::var("FOREST_SNAPSHOT_GC_KEEP_STATE_TREE_EPOCHS")
104+
.ok()
105+
.and_then(|i| {
106+
i.parse().ok().and_then(|i| {
107+
if i >= config.sync.recent_state_roots {
108+
tracing::info!("Snapshot GC is set to keep {i} epochs of state trees");
109+
Some(i)
110+
} else {
111+
tracing::warn!("Snapshot GC cannot to be set to keep {i} epochs of state trees, at least {} is required for snapshot export", config.sync.recent_state_roots);
112+
None
113+
}
114+
})
115+
})
116+
.unwrap_or(config.sync.recent_state_roots);
104117
let (reboot_tx, reboot_rx) = flume::bounded(1);
105118
let (trigger_tx, trigger_rx) = flume::bounded(1);
106119
Ok((

0 commit comments

Comments
 (0)