Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
review edits
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed May 31, 2021
1 parent 1c4f0b2 commit 7cf9d37
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 52 deletions.
21 changes: 9 additions & 12 deletions meilisearch-http/src/index/dump.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::{
fs::{create_dir_all, File},
io::{BufRead, BufReader},
path::Path,
sync::Arc,
};

use anyhow::bail;
use anyhow::Context;
use std::fs::{create_dir_all, File};
use std::io::{BufRead, BufReader, Write};
use std::path::Path;
use std::sync::Arc;

use anyhow::{bail, Context};
use heed::RoTxn;
use indexmap::IndexMap;
use milli::update::{IndexDocumentsMethod, UpdateFormat::JsonStream};
Expand Down Expand Up @@ -55,7 +52,7 @@ impl Index {
}

serde_json::to_writer(&mut document_file, &json_map)?;
std::io::Write::write(&mut document_file, b"\n")?;
document_file.write_all(b"\n")?;

json_map.clear();
}
Expand All @@ -82,7 +79,7 @@ impl Index {
pub fn load_dump(
src: impl AsRef<Path>,
dst: impl AsRef<Path>,
size: u64,
size: usize,
indexing_options: &IndexerOpts,
) -> anyhow::Result<()> {
let dir_name = src
Expand All @@ -99,7 +96,7 @@ impl Index {
primary_key,
} = serde_json::from_reader(&mut meta_file)?;
let settings = settings.check();
let index = Self::open(&dst_dir_path, size as usize)?;
let index = Self::open(&dst_dir_path, size)?;
let mut txn = index.write_txn()?;

let handler = UpdateHandler::new(&indexing_options)?;
Expand Down
12 changes: 4 additions & 8 deletions meilisearch-http/src/index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::{collections::{BTreeSet, HashSet}, fs::create_dir_all};
use std::marker::PhantomData;
use std::ops::Deref;
use std::path::Path;
use std::sync::Arc;
use std::{
collections::{BTreeSet, HashSet},
marker::PhantomData,
path::Path,
};

use anyhow::{bail, Context};
use heed::{EnvOpenOptions, RoTxn};
Expand Down Expand Up @@ -44,7 +42,7 @@ where

impl Index {
pub fn open(path: impl AsRef<Path>, size: usize) -> anyhow::Result<Self> {
std::fs::create_dir_all(&path)?;
create_dir_all(&path)?;
let mut options = EnvOpenOptions::new();
options.map_size(size);
let index = milli::Index::new(options, &path)?;
Expand Down Expand Up @@ -113,8 +111,6 @@ impl Index {

let mut documents = Vec::new();

println!("fields to display: {:?}", fields_to_display);

for entry in iter {
let (_id, obkv) = entry?;
let object = obkv_to_json(&fields_to_display, &fields_ids_map, obkv)?;
Expand Down
6 changes: 2 additions & 4 deletions meilisearch-http/src/index/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,8 @@ impl Index {
builder.update_format(format);
builder.index_documents_method(method);

//let indexing_callback =
//|indexing_step, update_id| info!("update {}: {:?}", update_id, indexing_step);

let indexing_callback = |_, _| ();
let indexing_callback =
|indexing_step, update_id| info!("update {}: {:?}", update_id, indexing_step);

let gzipped = false;
let addition = match content {
Expand Down
14 changes: 6 additions & 8 deletions meilisearch-http/src/index_controller/dump_actor/actor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::{
collections::HashMap,
path::{Path, PathBuf},
};

use async_stream::stream;
use chrono::Utc;
Expand All @@ -24,8 +22,8 @@ pub struct DumpActor<UuidResolver, Update> {
dump_path: PathBuf,
lock: Arc<Mutex<()>>,
dump_infos: Arc<RwLock<HashMap<String, DumpInfo>>>,
update_db_size: u64,
index_db_size: u64,
update_db_size: usize,
index_db_size: usize,
}

/// Generate uid from creation date
Expand All @@ -43,8 +41,8 @@ where
uuid_resolver: UuidResolver,
update: Update,
dump_path: impl AsRef<Path>,
index_db_size: u64,
update_db_size: u64,
index_db_size: usize,
update_db_size: usize,
) -> Self {
let dump_infos = Arc::new(RwLock::new(HashMap::new()));
let lock = Arc::new(Mutex::new(()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl DumpActorHandleImpl {
path: impl AsRef<Path>,
uuid_resolver: crate::index_controller::uuid_resolver::UuidResolverHandleImpl,
update: crate::index_controller::update_actor::UpdateActorHandleImpl<Bytes>,
index_db_size: u64,
update_db_size: u64,
index_db_size: usize,
update_db_size: usize,
) -> anyhow::Result<Self> {
let (sender, receiver) = mpsc::channel(10);
let actor = DumpActor::new(
Expand Down
15 changes: 7 additions & 8 deletions meilisearch-http/src/index_controller/dump_actor/loaders/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use crate::{
#[serde(rename_all = "camelCase")]
pub struct MetadataV2 {
db_version: String,
index_db_size: u64,
update_db_size: u64,
index_db_size: usize,
update_db_size: usize,
dump_date: DateTime<Utc>,
}

impl MetadataV2 {
pub fn new(index_db_size: u64, update_db_size: u64) -> Self {
pub fn new(index_db_size: usize, update_db_size: usize) -> Self {
Self {
db_version: env!("CARGO_PKG_VERSION").to_string(),
index_db_size,
Expand All @@ -33,9 +33,8 @@ impl MetadataV2 {
self,
src: impl AsRef<Path>,
dst: impl AsRef<Path>,
// TODO: use these variable to test if loading the index is possible.
_index_db_size: u64,
_update_db_size: u64,
index_db_size: usize,
update_db_size: usize,
indexing_options: &IndexerOpts,
) -> anyhow::Result<()> {
info!(
Expand All @@ -47,14 +46,14 @@ impl MetadataV2 {
HeedUuidStore::load_dump(src.as_ref(), &dst)?;

info!("Loading updates.");
UpdateStore::load_dump(&src, &dst, self.update_db_size)?;
UpdateStore::load_dump(&src, &dst, update_db_size)?;

info!("Loading indexes");
let indexes_path = src.as_ref().join("indexes");
let indexes = indexes_path.read_dir()?;
for index in indexes {
let index = index?;
Index::load_dump(&index.path(), &dst, self.index_db_size, indexing_options)?;
Index::load_dump(&index.path(), &dst, index_db_size, indexing_options)?;
}

Ok(())
Expand Down
10 changes: 5 additions & 5 deletions meilisearch-http/src/index_controller/dump_actor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum Metadata {
}

impl Metadata {
pub fn new_v2(index_db_size: u64, update_db_size: u64) -> Self {
pub fn new_v2(index_db_size: usize, update_db_size: usize) -> Self {
let meta = MetadataV2::new(index_db_size, update_db_size);
Self::V2(meta)
}
Expand Down Expand Up @@ -117,8 +117,8 @@ impl DumpInfo {
pub fn load_dump(
dst_path: impl AsRef<Path>,
src_path: impl AsRef<Path>,
index_db_size: u64,
update_db_size: u64,
index_db_size: usize,
update_db_size: usize,
indexer_opts: &IndexerOpts,
) -> anyhow::Result<()> {
let tmp_src = tempfile::tempdir_in(".")?;
Expand Down Expand Up @@ -166,8 +166,8 @@ struct DumpTask<U, P> {
uuid_resolver: U,
update_handle: P,
uid: String,
update_db_size: u64,
index_db_size: u64,
update_db_size: usize,
index_db_size: usize,
}

impl<U, P> DumpTask<U, P>
Expand Down
8 changes: 4 additions & 4 deletions meilisearch-http/src/index_controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ impl IndexController {
load_dump(
&options.db_path,
src_path,
options.max_mdb_size.get_bytes(),
options.max_udb_size.get_bytes(),
options.max_mdb_size.get_bytes() as usize,
options.max_udb_size.get_bytes() as usize,
&options.indexer_options,
)?;
}
Expand All @@ -116,8 +116,8 @@ impl IndexController {
&options.dumps_dir,
uuid_resolver.clone(),
update_handle.clone(),
options.max_mdb_size.get_bytes(),
options.max_udb_size.get_bytes(),
options.max_mdb_size.get_bytes() as usize,
options.max_udb_size.get_bytes() as usize,
)?;

if options.schedule_snapshot {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl UpdateStore {
pub fn load_dump(
src: impl AsRef<Path>,
dst: impl AsRef<Path>,
db_size: u64,
db_size: usize,
) -> anyhow::Result<()> {
let dst_update_path = dst.as_ref().join("updates/");
create_dir_all(&dst_update_path)?;
Expand Down

0 comments on commit 7cf9d37

Please sign in to comment.