Skip to content

Commit

Permalink
Add import formatting rules (#820)
Browse files Browse the repository at this point in the history
* Add import formatting rules

* Review fix: update rusty hook
  • Loading branch information
e-ivkov committed Jul 15, 2022
1 parent 2e1d6c1 commit 026bd04
Show file tree
Hide file tree
Showing 156 changed files with 900 additions and 751 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/rust-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Install miniml nightly (only for fmt)
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt
- name: Install minimal stable
uses: actions-rs/toolchain@v1
with:
Expand All @@ -32,6 +38,6 @@ jobs:
run: .github/scripts/protoc.sh
shell: bash
- name: Check code formatting
run: cargo fmt --all -- --check
run: cargo +nightly fmt --all -- --check
- name: Check cargo clippy warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
2 changes: 1 addition & 1 deletion .rusty-hook.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[hooks]
pre-push = "cargo fmt --all -- --check"
pre-push = "cargo +nightly fmt --all -- --check"

[logging]
verbose = true
17 changes: 9 additions & 8 deletions lib/api/src/grpc/conversions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
use std::collections::{HashMap, HashSet};
use std::time::Instant;

use chrono::{NaiveDateTime, Timelike};
use segment::types::{PayloadSelector, WithPayloadInterface};
use tonic::Status;
use uuid::Uuid;

use crate::grpc::models::{CollectionsResponse, VersionInfo};
use crate::grpc::qdrant::condition::ConditionOneOf;
use crate::grpc::qdrant::point_id::PointIdOptions;
use crate::grpc::qdrant::r#match::MatchValue;
use crate::grpc::qdrant::value::Kind;
use crate::grpc::qdrant::with_payload_selector::SelectorOptions;
use crate::grpc::qdrant::{
CollectionDescription, CollectionOperationResponse, Condition, FieldCondition, Filter,
Expand All @@ -11,14 +20,6 @@ use crate::grpc::qdrant::{
SearchParams, Struct, Value, ValuesCount, WithPayloadSelector,
};

use crate::grpc::qdrant::value::Kind;
use chrono::{NaiveDateTime, Timelike};
use segment::types::{PayloadSelector, WithPayloadInterface};
use std::collections::{HashMap, HashSet};
use std::time::Instant;
use tonic::Status;
use uuid::Uuid;

pub fn payload_to_proto(payload: segment::types::Payload) -> HashMap<String, Value> {
payload
.into_iter()
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/grpc/models.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::fmt::Debug;

use schemars::JsonSchema;
use serde;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

#[derive(Serialize, Deserialize)]
pub struct VersionInfo {
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/grpc/transport_channel_pool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use rand::seq::SliceRandom;
use std::collections::HashMap;
use std::time::Duration;
use std::vec::Vec;

use rand::seq::SliceRandom;
use tonic::transport::{Channel, Error, Uri};

/// Holds a pool of channels established for a set of URIs.
Expand Down
40 changes: 21 additions & 19 deletions lib/collection/src/collection.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
use std::cmp::max;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;

use futures::future::{join_all, try_join_all};
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use itertools::Itertools;
use segment::common::version::StorageVersion;
use segment::spaces::tools::{peek_top_largest_scores_iterable, peek_top_smallest_scores_iterable};
use segment::types::{
Condition, ExtendedPointId, Filter, HasIdCondition, Order, ScoredPoint, VectorElementType,
WithPayload, WithPayloadInterface,
};
use semver::{Version, VersionReq};
use tar::Builder as TarBuilder;
use tokio::fs::{copy, create_dir_all, remove_dir_all, remove_file, rename};
use tokio::runtime::Handle;
use tokio::sync::RwLock;

use crate::collection_state::State;
use crate::config::CollectionConfig;
use crate::hash_ring::HashRing;
Expand All @@ -20,25 +41,6 @@ use crate::shard::{
ShardOperation, ShardTransfer, HASH_RING_SHARD_SCALE,
};
use crate::telemetry::CollectionTelemetry;
use futures::future::{join_all, try_join_all};
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use itertools::Itertools;
use segment::common::version::StorageVersion;
use segment::spaces::tools::{peek_top_largest_scores_iterable, peek_top_smallest_scores_iterable};
use segment::types::{
Condition, ExtendedPointId, Filter, HasIdCondition, Order, ScoredPoint, VectorElementType,
WithPayload, WithPayloadInterface,
};
use semver::{Version, VersionReq};
use std::cmp::max;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tar::Builder as TarBuilder;
use tokio::fs::{copy, create_dir_all, remove_dir_all, remove_file, rename};
use tokio::runtime::Handle;
use tokio::sync::RwLock;

struct CollectionVersion;

Expand Down
8 changes: 2 additions & 6 deletions lib/collection/src/collection_manager/collection_updater.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use parking_lot::RwLock;

use segment::types::SeqNumberType;

use crate::collection_manager::holders::segment_holder::SegmentHolder;

use crate::collection_manager::segments_updater::*;
use crate::operations::types::{CollectionError, CollectionResult};
use crate::operations::CollectionUpdateOperations;
Expand Down Expand Up @@ -72,15 +70,13 @@ impl CollectionUpdater {

#[cfg(test)]
mod tests {
use tempdir::TempDir;

use segment::types::{Payload, WithPayload};
use tempdir::TempDir;

use super::*;
use crate::collection_manager::fixtures::build_test_holder;
use crate::collection_manager::segments_searcher::SegmentsSearcher;
use crate::collection_manager::segments_updater::upsert_points;

use super::*;
use crate::operations::payload_ops::{DeletePayload, PayloadOps, SetPayload};
use crate::operations::point_ops::PointOperations;

Expand Down
3 changes: 1 addition & 2 deletions lib/collection/src/collection_manager/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use std::path::Path;

use parking_lot::RwLock;
use rand::Rng;
use serde_json::json;

use segment::entry::entry_point::SegmentEntry;
use segment::segment::Segment;
use segment::segment_constructor::simple_segment_constructor::build_simple_segment;
use segment::types::{Distance, Payload, PointIdType, SeqNumberType};
use serde_json::json;

use crate::collection_manager::holders::segment_holder::SegmentHolder;
use crate::collection_manager::optimizers::indexing_optimizer::IndexingOptimizer;
Expand Down
24 changes: 14 additions & 10 deletions lib/collection/src/collection_manager/holders/proxy_segment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use crate::collection_manager::holders::segment_holder::LockedSegment;
use std::cmp::max;
use std::collections::{HashMap, HashSet};
use std::fs::{create_dir_all, remove_dir_all};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

use parking_lot::{RwLock, RwLockUpgradableReadGuard};
use segment::entry::entry_point::{OperationResult, SegmentEntry, SegmentFailedState};
use segment::index::field_index::CardinalityEstimation;
Expand All @@ -8,14 +14,10 @@ use segment::types::{
ScoredPoint, SearchParams, SegmentConfig, SegmentInfo, SegmentType, SeqNumberType,
VectorElementType, WithPayload,
};
use std::cmp::max;
use std::collections::{HashMap, HashSet};
use std::fs::{create_dir_all, remove_dir_all};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use uuid::Uuid;

use crate::collection_manager::holders::segment_holder::LockedSegment;

type LockedRmSet = Arc<RwLock<HashSet<PointIdType>>>;
type LockedFieldsSet = Arc<RwLock<HashSet<PayloadKeyType>>>;
type LockedFieldsMap = Arc<RwLock<HashMap<PayloadKeyType, PayloadSchemaType>>>;
Expand Down Expand Up @@ -584,12 +586,14 @@ impl SegmentEntry for ProxySegment {

#[cfg(test)]
mod tests {
use super::*;
use crate::collection_manager::fixtures::{build_segment_1, build_segment_2, empty_segment};
use segment::types::FieldCondition;
use std::fs::read_dir;

use segment::types::FieldCondition;
use tempdir::TempDir;

use super::*;
use crate::collection_manager::fixtures::{build_segment_1, build_segment_2, empty_segment};

#[test]
fn test_writing() {
let dir = TempDir::new("segment_dir").unwrap();
Expand Down
18 changes: 8 additions & 10 deletions lib/collection/src/collection_manager/holders/segment_holder.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use std::cmp::{max, min};
use std::collections::{BTreeSet, HashMap, HashSet};
use std::ops::Mul;
use std::path::Path;
use std::sync::Arc;
use std::thread::sleep;
use std::time::Duration;

use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use rand::seq::SliceRandom;
use rand::{thread_rng, Rng};

use segment::entry::entry_point::{OperationError, OperationResult, SegmentEntry};
use segment::segment::Segment;
use segment::types::{PointIdType, SeqNumberType};

use crate::collection_manager::holders::proxy_segment::ProxySegment;
use crate::operations::types::CollectionError;
use std::ops::Mul;
use std::path::Path;
use std::thread::sleep;
use std::time::Duration;

pub type SegmentId = usize;

Expand Down Expand Up @@ -431,16 +430,15 @@ impl<'s> SegmentHolder {

#[cfg(test)]
mod tests {
use tempdir::TempDir;
use std::fs::read_dir;
use std::{thread, time};

use segment::segment_constructor::simple_segment_constructor::build_simple_segment;
use segment::types::Distance;

use crate::collection_manager::fixtures::{build_segment_1, build_segment_2};
use tempdir::TempDir;

use super::*;
use std::fs::read_dir;
use std::{thread, time};
use crate::collection_manager::fixtures::{build_segment_1, build_segment_2};

#[test]
fn test_add_and_swap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ mod tests {
use parking_lot::lock_api::RwLock;
use rand::thread_rng;
use segment::fixtures::index_fixtures::random_vector;
use segment::types::{Payload, PayloadSchemaType, StorageType};
use serde_json::json;
use tempdir::TempDir;

use segment::types::{Payload, PayloadSchemaType, StorageType};

use super::*;
use crate::collection_manager::fixtures::random_segment;
use crate::collection_manager::holders::segment_holder::SegmentHolder;
use crate::collection_manager::segments_updater::{
Expand All @@ -228,8 +228,6 @@ mod tests {
use crate::operations::point_ops::{Batch, PointInsertOperations, PointOperations};
use crate::operations::{CreateIndex, FieldIndexOperations};

use super::*;

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::collections::HashSet;
use std::path::{Path, PathBuf};

use itertools::Itertools;
use segment::types::{HnswConfig, SegmentType, VECTOR_ELEMENT_SIZE};

use crate::collection_manager::holders::segment_holder::{
LockedSegment, LockedSegmentHolder, SegmentId,
};
use crate::collection_manager::optimizers::segment_optimizer::{
OptimizerThresholds, SegmentOptimizer,
};
use crate::config::CollectionParams;
use itertools::Itertools;
use segment::types::{HnswConfig, SegmentType, VECTOR_ELEMENT_SIZE};
use std::collections::HashSet;
use std::path::{Path, PathBuf};

const BYTES_IN_KB: usize = 1024;

Expand Down Expand Up @@ -125,14 +127,16 @@ impl SegmentOptimizer for MergeOptimizer {

#[cfg(test)]
mod tests {
use super::*;
use crate::collection_manager::fixtures::{get_merge_optimizer, random_segment};
use crate::collection_manager::holders::segment_holder::{LockedSegment, SegmentHolder};
use parking_lot::RwLock;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;

use parking_lot::RwLock;
use tempdir::TempDir;

use super::*;
use crate::collection_manager::fixtures::{get_merge_optimizer, random_segment};
use crate::collection_manager::holders::segment_holder::{LockedSegment, SegmentHolder};

#[test]
fn test_max_merge_size() {
let dir = TempDir::new("segment_dir").unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::sync::Arc;

use itertools::Itertools;
use parking_lot::{RwLock, RwLockUpgradableReadGuard};

use segment::entry::entry_point::SegmentEntry;
use segment::segment::Segment;
use segment::segment_constructor::build_segment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::collections::HashSet;
use std::path::{Path, PathBuf};

use ordered_float::OrderedFloat;
use segment::types::{HnswConfig, SegmentType};

use crate::collection_manager::holders::segment_holder::{
LockedSegment, LockedSegmentHolder, SegmentId,
};
use crate::collection_manager::optimizers::segment_optimizer::{
OptimizerThresholds, SegmentOptimizer,
};
use crate::config::CollectionParams;
use ordered_float::OrderedFloat;
use segment::types::{HnswConfig, SegmentType};
use std::collections::HashSet;
use std::path::{Path, PathBuf};

/// Optimizer which looks for segments with hig amount of soft-deleted points.
/// Used to free up space.
Expand Down Expand Up @@ -113,20 +115,21 @@ impl SegmentOptimizer for VacuumOptimizer {

#[cfg(test)]
mod tests {
use super::*;
use crate::collection_manager::fixtures::random_segment;
use crate::collection_manager::holders::segment_holder::SegmentHolder;
use std::num::NonZeroU32;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;

use itertools::Itertools;
use parking_lot::RwLock;
use rand::Rng;
use segment::types::Distance;
use serde_json::json;
use serde_json::Value;
use std::num::NonZeroU32;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use serde_json::{json, Value};
use tempdir::TempDir;

use super::*;
use crate::collection_manager::fixtures::random_segment;
use crate::collection_manager::holders::segment_holder::SegmentHolder;

#[test]
fn test_vacuum_conditions() {
let temp_dir = TempDir::new("segment_temp_dir").unwrap();
Expand Down
Loading

0 comments on commit 026bd04

Please sign in to comment.