-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
181 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::content_manager::errors::StorageError; | ||
use async_trait::async_trait; | ||
use collection::collection::Collection; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
pub type Collections = HashMap<String, Arc<Collection>>; | ||
|
||
#[async_trait] | ||
pub trait Checker { | ||
async fn is_collection_exists(&self, collection_name: &str) -> bool; | ||
|
||
async fn validate_collection_not_exists( | ||
&self, | ||
collection_name: &str, | ||
) -> Result<(), StorageError> { | ||
if self.is_collection_exists(collection_name).await { | ||
return Err(StorageError::BadInput { | ||
description: format!("Collection `{}` already exists!", collection_name), | ||
}); | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn validate_collection_exists(&self, collection_name: &str) -> Result<(), StorageError> { | ||
if !self.is_collection_exists(collection_name).await { | ||
return Err(StorageError::NotFound { | ||
description: format!("Collection `{}` doesn't exist!", collection_name), | ||
}); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Checker for Collections { | ||
async fn is_collection_exists(&self, collection_name: &str) -> bool { | ||
self.contains_key(collection_name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod collections_ops; | ||
pub mod errors; | ||
pub mod storage_ops; | ||
pub mod toc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use collection::collection_builder::optimizers_builder::OptimizersConfig; | ||
use storage::content_manager::toc::TableOfContent; | ||
use storage::types::{PerformanceConfig, StorageConfig}; | ||
use tempdir::TempDir; | ||
use tokio::runtime::Runtime; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use segment::types::Distance; | ||
use storage::content_manager::storage_ops::{AliasOperations, StorageOperations}; | ||
|
||
#[test] | ||
fn test_alias_operation() { | ||
let storage_dir = TempDir::new("storage").unwrap(); | ||
|
||
let config = StorageConfig { | ||
storage_path: storage_dir.path().to_str().unwrap().to_string(), | ||
optimizers: OptimizersConfig { | ||
deleted_threshold: 0.5, | ||
vacuum_min_vector_number: 100, | ||
max_segment_number: 2, | ||
memmap_threshold: 100, | ||
indexing_threshold: 100, | ||
payload_indexing_threshold: 100, | ||
flush_interval_sec: 2, | ||
}, | ||
wal: Default::default(), | ||
performance: PerformanceConfig { | ||
max_search_threads: 1, | ||
}, | ||
hnsw_index: Default::default(), | ||
}; | ||
|
||
let runtime = Runtime::new().unwrap(); | ||
let handle = runtime.handle().clone(); | ||
|
||
let toc = TableOfContent::new(&config, runtime); | ||
|
||
handle | ||
.block_on( | ||
toc.perform_collection_operation(StorageOperations::CreateCollection { | ||
name: "test".to_string(), | ||
vector_size: 10, | ||
distance: Distance::Cosine, | ||
hnsw_config: None, | ||
wal_config: None, | ||
optimizers_config: None, | ||
}), | ||
) | ||
.unwrap(); | ||
|
||
handle | ||
.block_on( | ||
toc.perform_collection_operation(StorageOperations::ChangeAliases { | ||
actions: vec![AliasOperations::CreateAlias { | ||
collection_name: "test".to_string(), | ||
alias_name: "test_alias".to_string(), | ||
}], | ||
}), | ||
) | ||
.unwrap(); | ||
|
||
handle | ||
.block_on( | ||
toc.perform_collection_operation(StorageOperations::ChangeAliases { | ||
actions: vec![ | ||
AliasOperations::CreateAlias { | ||
collection_name: "test".to_string(), | ||
alias_name: "test_alias2".to_string(), | ||
}, | ||
AliasOperations::DeleteAlias { | ||
alias_name: "test_alias".to_string(), | ||
}, | ||
AliasOperations::RenameAlias { | ||
old_alias_name: "test_alias2".to_string(), | ||
new_alias_name: "test_alias3".to_string(), | ||
}, | ||
], | ||
}), | ||
) | ||
.unwrap(); | ||
|
||
handle.block_on(toc.get_collection(&"test_alias3")).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters