Skip to content

Commit c70f508

Browse files
committed
feat: ELECTRS_ROCKSDB_WRITE_BUFFER_SIZE
In testing setups large write buffer sizes lead to large db files that potentially waste resources / interfere with CIs limits. This change adds an ability to overwrite the default behavior.
1 parent adedee1 commit c70f508

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/new_index/db.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ pub enum DBFlush {
8080
Enable,
8181
}
8282

83+
fn get_write_buffer_size() -> usize {
84+
const VAR_NAME: &str = "ELECTRS_ROCKSDB_WRITE_BUFFER_SIZE";
85+
86+
if let Ok(var) = std::env::var(VAR_NAME) {
87+
let size = FromStr::from_str(&var).expect("Could not parse {VAR_NAME}");
88+
89+
info!("Using custom write buffer size: {size}");
90+
91+
size
92+
} else {
93+
256 << 20
94+
}
95+
}
96+
8397
impl DB {
8498
pub fn open(path: &Path, config: &Config) -> DB {
8599
debug!("opening DB at {:?}", path);
@@ -89,7 +103,7 @@ impl DB {
89103
db_opts.set_compaction_style(rocksdb::DBCompactionStyle::Level);
90104
db_opts.set_compression_type(rocksdb::DBCompressionType::Snappy);
91105
db_opts.set_target_file_size_base(1_073_741_824);
92-
db_opts.set_write_buffer_size(256 << 20);
106+
db_opts.set_write_buffer_size(get_write_buffer_size());
93107
db_opts.set_disable_auto_compactions(true); // for initial bulk load
94108

95109
// db_opts.set_advise_random_on_open(???);

0 commit comments

Comments
 (0)