Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate synthetic size worker #3123

Merged
merged 6 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libs/tenant_size_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ license = "Apache-2.0"

[dependencies]
workspace_hack = { version = "0.1", path = "../../workspace_hack" }
anyhow = "1.0.68"
22 changes: 14 additions & 8 deletions libs/tenant_size_model/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::borrow::Cow;
use std::collections::HashMap;

use anyhow::Context;

/// Pricing model or history size builder.
///
/// Maintains knowledge of the branches and their modifications. Generic over the branch name key
Expand Down Expand Up @@ -134,7 +136,7 @@ impl<K: std::hash::Hash + Eq + 'static> Storage<K> {
size: Option<u64>,
) where
K: std::borrow::Borrow<Q>,
Q: std::hash::Hash + Eq,
Q: std::hash::Hash + Eq + std::fmt::Debug,
{
let lastseg_id = *self.branches.get(branch).unwrap();
let newseg_id = self.segments.len();
Expand Down Expand Up @@ -214,20 +216,24 @@ impl<K: std::hash::Hash + Eq + 'static> Storage<K> {
}

/// Panics if the parent branch cannot be found.
pub fn branch<Q: ?Sized>(&mut self, parent: &Q, name: K)
pub fn branch<Q: ?Sized>(&mut self, parent: &Q, name: K) -> anyhow::Result<()>
where
K: std::borrow::Borrow<Q>,
Q: std::hash::Hash + Eq,
K: std::borrow::Borrow<Q> + std::fmt::Debug,
Q: std::hash::Hash + Eq + std::fmt::Debug,
{
// Find the right segment
let branchseg_id = *self
.branches
.get(parent)
.expect("should had found the parent by key");
let branchseg_id = *self.branches.get(parent).with_context(|| {
format!(
"should had found the parent {:?} by key. in branches {:?}",
parent, self.branches
)
})?;

let _branchseg = &mut self.segments[branchseg_id];

// Create branch name for it
self.branches.insert(name, branchseg_id);
Ok(())
}

pub fn calculate(&mut self, retention_period: u64) -> SegmentSize {
Expand Down
16 changes: 8 additions & 8 deletions libs/tenant_size_model/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn scenario_2() -> (Vec<Segment>, SegmentSize) {
}

// Branch
storage.branch("main", "child");
storage.branch("main", "child").unwrap();
storage.update("child", 1_000);

// More updates on parent
Expand All @@ -63,7 +63,7 @@ fn scenario_3() -> (Vec<Segment>, SegmentSize) {
}

// Branch
storage.branch("main", "child");
storage.branch("main", "child").unwrap();
storage.update("child", 1_000);

// More updates on parent
Expand All @@ -90,7 +90,7 @@ fn scenario_4() -> (Vec<Segment>, SegmentSize) {
}

// Branch
storage.branch("main", "child");
storage.branch("main", "child").unwrap();
storage.update("child", 1_000);

// More updates on parent
Expand All @@ -106,10 +106,10 @@ fn scenario_4() -> (Vec<Segment>, SegmentSize) {
fn scenario_5() -> (Vec<Segment>, SegmentSize) {
let mut storage = Storage::new("a");
storage.insert("a", 5000);
storage.branch("a", "b");
storage.branch("a", "b").unwrap();
storage.update("b", 4000);
storage.update("a", 2000);
storage.branch("a", "c");
storage.branch("a", "c").unwrap();
storage.insert("c", 4000);
storage.insert("a", 2000);

Expand All @@ -133,12 +133,12 @@ fn scenario_6() -> (Vec<Segment>, SegmentSize) {

let mut storage = Storage::new(None);

storage.branch(&None, branches[0]); // at 0
storage.branch(&None, branches[0]).unwrap(); // at 0
storage.modify_branch(&branches[0], NO_OP, 108951064, 43696128); // at 108951064
storage.branch(&branches[0], branches[1]); // at 108951064
storage.branch(&branches[0], branches[1]).unwrap(); // at 108951064
storage.modify_branch(&branches[1], NO_OP, 15560408, -1851392); // at 124511472
storage.modify_branch(&branches[0], NO_OP, 174464360, -1531904); // at 283415424
storage.branch(&branches[0], branches[2]); // at 283415424
storage.branch(&branches[0], branches[2]).unwrap(); // at 283415424
storage.modify_branch(&branches[2], NO_OP, 15906192, 8192); // at 299321616
storage.modify_branch(&branches[0], NO_OP, 18909976, 32768); // at 302325400

Expand Down
1 change: 1 addition & 0 deletions pageserver/src/bin/pageserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ fn start_pageserver(conf: &'static PageServerConf) -> anyhow::Result<()> {
pageserver::consumption_metrics::collect_metrics(
metric_collection_endpoint,
conf.metric_collection_interval,
conf.synthetic_size_calculation_interval,
conf.id,
)
.instrument(info_span!("metrics_collection"))
Expand Down
Loading