Add compaction_target_size to per-tenant config

This commit is contained in:
Anastasia Lubennikova
2022-04-04 15:07:41 +03:00
parent 3da8233f08
commit 47ece2be8b
6 changed files with 15 additions and 2 deletions

View File

@@ -352,6 +352,9 @@ impl PageServerNode {
checkpoint_distance: settings
.get("checkpoint_distance")
.map(|x| x.parse::<u64>().unwrap()),
compaction_target_size: settings
.get("compaction_target_size")
.map(|x| x.parse::<u64>().unwrap()),
compaction_period: settings.get("compaction_period").map(|x| x.to_string()),
gc_horizon: settings
.get("gc_horizon")

View File

@@ -150,6 +150,7 @@ pub const TENANT_CONFIG_NAME: &str = "config";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct TenantConf {
pub checkpoint_distance: u64,
pub compaction_target_size: u64,
pub compaction_period: Duration,
pub gc_horizon: u64,
pub gc_period: Duration,
@@ -164,6 +165,7 @@ impl TenantConf {
pitr_interval: conf.pitr_interval,
checkpoint_distance: conf.checkpoint_distance,
compaction_period: conf.compaction_period,
compaction_target_size: conf.compaction_target_size,
}
}
pub fn save(&self, conf: &'static PageServerConf, tenantid: ZTenantId) -> Result<()> {

View File

@@ -26,6 +26,7 @@ pub struct TenantCreateRequest {
#[serde_as(as = "Option<DisplayFromStr>")]
pub new_tenant_id: Option<ZTenantId>,
pub checkpoint_distance: Option<u64>,
pub compaction_target_size: Option<u64>,
pub compaction_period: Option<String>,
pub gc_horizon: Option<u64>,
pub gc_period: Option<String>,
@@ -47,6 +48,7 @@ impl TenantCreateRequest {
TenantCreateRequest {
new_tenant_id,
checkpoint_distance: None,
compaction_target_size: None,
compaction_period: None,
gc_horizon: None,
gc_period: None,

View File

@@ -306,6 +306,9 @@ async fn tenant_create_handler(mut request: Request<Body>) -> Result<Response<Bo
if let Some(checkpoint_distance) = request_data.checkpoint_distance {
tenant_conf.checkpoint_distance = checkpoint_distance;
}
if let Some(compaction_target_size) = request_data.compaction_target_size {
tenant_conf.compaction_target_size = compaction_target_size;
}
if let Some(compaction_period) = request_data.compaction_period {
tenant_conf.compaction_period =
humantime::parse_duration(&compaction_period).map_err(ApiError::from_err)?;

View File

@@ -683,6 +683,7 @@ impl postgres_backend::Handler for PageServerHandler {
let conf = repo.get_tenant_conf();
pgb.write_message_noflush(&BeMessage::RowDescription(&[
RowDescriptor::int8_col(b"checkpoint_distance"),
RowDescriptor::int8_col(b"compaction_target_size"),
RowDescriptor::int8_col(b"compaction_period"),
RowDescriptor::int8_col(b"gc_horizon"),
RowDescriptor::int8_col(b"gc_period"),
@@ -690,6 +691,7 @@ impl postgres_backend::Handler for PageServerHandler {
]))?
.write_message_noflush(&BeMessage::DataRow(&[
Some(conf.checkpoint_distance.to_string().as_bytes()),
Some(conf.compaction_target_size.to_string().as_bytes()),
Some(conf.compaction_period.as_secs().to_string().as_bytes()),
Some(conf.gc_horizon.to_string().as_bytes()),
Some(conf.gc_period.as_secs().to_string().as_bytes()),

View File

@@ -14,7 +14,8 @@ def test_tenant_config(zenith_env_builder: ZenithEnvBuilder):
'gc_horizon': '1024',
'pitr_interval': '3600sec',
'checkpoint_distance': '10000',
'compaction_period': '60sec'
'compaction_period': '60sec',
'compaction_target_size': '1048576'
})
env.zenith_cli.create_timeline(f'test_tenant_conf', tenant_id=tenant)
@@ -27,4 +28,4 @@ def test_tenant_config(zenith_env_builder: ZenithEnvBuilder):
with closing(env.pageserver.connect()) as psconn:
with psconn.cursor() as pscur:
pscur.execute(f"show {tenant.hex}")
assert pscur.fetchone() == (10000, 60, 1024, 100, 3600)
assert pscur.fetchone() == (10000, 1048576, 60, 1024, 100, 3600)