1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

sharding migration

This commit is contained in:
Robin Appelman 2024-10-14 15:24:21 +02:00
commit e314a3b05f
2 changed files with 153 additions and 1 deletions

View file

@ -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, SingleShard};
use crate::service::sharded::{Sharding, ShardingMigrate, ShardingMigrateUnset, SingleShard};
use crate::service::smb::Smb;
use bollard::models::ContainerState;
use bollard::Docker;
@ -188,6 +188,8 @@ pub enum Service {
Dav(Dav),
Sharding(Sharding),
SingleShard(SingleShard),
ShardingMigrate(ShardingMigrate),
ShardingMigrateUnset(ShardingMigrateUnset),
Sftp(Sftp),
Kaspersky(Kaspersky),
KasperskyIcap(KasperskyIcap),
@ -215,6 +217,14 @@ impl Service {
"sharding" => Some(vec![Service::Sharding(Sharding)]),
"single-shard" => Some(vec![Service::SingleShard(SingleShard)]),
"singleshard" => Some(vec![Service::SingleShard(SingleShard)]),
"sharded-migrate" => Some(vec![Service::ShardingMigrate(ShardingMigrate)]),
"sharding-migrate" => Some(vec![Service::ShardingMigrate(ShardingMigrate)]),
"sharded-migrate-unset" => {
Some(vec![Service::ShardingMigrateUnset(ShardingMigrateUnset)])
}
"sharding-migrate-unset" => {
Some(vec![Service::ShardingMigrateUnset(ShardingMigrateUnset)])
}
"dav" => Some(vec![Service::Dav(Dav)]),
"sftp" => Some(vec![Service::Sftp(Sftp)]),
"oc" => Some(vec![Service::Oc(Oc)]),

View file

@ -161,3 +161,145 @@ impl ServiceTrait for SingleShard {
Ok(hashmap! {String::from("dbsharding") => shard_config})
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ShardingMigrate;
#[async_trait::async_trait]
impl ServiceTrait for ShardingMigrate {
fn name(&self) -> &str {
"sharding-migrate"
}
async fn spawn(
&self,
docker: &Docker,
cloud_id: &str,
network: &str,
config: &HazeConfig,
options: &CloudOptions,
) -> Result<Vec<String>> {
Sharding::spawn(&Sharding, docker, cloud_id, network, config, options).await
}
async fn is_healthy(
&self,
docker: &Docker,
cloud_id: &str,
options: &CloudOptions,
) -> Result<bool> {
Sharding::is_healthy(&Sharding, docker, cloud_id, options).await
}
fn config(
&self,
_docker: &Docker,
_cloud_id: &str,
_config: &HazeConfig,
) -> Result<HashMap<String, Value>> {
let shard_config = json!({
"filecache": {
"from_shard_key": 99,
"from_primary_key": 9999,
"shards": [
{
"dbname": "haze",
"host": "db-1",
"user": "haze",
"password": "haze",
},
{
"dbname": "haze",
"host": "db-2",
"user": "haze",
"password": "haze",
},
{
"dbname": "haze",
"host": "db-3",
"user": "haze",
"password": "haze",
},
{
"dbname": "haze",
"host": "db-4",
"user": "haze",
"password": "haze",
}
],
}
});
Ok(hashmap! {String::from("dbsharding") => shard_config})
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ShardingMigrateUnset;
#[async_trait::async_trait]
impl ServiceTrait for ShardingMigrateUnset {
fn name(&self) -> &str {
"sharding-migrate-unset"
}
async fn spawn(
&self,
docker: &Docker,
cloud_id: &str,
network: &str,
config: &HazeConfig,
options: &CloudOptions,
) -> Result<Vec<String>> {
Sharding::spawn(&Sharding, docker, cloud_id, network, config, options).await
}
async fn is_healthy(
&self,
docker: &Docker,
cloud_id: &str,
options: &CloudOptions,
) -> Result<bool> {
Sharding::is_healthy(&Sharding, docker, cloud_id, options).await
}
fn config(
&self,
_docker: &Docker,
_cloud_id: &str,
_config: &HazeConfig,
) -> Result<HashMap<String, Value>> {
let shard_config = json!({
"filecache": {
"from_shard_key": 99,
"from_primary_key": 9999,
"shards": [
{
"dbname": "haze",
"host": "db-1",
"user": "haze",
"password": "haze",
},
{
"dbname": "haze",
"host": "db-2",
"user": "haze",
"password": "haze",
},
{
"dbname": "haze",
"host": "db-3",
"user": "haze",
"password": "haze",
},
{
"dbname": "haze",
"host": "db-4",
"user": "haze",
"password": "haze",
}
],
}
});
Ok(hashmap! {String::from("_dbsharding") => shard_config})
}
}