Put the documents MTBL back into LMDB

We makes sure to write the documents into a file before
memory mapping it and putting it into LMDB, this way we avoid
moving it to RAM
This commit is contained in:
Clément Renault
2020-08-28 15:38:05 +02:00
parent d784d87880
commit 0a44ff86ab
10 changed files with 100 additions and 110 deletions

View File

@ -62,7 +62,6 @@ fn highlight_string(string: &str, words: &HashSet<String>) -> String {
struct IndexTemplate {
db_name: String,
db_size: usize,
docs_size: usize,
docs_count: usize,
}
@ -83,28 +82,23 @@ async fn main() -> anyhow::Result<()> {
.open(&opt.database)?;
// Open the LMDB database.
let index = Index::new(&env, &opt.database)?;
let index = Index::new(&env)?;
// Retrieve the database the file stem (w/o the extension),
// the disk file size and the number of documents in the database.
let db_name = opt.database.file_stem().and_then(|s| s.to_str()).unwrap_or("").to_string();
let db_size = File::open(opt.database.join("data.mdb"))?.metadata()?.len() as usize;
let docs_size = File::open(opt.database.join("documents.mtbl"))?.metadata()?.len() as usize;
let docs_count = index.number_of_documents();
let rtxn = env.read_txn()?;
let docs_count = index.number_of_documents(&rtxn)? as usize;
drop(rtxn);
// We run and wait on the HTTP server
// Expose an HTML page to debug the search in a browser
let dash_html_route = warp::filters::method::get()
.and(warp::filters::path::end())
.map(move || {
IndexTemplate {
db_name: db_name.clone(),
db_size,
docs_size,
docs_count: docs_count as usize,
}
});
.map(move || IndexTemplate { db_name: db_name.clone(), db_size, docs_count });
let dash_bulma_route = warp::filters::method::get()
.and(warp::path!("bulma.min.css"))
@ -192,7 +186,7 @@ async fn main() -> anyhow::Result<()> {
if let Some(headers) = index.headers(&rtxn).unwrap() {
// We write the headers
body.extend_from_slice(headers);
let documents = index.documents(documents_ids).unwrap();
let documents = index.documents(&rtxn, documents_ids).unwrap();
for (_id, content) in documents {
let content = std::str::from_utf8(content.as_ref()).unwrap();