feat: introduce preloaded index cache and thread-safe progress tracker
Introduce `PreloadedIndex` to cache partition indices and eliminate redundant I/O during repeated queries. Refactor the query pipeline to route through this pre-loaded index, and expose it publicly in `obikpartitionner`. Additionally, add a thread-safe, lazily-initialized `MultiProgress` singleton for improved progress tracking.
This commit is contained in:
1 parent
2ebc5f0d75
commit
1661dd6b1c
4 files changed
+137
-11
No files matched your search
@@ -5,6 +5,7 @@ use std::sync::Arc;
|
||||
|
||||
use clap::Args;
|
||||
use obikindex::KmerIndex;
|
||||
use obikpartitionner::PreloadedIndex;
|
||||
use obilayeredmap::IndexMode;
|
||||
use obiread::chunk::read_sequence_chunks;
|
||||
use obiread::record::{SeqRecord, parse_chunk};
|
||||
@@ -211,6 +212,7 @@ fn apply_findere(
|
||||
|
||||
fn process_chunk(
|
||||
idx: &KmerIndex,
|
||||
preloaded: &PreloadedIndex,
|
||||
rope: Rope,
|
||||
k: usize,
|
||||
n_genomes: usize,
|
||||
@@ -243,9 +245,8 @@ fn process_chunk(
|
||||
continue;
|
||||
}
|
||||
|
||||
let kmer_results = idx
|
||||
.partition()
|
||||
.query_partition(part_idx, part_sks, k, n_genomes, with_counts)
|
||||
let kmer_results = preloaded
|
||||
.query_partition(part_idx, part_sks, k, n_genomes)
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("query error on partition {part_idx}: {e}");
|
||||
std::process::exit(1);
|
||||
@@ -351,6 +352,14 @@ pub fn run(args: QueryArgs) {
|
||||
eprintln!("warning: --mismatch not yet implemented, ignored");
|
||||
}
|
||||
|
||||
let preloaded = Arc::new(
|
||||
PreloadedIndex::new(idx.partition(), n_partitions, with_counts)
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("error loading index layers: {e}");
|
||||
std::process::exit(1);
|
||||
})
|
||||
);
|
||||
|
||||
let detail = args.detail;
|
||||
let count_missing = args.count_missing;
|
||||
let force_presence = args.force_presence;
|
||||
@@ -376,11 +385,12 @@ pub fn run(args: QueryArgs) {
|
||||
let pipe = obipipeline::make_pipe! {
|
||||
QueryData : Rope => Vec<u8>,
|
||||
| {
|
||||
let idx = Arc::clone(&idx);
|
||||
let idx = Arc::clone(&idx);
|
||||
let preloaded = Arc::clone(&preloaded);
|
||||
move |rope: Rope| {
|
||||
process_chunk(
|
||||
&idx, rope, k, n_genomes, n_partitions, with_counts, effective_z,
|
||||
detail, count_missing, force_presence, presence_threshold,
|
||||
&idx, &preloaded, rope, k, n_genomes, n_partitions, with_counts,
|
||||
effective_z, detail, count_missing, force_presence, presence_threshold,
|
||||
)
|
||||
}
|
||||
} : Chunk => Output,
|
||||
|
||||
Reference in new issue
Block a user