mirror of
https://codeberg.org/icewind/haze.git
synced 2026-10-01 08:44:09 +02:00
add basic partitioning support
This commit is contained in:
parent
37f467deff
commit
8f7c4e1078
2 changed files with 67 additions and 2 deletions
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