ElasticSearch backend implementation
This commit is contained in:
@@ -5,13 +5,15 @@ edition = "2021"
|
||||
resolver = "2"
|
||||
|
||||
[features]
|
||||
default = ["sqlite", "foundationdb", "postgres", "mysql", "rocks"]
|
||||
#default = []
|
||||
#default = ["sqlite", "foundationdb", "postgres", "mysql", "rocks", "elastic", "s3"]
|
||||
default = ["rocks", "elastic"]
|
||||
sqlite = ["store/sqlite"]
|
||||
foundationdb = ["store/foundation"]
|
||||
postgres = ["store/postgres"]
|
||||
mysql = ["store/mysql"]
|
||||
rocks = ["store/rocks"]
|
||||
elastic = ["store/elastic"]
|
||||
s3 = ["store/s3"]
|
||||
|
||||
[dev-dependencies]
|
||||
store = { path = "../crates/store", features = ["test_mode"] }
|
||||
|
||||
@@ -147,6 +147,12 @@ database = "stalwart"
|
||||
user = "root"
|
||||
password = "password"
|
||||
|
||||
[store.fts]
|
||||
url = "https://localhost:9200"
|
||||
user = "elastic"
|
||||
password = "RtQ-Lu6+o4rxx=XJplVJ"
|
||||
allow-invalid-certs = true
|
||||
|
||||
[store.blob]
|
||||
type = "local"
|
||||
|
||||
|
||||
@@ -145,6 +145,12 @@ database = "stalwart"
|
||||
user = "root"
|
||||
password = "password"
|
||||
|
||||
[store.fts]
|
||||
url = "https://localhost:9200"
|
||||
user = "elastic"
|
||||
password = "RtQ-Lu6+o4rxx=XJplVJ"
|
||||
allow-invalid-certs = true
|
||||
|
||||
[store.blob]
|
||||
type = "local"
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ use std::io::Read;
|
||||
|
||||
use ::store::Store;
|
||||
|
||||
use store::backend::{rocksdb::RocksDbStore, sqlite::SqliteStore};
|
||||
use store::backend::{elastic::ElasticSearchStore, rocksdb::RocksDbStore};
|
||||
use utils::config::Config;
|
||||
|
||||
pub struct TempDir {
|
||||
@@ -52,25 +52,33 @@ database = "stalwart"
|
||||
user = "root"
|
||||
password = "password"
|
||||
|
||||
[store.fts]
|
||||
url = "https://localhost:9200"
|
||||
user = "elastic"
|
||||
password = "RtQ-Lu6+o4rxx=XJplVJ"
|
||||
allow-invalid-certs = true
|
||||
|
||||
"#;
|
||||
|
||||
#[tokio::test]
|
||||
pub async fn store_tests() {
|
||||
let insert = true;
|
||||
//let insert = true;
|
||||
let insert = false;
|
||||
let temp_dir = TempDir::new("store_tests", insert);
|
||||
let config_file = CONFIG.replace("{TMP}", &temp_dir.path.to_string_lossy());
|
||||
let db: Store = SqliteStore::open(&Config::new(&config_file).unwrap())
|
||||
//let db: Store = FdbStore::open(&Config::new(&config_file).unwrap())
|
||||
//let db: Store = PostgresStore::open(&Config::new(&config_file).unwrap())
|
||||
//let db: Store = MysqlStore::open(&Config::new(&config_file).unwrap())
|
||||
//let db: Store = RocksDbStore::open(&Config::new(&config_file).unwrap())
|
||||
.await
|
||||
.unwrap()
|
||||
.into();
|
||||
let config = Config::new(&config_file).unwrap();
|
||||
//let db: Store = SqliteStore::open(&Config::new(&config_file).unwrap())
|
||||
//let db: Store = FdbStore::open(&Config::new(&config_file).unwrap())
|
||||
//let db: Store = PostgresStore::open(&Config::new(&config_file).unwrap())
|
||||
//let db: Store = MysqlStore::open(&Config::new(&config_file).unwrap())
|
||||
let db: Store = RocksDbStore::open(&config).await.unwrap().into();
|
||||
//let fts_store = FtsStore::from(db.clone());
|
||||
let fts_store = ElasticSearchStore::open(&config).await.unwrap().into();
|
||||
|
||||
if insert {
|
||||
db.destroy().await;
|
||||
}
|
||||
query::test(db.clone(), insert).await;
|
||||
query::test(db.clone(), fts_store, insert).await;
|
||||
assign_id::test(db).await;
|
||||
if insert {
|
||||
temp_dir.delete();
|
||||
|
||||
@@ -110,7 +110,7 @@ impl From<FieldId> for u8 {
|
||||
}
|
||||
impl Display for FieldId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} ({})", FIELDS[self.0 as usize], self.0)
|
||||
write!(f, "{}", FIELDS[self.0 as usize])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,9 +125,8 @@ impl FieldId {
|
||||
}
|
||||
|
||||
#[allow(clippy::mutex_atomic)]
|
||||
pub async fn test(db: Store, do_insert: bool) {
|
||||
pub async fn test(db: Store, fts_store: FtsStore, do_insert: bool) {
|
||||
println!("Running Store query tests...");
|
||||
let fts_store = FtsStore::from(db.clone());
|
||||
|
||||
let pool = rayon::ThreadPoolBuilder::new()
|
||||
.num_threads(8)
|
||||
|
||||
Reference in New Issue
Block a user