mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-27 13:47:29 +01:00
Reintroduce appending sorted entries when possible
This commit is contained in:
parent
382be56d36
commit
04b1bbf932
@ -3,7 +3,7 @@ use std::fs::File;
|
|||||||
use std::io::{self, Seek, SeekFrom};
|
use std::io::{self, Seek, SeekFrom};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use grenad::{CompressionType, MergerIter, Reader, Sorter};
|
use grenad::{CompressionType, Reader, Sorter};
|
||||||
use heed::types::ByteSlice;
|
use heed::types::ByteSlice;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
@ -209,18 +209,14 @@ pub fn sorter_into_lmdb_database(
|
|||||||
debug!("Writing MTBL sorter...");
|
debug!("Writing MTBL sorter...");
|
||||||
let before = Instant::now();
|
let before = Instant::now();
|
||||||
|
|
||||||
merger_iter_into_lmdb_database(wtxn, database, sorter.into_stream_merger_iter()?, merge)?;
|
let mut merger_iter = sorter.into_stream_merger_iter()?;
|
||||||
|
if database.is_empty(wtxn)? {
|
||||||
debug!("MTBL sorter writen in {:.02?}!", before.elapsed());
|
let mut out_iter = database.iter_mut::<_, ByteSlice, ByteSlice>(wtxn)?;
|
||||||
Ok(())
|
while let Some((k, v)) = merger_iter.next()? {
|
||||||
|
// safety: we don't keep references from inside the LMDB database.
|
||||||
|
unsafe { out_iter.append(k, v)? };
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
fn merger_iter_into_lmdb_database<R: io::Read + io::Seek>(
|
|
||||||
wtxn: &mut heed::RwTxn,
|
|
||||||
database: heed::PolyDatabase,
|
|
||||||
mut merger_iter: MergerIter<R, MergeFn>,
|
|
||||||
merge: MergeFn,
|
|
||||||
) -> Result<()> {
|
|
||||||
while let Some((k, v)) = merger_iter.next()? {
|
while let Some((k, v)) = merger_iter.next()? {
|
||||||
let mut iter = database.prefix_iter_mut::<_, ByteSlice, ByteSlice>(wtxn, k)?;
|
let mut iter = database.prefix_iter_mut::<_, ByteSlice, ByteSlice>(wtxn, k)?;
|
||||||
match iter.next().transpose()? {
|
match iter.next().transpose()? {
|
||||||
@ -239,6 +235,8 @@ fn merger_iter_into_lmdb_database<R: io::Read + io::Seek>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!("MTBL sorter writen in {:.02?}!", before.elapsed());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user