Skip to content

Commit 81d8575

Browse files
author
Ludo Galabru
committed
fix: recreate db conn on a regular basis
1 parent 96fd8a8 commit 81d8575

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

components/ordhook-cli/src/core/pipeline/processors/block_archiving.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ pub fn start_block_archiving_processor(
2727
let ctx = ctx.clone();
2828
let handle: JoinHandle<()> = hiro_system_kit::thread_named("Processor Runloop")
2929
.spawn(move || {
30-
let blocks_db_rw =
30+
let mut blocks_db_rw =
3131
open_readwrite_ordhook_db_conn_rocks_db(&config.expected_cache_path(), &ctx).unwrap();
3232
let mut empty_cycles = 0;
33+
let mut processed_blocks = 0;
3334

3435
if let Ok(PostProcessorCommand::Start) = commands_rx.recv() {
3536
let _ = events_tx.send(PostProcessorEvent::Started);
@@ -67,7 +68,13 @@ pub fn start_block_archiving_processor(
6768
}
6869
},
6970
};
71+
processed_blocks += compacted_blocks.len();
7072
store_compacted_blocks(compacted_blocks, update_tip, &blocks_db_rw, &ctx);
73+
74+
if processed_blocks % 10_000 == 0 {
75+
let _ = blocks_db_rw.flush_wal(true);
76+
blocks_db_rw = open_readwrite_ordhook_db_conn_rocks_db(&config.expected_cache_path(), &ctx).unwrap();
77+
}
7178
}
7279

7380
if let Err(e) = blocks_db_rw.flush() {

components/ordhook-cli/src/core/pipeline/processors/inscription_indexing.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ pub fn start_inscription_indexing_processor(
5656
let ctx = ctx.clone();
5757
let handle: JoinHandle<()> = hiro_system_kit::thread_named("Inscription indexing runloop")
5858
.spawn(move || {
59-
let cache_l2 = Arc::new(new_traversals_lazy_cache(1024));
60-
let garbage_collect_every_n_blocks = 100;
59+
let cache_l2 = Arc::new(new_traversals_lazy_cache(100_000));
60+
let garbage_collect_every_n_blocks = 256;
6161
let mut garbage_collect_nth_block = 0;
6262

6363
let mut inscriptions_db_conn_rw =
6464
open_readwrite_ordhook_db_conn(&config.expected_cache_path(), &ctx).unwrap();
6565
let ordhook_config = config.get_ordhook_config();
66-
let blocks_db_rw =
66+
let mut blocks_db_rw =
6767
open_readwrite_ordhook_db_conn_rocks_db(&config.expected_cache_path(), &ctx).unwrap();
6868
let mut empty_cycles = 0;
6969

@@ -132,14 +132,23 @@ pub fn start_inscription_indexing_processor(
132132

133133
garbage_collect_nth_block += blocks.len();
134134

135-
// Clear L2 cache on a regular basis
136135
if garbage_collect_nth_block > garbage_collect_every_n_blocks {
136+
// Clear L2 cache on a regular basis
137137
info!(
138138
ctx.expect_logger(),
139139
"Clearing cache L2 ({} entries)",
140140
cache_l2.len()
141141
);
142142
cache_l2.clear();
143+
144+
// Clear rocksdb db connection on a regular basis
145+
let _ = blocks_db_rw.flush_wal(true);
146+
blocks_db_rw = open_readwrite_ordhook_db_conn_rocks_db(&config.expected_cache_path(), &ctx).unwrap();
147+
148+
// Recreate sqlite db connection on a regular basis
149+
inscriptions_db_conn_rw =
150+
open_readwrite_ordhook_db_conn(&config.expected_cache_path(), &ctx).unwrap();
151+
143152
garbage_collect_nth_block = 0;
144153
}
145154
}

0 commit comments

Comments
 (0)