Consolidate repeated code in Rocks::open() (#34131)
The function matches the access type and calls a different RocksDB function depending on whether we have primary or secondary access. But, lots of the code is the same for these two paths so de-duplicate the repeated sections.
This commit is contained in:
parent
6280b1e53e
commit
29947ba867
|
@ -419,46 +419,39 @@ impl Rocks {
|
||||||
}
|
}
|
||||||
let oldest_slot = OldestSlot::default();
|
let oldest_slot = OldestSlot::default();
|
||||||
let column_options = options.column_options.clone();
|
let column_options = options.column_options.clone();
|
||||||
|
let cf_descriptors = Self::cf_descriptors(&options, &oldest_slot);
|
||||||
|
|
||||||
// Open the database
|
// Open the database
|
||||||
let db = match access_type {
|
let db = match access_type {
|
||||||
AccessType::Primary | AccessType::PrimaryForMaintenance => Rocks {
|
AccessType::Primary | AccessType::PrimaryForMaintenance => {
|
||||||
db: DB::open_cf_descriptors(
|
DB::open_cf_descriptors(&db_options, path, cf_descriptors)?
|
||||||
&db_options,
|
}
|
||||||
path,
|
|
||||||
Self::cf_descriptors(&options, &oldest_slot),
|
|
||||||
)?,
|
|
||||||
access_type,
|
|
||||||
oldest_slot,
|
|
||||||
column_options,
|
|
||||||
write_batch_perf_status: PerfSamplingStatus::default(),
|
|
||||||
},
|
|
||||||
AccessType::Secondary => {
|
AccessType::Secondary => {
|
||||||
let secondary_path = path.join("solana-secondary");
|
let secondary_path = path.join("solana-secondary");
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Opening Rocks with secondary (read only) access at: {:?}",
|
"Opening Rocks with secondary (read only) access at: {secondary_path:?}. \
|
||||||
secondary_path
|
This secondary access could temporarily degrade other accesses, such as \
|
||||||
|
by solana-validator"
|
||||||
);
|
);
|
||||||
info!("This secondary access could temporarily degrade other accesses, such as by solana-validator");
|
DB::open_cf_descriptors_as_secondary(
|
||||||
|
|
||||||
Rocks {
|
|
||||||
db: DB::open_cf_descriptors_as_secondary(
|
|
||||||
&db_options,
|
&db_options,
|
||||||
path,
|
path,
|
||||||
&secondary_path,
|
&secondary_path,
|
||||||
Self::cf_descriptors(&options, &oldest_slot),
|
cf_descriptors,
|
||||||
)?,
|
)?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let rocks = Rocks {
|
||||||
|
db,
|
||||||
access_type,
|
access_type,
|
||||||
oldest_slot,
|
oldest_slot,
|
||||||
column_options,
|
column_options,
|
||||||
write_batch_perf_status: PerfSamplingStatus::default(),
|
write_batch_perf_status: PerfSamplingStatus::default(),
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
db.configure_compaction();
|
|
||||||
|
|
||||||
Ok(db)
|
rocks.configure_compaction();
|
||||||
|
|
||||||
|
Ok(rocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cf_descriptors(
|
fn cf_descriptors(
|
||||||
|
|
Loading…
Reference in New Issue