Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refine file cache management in genesis data import #2097

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/rooch/src/commands/statedb/commands/genesis_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,12 @@ fn produce_ord_updates(tx: SyncSender<BatchUpdatesOrd>, input: PathBuf, batch_si

for line in reader.by_ref().lines().take(batch_size) {
let line = line.unwrap();
bytes_read += line.len() as u64 + 1; // Add line.len() + 1, assuming that the line terminator is '\n'

if is_title_line {
is_title_line = false;
if line.starts_with("# export at") {
// skip block height info
bytes_read += line.len() as u64 + 1; // Add line.len() + 1, assuming that the line terminator is '\n'
continue;
}
}
Expand All @@ -488,7 +488,6 @@ fn produce_ord_updates(tx: SyncSender<BatchUpdatesOrd>, input: PathBuf, batch_si
let (key2, state2) = gen_inscription_ids_update(index, inscription_id);
updates.inscription_ids_updates.put(key2, state2);
index += 1;
bytes_read += line.len() as u64 + 1;
}
let _ = file_cache_mgr.drop_cache_range(cache_drop_offset, bytes_read);
cache_drop_offset += bytes_read;
Expand Down
9 changes: 9 additions & 0 deletions crates/rooch/src/commands/statedb/commands/genesis_utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use moveos_types::moveos_std::simple_multimap::{Element, SimpleMultiMap};
use moveos_types::startup_info::StartupInfo;
use moveos_types::state::{KeyState, MoveState, State};
use redb::{Database, ReadOnlyTable};
use rooch_common::fs::file_cache::FileCacheManager;
use rooch_config::{RoochOpt, R_OPT_NET_HELP};
use rooch_db::RoochDB;
use rooch_types::address::BitcoinAddress;
Expand Down Expand Up @@ -399,6 +400,9 @@ pub fn produce_utxo_updates(
batch_size: usize,
utxo_ord_map_db: Option<Arc<Database>>,
) {
let file_cache_mgr = FileCacheManager::new(input.clone()).unwrap();
let mut cache_drop_offset: u64 = 0;

let mut csv_reader = BufReader::with_capacity(8 * 1024 * 1024, File::open(input).unwrap());
let mut is_title_line = true;
let mut address_mapping_checker = HashMap::new();
Expand All @@ -410,12 +414,15 @@ pub fn produce_utxo_updates(
}
};
loop {
let mut bytes_read = 0;

let mut updates = BatchUpdates {
utxo_updates: UpdateSet::new(),
rooch_to_bitcoin_mapping_updates: UpdateSet::new(),
};
for line in csv_reader.by_ref().lines().take(batch_size) {
let line = line.unwrap();
bytes_read += line.len() as u64 + 1; // Add line.len() + 1, assuming that the line terminator is '\n'

if is_title_line {
is_title_line = false;
Expand Down Expand Up @@ -447,6 +454,8 @@ pub fn produce_utxo_updates(
}
}
}
let _ = file_cache_mgr.drop_cache_range(cache_drop_offset, bytes_read);
cache_drop_offset += bytes_read;
if updates.utxo_updates.is_empty() {
break;
}
Expand Down
Loading