parser: reactivate 'first_defragment' option

This commit is contained in:
k
2024-10-31 11:39:36 +01:00
parent 647a51af15
commit 216a3977be
4 changed files with 21 additions and 41 deletions

View File

@@ -32,11 +32,9 @@ pub fn iter_blocks(
let mut databases = Databases::import();
if config.first_defragment() {
exit.block();
databases.defragment();
if true {
panic!("Done");
}
exit.unblock();
}
log("Imported databases");

View File

@@ -49,7 +49,13 @@ where
Value: Storable + PartialEq,
{
pub fn open(folder: &str, file: &str) -> color_eyre::Result<Self> {
let mut txn = Self::init_txn(folder, file)?;
let path = databases_folder_path(folder);
fs::create_dir_all(&path)?;
let path = format!("{path}/{file}");
let env = unsafe { Env::new_nolock(path, PAGE_SIZE, 1).unwrap() };
let mut txn = Env::mut_txn_begin(env)?;
let db = txn
.root_db(ROOT_DB)
@@ -169,18 +175,6 @@ where
format!("{}/{}", databases_folder_path(&self.folder), self.file)
}
fn init_txn(folder: &str, file: &str) -> color_eyre::Result<MutTxn<Env, ()>> {
let path = databases_folder_path(folder);
fs::create_dir_all(&path)?;
let env = unsafe { Env::new_nolock(format!("{path}/{file}"), PAGE_SIZE, 1).unwrap() };
let txn = Env::mut_txn_begin(env)?;
Ok(txn)
}
fn db_multi_put(&mut self, tree: BTreeMap<Key, Value>) -> Result<(), Error> {
tree.into_iter()
.try_for_each(|(key, value)| -> Result<(), Error> {
@@ -244,10 +238,12 @@ where
let mut s = Self::open(&folder, &file).unwrap();
if s.is_empty() {
s.cached_puts = btree;
s.export().unwrap();
if !s.is_empty() {
panic!()
}
s.cached_puts = btree;
s.export().unwrap();
}
}

View File

@@ -103,39 +103,27 @@ impl Databases {
fn open_all(&mut self) {
thread::scope(|s| {
s.spawn(|| {
time("Opening all address_index_to_address_data", || {
self.address_index_to_address_data.open_all()
})
self.address_index_to_address_data.open_all();
});
s.spawn(|| {
time("Opening all address_index_to_empty_address_data", || {
self.address_index_to_empty_address_data.open_all()
})
self.address_index_to_empty_address_data.open_all();
});
s.spawn(|| {
time("Opening all address_to_address_index", || {
self.address_to_address_index.open_all()
})
self.address_to_address_index.open_all();
});
s.spawn(|| {
time("Opening all txid_to_tx_data", || {
self.txid_to_tx_data.open_all()
})
self.txid_to_tx_data.open_all();
});
s.spawn(|| {
time("Opening all txout_index_to_address_index", || {
self.txout_index_to_address_index.open_all()
})
self.txout_index_to_address_index.open_all();
});
s.spawn(|| {
time("Opening all txout_index_to_amount", || {
self.txout_index_to_amount.open_all()
})
self.txout_index_to_amount.open_all();
});
});
}

View File

@@ -169,8 +169,6 @@ impl Config {
}
pub fn first_defragment(&self) -> bool {
log("Buggy for now, skipped");
false
// self.first_defragment.is_some_and(|b| b)
self.first_defragment.is_some_and(|b| b)
}
}