Skip to content

Commit afe1dc7

Browse files
committed
configurable buffer size
1 parent f7a7833 commit afe1dc7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

docs/docs/users/reference/env_variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ process.
4747
| `FOREST_TRACE_FILTER_MAX_RESULT` | positive integer | 500 | 1000 | Sets the maximum results returned per request by `trace_filter` |
4848
| `FOREST_CHAIN_INDEXER_ENABLED` | 1 or true | false | 1 | Whether or not to index the chain to support the Ethereum RPC API |
4949
| `FOREST_MESSAGES_IN_TIPSET_CACHE_SIZE` | positive integer | 100 | 42 | The size of an internal cache of tipsets to messages |
50+
| `FOREST_STATE_MIGRATION_DB_WRITE_BUFFER` | non-negative integer | 10000 | 100000 | The size of db write buffer for state migration (~10MB memory per 10k buffer) |
5051

5152
### `FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT`
5253

src/state_migration/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ pub fn run_state_migrations<DB>(
9595
where
9696
DB: Blockstore + Send + Sync,
9797
{
98+
// ~10MB memory per 10k buffer
99+
let db_write_buffer = match std::env::var("FOREST_STATE_MIGRATION_DB_WRITE_BUFFER") {
100+
Ok(v) => v.parse().ok(),
101+
_ => None,
102+
}
103+
.unwrap_or(10000);
98104
let mappings = get_migrations(&chain_config.network);
99105

100106
// Make sure bundle is defined.
@@ -118,7 +124,10 @@ where
118124
if epoch == chain_config.epoch(height) {
119125
tracing::info!("Running {height} migration at epoch {epoch}");
120126
let start_time = std::time::Instant::now();
121-
let db = Arc::new(BlockstoreWithWriteBuffer::new(db.clone()));
127+
let db = Arc::new(BlockstoreWithWriteBuffer::new_with_capacity(
128+
db.clone(),
129+
db_write_buffer,
130+
));
122131
let new_state = migrate(chain_config, &db, parent_state, epoch)?;
123132
let elapsed = start_time.elapsed();
124133
// `new_state_actors` is the Go state migration output, log for comparision
@@ -148,7 +157,7 @@ where
148157
Ok(None)
149158
}
150159

151-
pub struct BlockstoreWithWriteBuffer<DB: Blockstore> {
160+
pub(crate) struct BlockstoreWithWriteBuffer<DB: Blockstore> {
152161
inner: DB,
153162
buffer: RwLock<HashMap<Cid, Vec<u8>>>,
154163
buffer_capacity: usize,
@@ -176,10 +185,6 @@ impl<DB: Blockstore> Blockstore for BlockstoreWithWriteBuffer<DB> {
176185
}
177186

178187
impl<DB: Blockstore> BlockstoreWithWriteBuffer<DB> {
179-
pub fn new(inner: DB) -> Self {
180-
Self::new_with_capacity(inner, 10000)
181-
}
182-
183188
pub fn new_with_capacity(inner: DB, buffer_capacity: usize) -> Self {
184189
Self {
185190
inner,

0 commit comments

Comments
 (0)