mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
allow configuring a single shard
This commit is contained in:
parent
fdbc6f2e46
commit
1effe0bf99
2 changed files with 68 additions and 1 deletions
|
|
@ -28,7 +28,7 @@ pub use crate::service::office::Office;
|
|||
pub use crate::service::onlyoffice::OnlyOffice;
|
||||
pub use crate::service::push::NotifyPush;
|
||||
use crate::service::sftp::Sftp;
|
||||
use crate::service::sharded::Sharding;
|
||||
use crate::service::sharded::{Sharding, SingleShard};
|
||||
use crate::service::smb::Smb;
|
||||
use bollard::models::ContainerState;
|
||||
use bollard::Docker;
|
||||
|
|
@ -187,6 +187,7 @@ pub enum Service {
|
|||
Smb(Smb),
|
||||
Dav(Dav),
|
||||
Sharding(Sharding),
|
||||
SingleShard(SingleShard),
|
||||
Sftp(Sftp),
|
||||
Kaspersky(Kaspersky),
|
||||
KasperskyIcap(KasperskyIcap),
|
||||
|
|
@ -212,6 +213,8 @@ impl Service {
|
|||
"smb" => Some(vec![Service::Smb(Smb)]),
|
||||
"sharded" => Some(vec![Service::Sharding(Sharding)]),
|
||||
"sharding" => Some(vec![Service::Sharding(Sharding)]),
|
||||
"single-shard" => Some(vec![Service::SingleShard(SingleShard)]),
|
||||
"singleshard" => Some(vec![Service::SingleShard(SingleShard)]),
|
||||
"dav" => Some(vec![Service::Dav(Dav)]),
|
||||
"sftp" => Some(vec![Service::Sftp(Sftp)]),
|
||||
"oc" => Some(vec![Service::Oc(Oc)]),
|
||||
|
|
|
|||
|
|
@ -105,3 +105,67 @@ impl ServiceTrait for Sharding {
|
|||
Ok(hashmap! {String::from("dbsharding") => shard_config})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct SingleShard;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceTrait for SingleShard {
|
||||
fn name(&self) -> &str {
|
||||
"single-shard"
|
||||
}
|
||||
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
options: &CloudOptions,
|
||||
) -> Result<Vec<String>> {
|
||||
if options.db.family() == DatabaseFamily::Sqlite {
|
||||
return Err(Report::msg("Sharding is not supported with sqlite"));
|
||||
}
|
||||
|
||||
let container = options
|
||||
.db
|
||||
.spawn(docker, cloud_id, network, "-shard")
|
||||
.await?;
|
||||
|
||||
Ok(container.into_iter().collect())
|
||||
}
|
||||
|
||||
async fn is_healthy(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
options: &CloudOptions,
|
||||
) -> Result<bool> {
|
||||
options.db.is_healthy(docker, cloud_id, "-shard").await
|
||||
}
|
||||
|
||||
fn config(
|
||||
&self,
|
||||
_docker: &Docker,
|
||||
_cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<HashMap<String, Value>> {
|
||||
let shard_config = json!({
|
||||
"filecache": {
|
||||
"table": "filecache",
|
||||
"primary_key": "fileid",
|
||||
"shard_key": "storage",
|
||||
"companion_tables": ["filecache_extended", "files_metadata"],
|
||||
"shards": [
|
||||
{
|
||||
"dbname": "haze",
|
||||
"host": "db-shard",
|
||||
"user": "haze",
|
||||
"password": "haze",
|
||||
}
|
||||
],
|
||||
}
|
||||
});
|
||||
Ok(hashmap! {String::from("dbsharding") => shard_config})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue