mirror of
https://codeberg.org/icewind/haze.git
synced 2026-08-02 12:14:46 +02:00
add basic partitioning support
This commit is contained in:
parent
37f467deff
commit
8f7c4e1078
2 changed files with 67 additions and 2 deletions
|
|
@ -8,10 +8,10 @@ mod objectstore;
|
||||||
mod oc;
|
mod oc;
|
||||||
mod office;
|
mod office;
|
||||||
mod onlyoffice;
|
mod onlyoffice;
|
||||||
|
mod partitioning;
|
||||||
mod push;
|
mod push;
|
||||||
mod sftp;
|
|
||||||
// mod sharding;
|
|
||||||
mod redis;
|
mod redis;
|
||||||
|
mod sftp;
|
||||||
mod sharded;
|
mod sharded;
|
||||||
mod smb;
|
mod smb;
|
||||||
mod webhook;
|
mod webhook;
|
||||||
|
|
@ -28,6 +28,7 @@ pub use crate::service::objectstore::ObjectStore;
|
||||||
use crate::service::oc::Oc;
|
use crate::service::oc::Oc;
|
||||||
pub use crate::service::office::Office;
|
pub use crate::service::office::Office;
|
||||||
pub use crate::service::onlyoffice::OnlyOffice;
|
pub use crate::service::onlyoffice::OnlyOffice;
|
||||||
|
use crate::service::partitioning::Partitioning;
|
||||||
pub use crate::service::push::NotifyPush;
|
pub use crate::service::push::NotifyPush;
|
||||||
use crate::service::redis::Redis;
|
use crate::service::redis::Redis;
|
||||||
use crate::service::sftp::{Sftp, SftpKey};
|
use crate::service::sftp::{Sftp, SftpKey};
|
||||||
|
|
@ -311,6 +312,8 @@ pub enum ServiceType {
|
||||||
FrankenPhp,
|
FrankenPhp,
|
||||||
/// Webhook test listener
|
/// Webhook test listener
|
||||||
Webhook,
|
Webhook,
|
||||||
|
/// Enable DB partitioning for mariadb
|
||||||
|
Partitioning,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
|
|
@ -328,6 +331,7 @@ pub enum Service {
|
||||||
SingleShard(SingleShard),
|
SingleShard(SingleShard),
|
||||||
ShardingMigrate(ShardingMigrate),
|
ShardingMigrate(ShardingMigrate),
|
||||||
ShardingMigrateUnset(ShardingMigrateUnset),
|
ShardingMigrateUnset(ShardingMigrateUnset),
|
||||||
|
Partitioning(Partitioning),
|
||||||
Sftp(Sftp),
|
Sftp(Sftp),
|
||||||
SftpKey(SftpKey),
|
SftpKey(SftpKey),
|
||||||
Kaspersky(Kaspersky),
|
Kaspersky(Kaspersky),
|
||||||
|
|
@ -371,6 +375,7 @@ impl Service {
|
||||||
ServiceType::ShardingMigrateUnset => {
|
ServiceType::ShardingMigrateUnset => {
|
||||||
Some(vec![Service::ShardingMigrateUnset(ShardingMigrateUnset)])
|
Some(vec![Service::ShardingMigrateUnset(ShardingMigrateUnset)])
|
||||||
}
|
}
|
||||||
|
ServiceType::Partitioning => Some(vec![Service::Partitioning(Partitioning)]),
|
||||||
ServiceType::Dav => Some(vec![Service::Dav(Dav)]),
|
ServiceType::Dav => Some(vec![Service::Dav(Dav)]),
|
||||||
ServiceType::Sftp => Some(vec![Service::Sftp(Sftp)]),
|
ServiceType::Sftp => Some(vec![Service::Sftp(Sftp)]),
|
||||||
ServiceType::SftpKey => Some(vec![Service::SftpKey(SftpKey)]),
|
ServiceType::SftpKey => Some(vec![Service::SftpKey(SftpKey)]),
|
||||||
|
|
|
||||||
60
src/service/partitioning.rs
Normal file
60
src/service/partitioning.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
use std::io::stdout;
|
||||||
|
|
||||||
|
use crate::cloud::CloudOptions;
|
||||||
|
use crate::config::HazeConfig;
|
||||||
|
use crate::database::DatabaseFamily;
|
||||||
|
use crate::exec::exec;
|
||||||
|
use crate::service::ServiceTrait;
|
||||||
|
use crate::Result;
|
||||||
|
use bollard::Docker;
|
||||||
|
use miette::Report;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
|
pub struct Partitioning;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl ServiceTrait for Partitioning {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"partitioning"
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn spawn(
|
||||||
|
&self,
|
||||||
|
_docker: &Docker,
|
||||||
|
_cloud_id: &str,
|
||||||
|
_network: &str,
|
||||||
|
_config: &HazeConfig,
|
||||||
|
options: &CloudOptions,
|
||||||
|
) -> Result<Vec<String>> {
|
||||||
|
if options.db.family() != DatabaseFamily::MariaDB {
|
||||||
|
return Err(Report::msg("Partitioning is only supported with mariadb"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Vec::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn post_setup(
|
||||||
|
&self,
|
||||||
|
docker: &Docker,
|
||||||
|
cloud_id: &str,
|
||||||
|
_config: &HazeConfig,
|
||||||
|
) -> Result<Vec<Vec<String>>> {
|
||||||
|
let db = format!("{cloud_id}-db");
|
||||||
|
let queries = &[
|
||||||
|
"alter table oc_filecache drop primary key, add primary key (fileid, storage)",
|
||||||
|
"alter table oc_filecache partition by hash(storage) partitions 5",
|
||||||
|
];
|
||||||
|
for query in queries {
|
||||||
|
exec(
|
||||||
|
docker,
|
||||||
|
&db,
|
||||||
|
"root",
|
||||||
|
vec!["mariadb", "-u", "haze", "-phaze", "haze", "-e", query],
|
||||||
|
Vec::<String>::new(),
|
||||||
|
Some(stdout()),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Ok(Vec::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue