mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 00:57:57 +00:00
Fix db initialization for light client (#7130)
* Fix db initialization for light client * Fix cache distribution
This commit is contained in:
@@ -227,31 +227,46 @@ pub fn open_database<Block: BlockT>(
|
||||
|
||||
// and now open database assuming that it has the latest version
|
||||
let mut db_config = kvdb_rocksdb::DatabaseConfig::with_columns(NUM_COLUMNS);
|
||||
let state_col_budget = (*cache_size as f64 * 0.9) as usize;
|
||||
let other_col_budget = (cache_size - state_col_budget) / (NUM_COLUMNS as usize - 1);
|
||||
let mut memory_budget = std::collections::HashMap::new();
|
||||
let path = path.to_str()
|
||||
.ok_or_else(|| sp_blockchain::Error::Backend("Invalid database path".into()))?;
|
||||
|
||||
for i in 0..NUM_COLUMNS {
|
||||
if i == crate::columns::STATE {
|
||||
memory_budget.insert(i, state_col_budget);
|
||||
} else {
|
||||
memory_budget.insert(i, other_col_budget);
|
||||
let mut memory_budget = std::collections::HashMap::new();
|
||||
match db_type {
|
||||
DatabaseType::Full => {
|
||||
let state_col_budget = (*cache_size as f64 * 0.9) as usize;
|
||||
let other_col_budget = (cache_size - state_col_budget) / (NUM_COLUMNS as usize - 1);
|
||||
|
||||
for i in 0..NUM_COLUMNS {
|
||||
if i == crate::columns::STATE {
|
||||
memory_budget.insert(i, state_col_budget);
|
||||
} else {
|
||||
memory_budget.insert(i, other_col_budget);
|
||||
}
|
||||
}
|
||||
log::trace!(
|
||||
target: "db",
|
||||
"Open RocksDB database at {}, state column budget: {} MiB, others({}) column cache: {} MiB",
|
||||
path,
|
||||
state_col_budget,
|
||||
NUM_COLUMNS,
|
||||
other_col_budget,
|
||||
);
|
||||
},
|
||||
DatabaseType::Light => {
|
||||
let col_budget = cache_size / (NUM_COLUMNS as usize);
|
||||
for i in 0..NUM_COLUMNS {
|
||||
memory_budget.insert(i, col_budget);
|
||||
}
|
||||
log::trace!(
|
||||
target: "db",
|
||||
"Open RocksDB light database at {}, column cache: {} MiB",
|
||||
path,
|
||||
col_budget,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
db_config.memory_budget = memory_budget;
|
||||
|
||||
log::trace!(
|
||||
target: "db",
|
||||
"Open RocksDB database at {}, state column budget: {} MiB, others({}) column cache: {} MiB",
|
||||
path,
|
||||
state_col_budget,
|
||||
NUM_COLUMNS,
|
||||
other_col_budget,
|
||||
);
|
||||
|
||||
let db = kvdb_rocksdb::Database::open(&db_config, &path)
|
||||
.map_err(|err| sp_blockchain::Error::Backend(format!("{}", err)))?;
|
||||
sp_database::as_database(db)
|
||||
@@ -262,7 +277,7 @@ pub fn open_database<Block: BlockT>(
|
||||
},
|
||||
#[cfg(feature = "with-parity-db")]
|
||||
DatabaseSettingsSrc::ParityDb { path } => {
|
||||
crate::parity_db::open(&path)
|
||||
crate::parity_db::open(&path, db_type)
|
||||
.map_err(|e| sp_blockchain::Error::Backend(format!("{:?}", e)))?
|
||||
},
|
||||
#[cfg(not(feature = "with-parity-db"))]
|
||||
|
||||
Reference in New Issue
Block a user