From 4041d9dc481b78adce546b0a68d57e0a3c8e4121 Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 24 Mar 2021 11:29:11 +0100 Subject: [PATCH] format code --- meilisearch-http/src/helpers/compression.rs | 2 +- .../src/index_controller/index_actor/actor.rs | 4 ++-- .../index_controller/index_actor/handle_impl.rs | 12 +++++------- .../src/index_controller/index_actor/message.rs | 7 ++----- .../src/index_controller/index_actor/mod.rs | 10 ++-------- .../src/index_controller/index_actor/store.rs | 10 +++++----- meilisearch-http/src/index_controller/mod.rs | 4 +++- .../src/index_controller/snapshot.rs | 11 ++++------- .../src/index_controller/update_actor/actor.rs | 8 ++++---- .../src/index_controller/update_actor/message.rs | 4 ++-- .../src/index_controller/update_actor/mod.rs | 8 ++++---- .../update_actor/update_store.rs | 16 +++++++++++----- .../src/index_controller/uuid_resolver/actor.rs | 3 +-- .../uuid_resolver/handle_impl.rs | 4 ++-- .../src/index_controller/uuid_resolver/store.rs | 4 ++-- meilisearch-http/src/routes/stats.rs | 2 +- meilisearch-http/tests/common/server.rs | 10 ++++++++-- meilisearch-http/tests/stats/mod.rs | 2 +- 18 files changed, 60 insertions(+), 61 deletions(-) diff --git a/meilisearch-http/src/helpers/compression.rs b/meilisearch-http/src/helpers/compression.rs index 201f35149..c4747cb21 100644 --- a/meilisearch-http/src/helpers/compression.rs +++ b/meilisearch-http/src/helpers/compression.rs @@ -2,7 +2,7 @@ use std::fs::{create_dir_all, File}; use std::io::Write; use std::path::Path; -use flate2::{Compression, write::GzEncoder, read::GzDecoder}; +use flate2::{read::GzDecoder, write::GzEncoder, Compression}; use tar::{Archive, Builder}; pub fn to_tar_gz(src: impl AsRef, dest: impl AsRef) -> anyhow::Result<()> { diff --git a/meilisearch-http/src/index_controller/index_actor/actor.rs b/meilisearch-http/src/index_controller/index_actor/actor.rs index 89831b53a..812cf8408 100644 --- a/meilisearch-http/src/index_controller/index_actor/actor.rs +++ b/meilisearch-http/src/index_controller/index_actor/actor.rs @@ -12,11 +12,11 @@ use tokio::sync::mpsc; use tokio::task::spawn_blocking; use uuid::Uuid; +use super::{IndexError, IndexMeta, IndexMsg, IndexSettings, IndexStore, Result, UpdateResult}; use crate::index::{Document, SearchQuery, SearchResult, Settings}; use crate::index_controller::update_handler::UpdateHandler; -use crate::index_controller::{updates::Processing, UpdateMeta, get_arc_ownership_blocking}; +use crate::index_controller::{get_arc_ownership_blocking, updates::Processing, UpdateMeta}; use crate::option::IndexerOpts; -use super::{IndexSettings, Result, IndexMsg, IndexStore, IndexError, UpdateResult, IndexMeta}; pub struct IndexActor { read_receiver: Option>, diff --git a/meilisearch-http/src/index_controller/index_actor/handle_impl.rs b/meilisearch-http/src/index_controller/index_actor/handle_impl.rs index 9c43bd6e7..dba0f9e60 100644 --- a/meilisearch-http/src/index_controller/index_actor/handle_impl.rs +++ b/meilisearch-http/src/index_controller/index_actor/handle_impl.rs @@ -1,12 +1,14 @@ -use std::path::{PathBuf, Path}; +use std::path::{Path, PathBuf}; use tokio::sync::{mpsc, oneshot}; use uuid::Uuid; +use super::{ + IndexActor, IndexActorHandle, IndexMeta, IndexMsg, MapIndexStore, Result, UpdateResult, +}; use crate::index::{Document, SearchQuery, SearchResult, Settings}; use crate::index_controller::IndexSettings; use crate::index_controller::{updates::Processing, UpdateMeta}; -use super::{IndexActorHandle, IndexMsg, IndexMeta, UpdateResult, Result, IndexActor, MapIndexStore}; #[derive(Clone)] pub struct IndexActorHandleImpl { @@ -102,11 +104,7 @@ impl IndexActorHandle for IndexActorHandleImpl { Ok(receiver.await.expect("IndexActor has been killed")?) } - async fn update_index( - &self, - uuid: Uuid, - index_settings: IndexSettings, - ) -> Result { + async fn update_index(&self, uuid: Uuid, index_settings: IndexSettings) -> Result { let (ret, receiver) = oneshot::channel(); let msg = IndexMsg::UpdateIndex { uuid, diff --git a/meilisearch-http/src/index_controller/index_actor/message.rs b/meilisearch-http/src/index_controller/index_actor/message.rs index 66edb5b77..46d7f6214 100644 --- a/meilisearch-http/src/index_controller/index_actor/message.rs +++ b/meilisearch-http/src/index_controller/index_actor/message.rs @@ -3,12 +3,9 @@ use std::path::PathBuf; use tokio::sync::oneshot; use uuid::Uuid; +use super::{IndexMeta, IndexSettings, Result, UpdateResult}; use crate::index::{Document, SearchQuery, SearchResult, Settings}; -use crate::index_controller::{ - updates::Processing, - UpdateMeta, -}; -use super::{IndexSettings, IndexMeta, UpdateResult, Result}; +use crate::index_controller::{updates::Processing, UpdateMeta}; pub enum IndexMsg { CreateIndex { diff --git a/meilisearch-http/src/index_controller/index_actor/mod.rs b/meilisearch-http/src/index_controller/index_actor/mod.rs index e3e48add7..2dc856b80 100644 --- a/meilisearch-http/src/index_controller/index_actor/mod.rs +++ b/meilisearch-http/src/index_controller/index_actor/mod.rs @@ -17,9 +17,9 @@ use crate::index_controller::{ updates::{Failed, Processed, Processing}, UpdateMeta, }; +use actor::IndexActor; use message::IndexMsg; use store::{IndexStore, MapIndexStore}; -use actor::IndexActor; pub use handle_impl::IndexActorHandleImpl; @@ -69,7 +69,6 @@ pub enum IndexError { ExistingPrimaryKey, } - #[async_trait::async_trait] #[cfg_attr(test, automock)] pub trait IndexActorHandle { @@ -97,11 +96,6 @@ pub trait IndexActorHandle { ) -> Result; async fn delete(&self, uuid: Uuid) -> Result<()>; async fn get_index_meta(&self, uuid: Uuid) -> Result; - async fn update_index( - &self, - uuid: Uuid, - index_settings: IndexSettings, - ) -> Result; + async fn update_index(&self, uuid: Uuid, index_settings: IndexSettings) -> Result; async fn snapshot(&self, uuid: Uuid, path: PathBuf) -> Result<()>; } - diff --git a/meilisearch-http/src/index_controller/index_actor/store.rs b/meilisearch-http/src/index_controller/index_actor/store.rs index a9f3cd479..6250f515e 100644 --- a/meilisearch-http/src/index_controller/index_actor/store.rs +++ b/meilisearch-http/src/index_controller/index_actor/store.rs @@ -1,12 +1,12 @@ -use std::path::{PathBuf, Path}; -use std::sync::Arc; use std::collections::HashMap; +use std::path::{Path, PathBuf}; +use std::sync::Arc; -use uuid::Uuid; +use heed::EnvOpenOptions; +use tokio::fs; use tokio::sync::RwLock; use tokio::task::spawn_blocking; -use tokio::fs; -use heed::EnvOpenOptions; +use uuid::Uuid; use super::{IndexError, Result}; use crate::index::Index; diff --git a/meilisearch-http/src/index_controller/mod.rs b/meilisearch-http/src/index_controller/mod.rs index 77ad957f8..3efb31f82 100644 --- a/meilisearch-http/src/index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/mod.rs @@ -12,6 +12,7 @@ use std::time::Duration; use actix_web::web::{Bytes, Payload}; use anyhow::bail; use futures::stream::StreamExt; +use log::info; use milli::update::{IndexDocumentsMethod, UpdateFormat}; use serde::{Deserialize, Serialize}; use tokio::sync::mpsc; @@ -22,9 +23,9 @@ use crate::index::{Facets, Settings, UpdateResult}; use crate::option::Opt; use index_actor::IndexActorHandle; +use snapshot::load_snapshot; use update_actor::UpdateActorHandle; use uuid_resolver::UuidResolverHandle; -use snapshot::load_snapshot; use snapshot::SnapshotService; pub use updates::{Failed, Processed, Processing}; @@ -72,6 +73,7 @@ impl IndexController { let update_store_size = options.max_udb_size.get_bytes() as usize; if let Some(ref path) = options.import_snapshot { + info!("Loading from snapshot {:?}", path); load_snapshot( &options.db_path, path, diff --git a/meilisearch-http/src/index_controller/snapshot.rs b/meilisearch-http/src/index_controller/snapshot.rs index 98fabcca7..5ff0b9d6f 100644 --- a/meilisearch-http/src/index_controller/snapshot.rs +++ b/meilisearch-http/src/index_controller/snapshot.rs @@ -39,7 +39,10 @@ where } pub async fn run(self) { - info!("Snashot scheduled every {}s.", self.snapshot_period.as_secs()); + info!( + "Snashot scheduled every {}s.", + self.snapshot_period.as_secs() + ); loop { sleep(self.snapshot_period).await; if let Err(e) = self.perform_snapshot().await { @@ -49,17 +52,11 @@ where } async fn perform_snapshot(&self) -> anyhow::Result<()> { - if !self.snapshot_path.is_file() { - bail!("Invalid snapshot file path."); - } - info!("Performing snapshot."); let temp_snapshot_dir = spawn_blocking(move || tempfile::tempdir_in(".")).await??; let temp_snapshot_path = temp_snapshot_dir.path().to_owned(); - fs::create_dir_all(&temp_snapshot_path).await?; - let uuids = self .uuid_resolver_handle .snapshot(temp_snapshot_path.clone()) diff --git a/meilisearch-http/src/index_controller/update_actor/actor.rs b/meilisearch-http/src/index_controller/update_actor/actor.rs index df949279e..688472740 100644 --- a/meilisearch-http/src/index_controller/update_actor/actor.rs +++ b/meilisearch-http/src/index_controller/update_actor/actor.rs @@ -2,15 +2,15 @@ use std::io::SeekFrom; use std::path::{Path, PathBuf}; use log::info; -use tokio::sync::mpsc; -use uuid::Uuid; use oxidized_json_checker::JsonChecker; use tokio::fs; use tokio::io::{AsyncSeekExt, AsyncWriteExt}; +use tokio::sync::mpsc; +use uuid::Uuid; -use super::{PayloadData, UpdateError, UpdateMsg, UpdateStoreStore, Result}; +use super::{PayloadData, Result, UpdateError, UpdateMsg, UpdateStoreStore}; use crate::index_controller::index_actor::IndexActorHandle; -use crate::index_controller::{UpdateMeta, UpdateStatus, get_arc_ownership_blocking}; +use crate::index_controller::{get_arc_ownership_blocking, UpdateMeta, UpdateStatus}; pub struct UpdateActor { path: PathBuf, diff --git a/meilisearch-http/src/index_controller/update_actor/message.rs b/meilisearch-http/src/index_controller/update_actor/message.rs index 628a1ebcb..8e6e3c212 100644 --- a/meilisearch-http/src/index_controller/update_actor/message.rs +++ b/meilisearch-http/src/index_controller/update_actor/message.rs @@ -1,9 +1,9 @@ use std::path::PathBuf; +use tokio::sync::{mpsc, oneshot}; use uuid::Uuid; -use tokio::sync::{oneshot, mpsc}; -use super::{Result, PayloadData, UpdateStatus, UpdateMeta}; +use super::{PayloadData, Result, UpdateMeta, UpdateStatus}; pub enum UpdateMsg { Update { diff --git a/meilisearch-http/src/index_controller/update_actor/mod.rs b/meilisearch-http/src/index_controller/update_actor/mod.rs index 1fb53a2b3..f3c3caf04 100644 --- a/meilisearch-http/src/index_controller/update_actor/mod.rs +++ b/meilisearch-http/src/index_controller/update_actor/mod.rs @@ -1,7 +1,7 @@ mod actor; -mod store; -mod message; mod handle_impl; +mod message; +mod store; mod update_store; use std::path::PathBuf; @@ -15,7 +15,7 @@ use crate::index_controller::{UpdateMeta, UpdateStatus}; use actor::UpdateActor; use message::UpdateMsg; -use store::{UpdateStoreStore, MapUpdateStoreStore}; +use store::{MapUpdateStoreStore, UpdateStoreStore}; pub use handle_impl::UpdateActorHandleImpl; @@ -51,5 +51,5 @@ pub trait UpdateActorHandle { meta: UpdateMeta, data: mpsc::Receiver>, uuid: Uuid, - ) -> Result ; + ) -> Result; } diff --git a/meilisearch-http/src/index_controller/update_actor/update_store.rs b/meilisearch-http/src/index_controller/update_actor/update_store.rs index 63806260b..f8dcace7b 100644 --- a/meilisearch-http/src/index_controller/update_actor/update_store.rs +++ b/meilisearch-http/src/index_controller/update_actor/update_store.rs @@ -1,10 +1,10 @@ -use std::fs::{remove_file, create_dir_all, copy}; +use std::fs::{copy, create_dir_all, remove_file}; use std::path::{Path, PathBuf}; use std::sync::Arc; use heed::types::{DecodeIgnore, OwnedType, SerdeJson}; -use heed::{Database, Env, EnvOpenOptions, CompactionOption}; -use parking_lot::{RwLock, Mutex}; +use heed::{CompactionOption, Database, Env, EnvOpenOptions}; +use parking_lot::{Mutex, RwLock}; use serde::{Deserialize, Serialize}; use std::fs::File; use tokio::sync::mpsc; @@ -379,7 +379,12 @@ where Ok(aborted_updates) } - pub fn snapshot(&self, txn: &mut heed::RwTxn, path: impl AsRef, uuid: Uuid) -> anyhow::Result<()> { + pub fn snapshot( + &self, + txn: &mut heed::RwTxn, + path: impl AsRef, + uuid: Uuid, + ) -> anyhow::Result<()> { let update_path = path.as_ref().join("updates"); create_dir_all(&update_path)?; @@ -389,7 +394,8 @@ where snapshot_path.push("data.mdb"); // create db snapshot - self.env.copy_to_path(&snapshot_path, CompactionOption::Enabled)?; + self.env + .copy_to_path(&snapshot_path, CompactionOption::Enabled)?; let update_files_path = update_path.join("update_files"); create_dir_all(&update_files_path)?; diff --git a/meilisearch-http/src/index_controller/uuid_resolver/actor.rs b/meilisearch-http/src/index_controller/uuid_resolver/actor.rs index 4c0a13ad7..e1abe4ddb 100644 --- a/meilisearch-http/src/index_controller/uuid_resolver/actor.rs +++ b/meilisearch-http/src/index_controller/uuid_resolver/actor.rs @@ -4,7 +4,7 @@ use log::{info, warn}; use tokio::sync::mpsc; use uuid::Uuid; -use super::{UuidResolveMsg, UuidStore, Result, UuidError}; +use super::{Result, UuidError, UuidResolveMsg, UuidStore}; pub struct UuidResolverActor { inbox: mpsc::Receiver, @@ -91,4 +91,3 @@ fn is_index_uid_valid(uid: &str) -> bool { uid.chars() .all(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_') } - diff --git a/meilisearch-http/src/index_controller/uuid_resolver/handle_impl.rs b/meilisearch-http/src/index_controller/uuid_resolver/handle_impl.rs index 265ea8422..e7a4eb927 100644 --- a/meilisearch-http/src/index_controller/uuid_resolver/handle_impl.rs +++ b/meilisearch-http/src/index_controller/uuid_resolver/handle_impl.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use tokio::sync::{mpsc, oneshot}; use uuid::Uuid; -use super::{HeedUuidStore, UuidResolverActor, UuidResolveMsg, UuidResolverHandle, Result}; +use super::{HeedUuidStore, Result, UuidResolveMsg, UuidResolverActor, UuidResolverHandle}; #[derive(Clone)] pub struct UuidResolverHandleImpl { @@ -21,7 +21,7 @@ impl UuidResolverHandleImpl { } #[async_trait::async_trait] -impl UuidResolverHandle for UuidResolverHandleImpl { +impl UuidResolverHandle for UuidResolverHandleImpl { async fn resolve(&self, name: String) -> anyhow::Result { let (ret, receiver) = oneshot::channel(); let msg = UuidResolveMsg::Resolve { uid: name, ret }; diff --git a/meilisearch-http/src/index_controller/uuid_resolver/store.rs b/meilisearch-http/src/index_controller/uuid_resolver/store.rs index e821f2b2b..710d48e5d 100644 --- a/meilisearch-http/src/index_controller/uuid_resolver/store.rs +++ b/meilisearch-http/src/index_controller/uuid_resolver/store.rs @@ -3,11 +3,11 @@ use std::path::{Path, PathBuf}; use heed::{ types::{ByteSlice, Str}, - Database, Env, EnvOpenOptions,CompactionOption + CompactionOption, Database, Env, EnvOpenOptions, }; use uuid::Uuid; -use super::{UUID_STORE_SIZE, UuidError, Result}; +use super::{Result, UuidError, UUID_STORE_SIZE}; #[async_trait::async_trait] pub trait UuidStore { diff --git a/meilisearch-http/src/routes/stats.rs b/meilisearch-http/src/routes/stats.rs index 172b5dde9..ed951149c 100644 --- a/meilisearch-http/src/routes/stats.rs +++ b/meilisearch-http/src/routes/stats.rs @@ -56,7 +56,7 @@ struct VersionResponse { #[get("/version", wrap = "Authentication::Private")] async fn get_version() -> HttpResponse { - HttpResponse::Ok().json(VersionResponse { + HttpResponse::Ok().json(VersionResponse { commit_sha: env!("VERGEN_SHA").to_string(), build_date: env!("VERGEN_BUILD_TIMESTAMP").to_string(), pkg_version: env!("CARGO_PKG_VERSION").to_string(), diff --git a/meilisearch-http/tests/common/server.rs b/meilisearch-http/tests/common/server.rs index da490250b..4655b10a8 100644 --- a/meilisearch-http/tests/common/server.rs +++ b/meilisearch-http/tests/common/server.rs @@ -27,14 +27,20 @@ impl Server { let data = Data::new(opt).unwrap(); let service = Service(data); - Server { service, _dir: Some(dir) } + Server { + service, + _dir: Some(dir), + } } pub async fn new_with_options(opt: Opt) -> Self { let data = Data::new(opt).unwrap(); let service = Service(data); - Server { service, _dir: None } + Server { + service, + _dir: None, + } } /// Returns a view to an index. There is no guarantee that the index exists. diff --git a/meilisearch-http/tests/stats/mod.rs b/meilisearch-http/tests/stats/mod.rs index 5e3c9db45..db04fb1c0 100644 --- a/meilisearch-http/tests/stats/mod.rs +++ b/meilisearch-http/tests/stats/mod.rs @@ -18,4 +18,4 @@ async fn test_healthyness() { let (response, status_code) = server.service.get("/health").await; assert_eq!(status_code, 200); assert_eq!(response["status"], "available"); - } +}