Skip to content

Commit

Permalink
storage controller: rename TenantState to TenantShard (#7329)
Browse files Browse the repository at this point in the history
This is a widely used type that had a misleading name: it's not the
total state of a tenant, but rrepresents one shard.
  • Loading branch information
jcsp committed Apr 5, 2024
1 parent 66fc465 commit ec01292
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 116 deletions.
2 changes: 1 addition & 1 deletion storage_controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod reconciler;
mod scheduler;
mod schema;
pub mod service;
mod tenant_state;
mod tenant_shard;

#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone, Serialize)]
struct Sequence(u64);
Expand Down
2 changes: 1 addition & 1 deletion storage_controller/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ impl Persistence {
}
}

/// Parts of [`crate::tenant_state::TenantState`] that are stored durably
/// Parts of [`crate::tenant_shard::TenantShard`] that are stored durably
#[derive(Queryable, Selectable, Insertable, Serialize, Deserialize, Clone, Eq, PartialEq)]
#[diesel(table_name = crate::schema::tenant_shards)]
pub(crate) struct TenantShardPersistence {
Expand Down
10 changes: 5 additions & 5 deletions storage_controller/src/reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ use utils::sync::gate::GateGuard;

use crate::compute_hook::{ComputeHook, NotifyError};
use crate::node::Node;
use crate::tenant_state::{IntentState, ObservedState, ObservedStateLocation};
use crate::tenant_shard::{IntentState, ObservedState, ObservedStateLocation};

const DEFAULT_HEATMAP_PERIOD: &str = "60s";

/// Object with the lifetime of the background reconcile task that is created
/// for tenants which have a difference between their intent and observed states.
pub(super) struct Reconciler {
/// See [`crate::tenant_state::TenantState`] for the meanings of these fields: they are a snapshot
/// See [`crate::tenant_shard::TenantShard`] for the meanings of these fields: they are a snapshot
/// of a tenant's state from when we spawned a reconcile task.
pub(super) tenant_shard_id: TenantShardId,
pub(crate) shard: ShardIdentity,
Expand All @@ -48,11 +48,11 @@ pub(super) struct Reconciler {

/// To avoid stalling if the cloud control plane is unavailable, we may proceed
/// past failures in [`ComputeHook::notify`], but we _must_ remember that we failed
/// so that we can set [`crate::tenant_state::TenantState::pending_compute_notification`] to ensure a later retry.
/// so that we can set [`crate::tenant_shard::TenantShard::pending_compute_notification`] to ensure a later retry.
pub(crate) compute_notify_failure: bool,

/// A means to abort background reconciliation: it is essential to
/// call this when something changes in the original TenantState that
/// call this when something changes in the original TenantShard that
/// will make this reconciliation impossible or unnecessary, for
/// example when a pageserver node goes offline, or the PlacementPolicy for
/// the tenant is changed.
Expand All @@ -66,7 +66,7 @@ pub(super) struct Reconciler {
pub(crate) persistence: Arc<Persistence>,
}

/// This is a snapshot of [`crate::tenant_state::IntentState`], but it does not do any
/// This is a snapshot of [`crate::tenant_shard::IntentState`], but it does not do any
/// reference counting for Scheduler. The IntentState is what the scheduler works with,
/// and the TargetState is just the instruction for a particular Reconciler run.
#[derive(Debug)]
Expand Down
10 changes: 5 additions & 5 deletions storage_controller/src/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{node::Node, tenant_state::TenantState};
use crate::{node::Node, tenant_shard::TenantShard};
use pageserver_api::controller_api::UtilizationScore;
use serde::Serialize;
use std::collections::HashMap;
Expand Down Expand Up @@ -27,7 +27,7 @@ pub enum MaySchedule {

#[derive(Serialize)]
struct SchedulerNode {
/// How many shards are currently scheduled on this node, via their [`crate::tenant_state::IntentState`].
/// How many shards are currently scheduled on this node, via their [`crate::tenant_shard::IntentState`].
shard_count: usize,

/// Whether this node is currently elegible to have new shards scheduled (this is derived
Expand Down Expand Up @@ -84,7 +84,7 @@ impl std::ops::Add for AffinityScore {
}
}

// For carrying state between multiple calls to [`TenantState::schedule`], e.g. when calling
// For carrying state between multiple calls to [`TenantShard::schedule`], e.g. when calling
// it for many shards in the same tenant.
#[derive(Debug, Default)]
pub(crate) struct ScheduleContext {
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Scheduler {
pub(crate) fn consistency_check<'a>(
&self,
nodes: impl Iterator<Item = &'a Node>,
shards: impl Iterator<Item = &'a TenantState>,
shards: impl Iterator<Item = &'a TenantShard>,
) -> anyhow::Result<()> {
let mut expect_nodes: HashMap<NodeId, SchedulerNode> = HashMap::new();
for node in nodes {
Expand Down Expand Up @@ -398,7 +398,7 @@ pub(crate) mod test_utils {
mod tests {
use super::*;

use crate::tenant_state::IntentState;
use crate::tenant_shard::IntentState;
#[test]
fn scheduler_basic() -> anyhow::Result<()> {
let nodes = test_utils::make_test_nodes(2);
Expand Down
Loading

1 comment on commit ec01292

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2834 tests run: 2697 passed, 0 failed, 137 skipped (full report)


Code coverage* (full report)

  • functions: 28.0% (6403 of 22855 functions)
  • lines: 46.8% (45071 of 96207 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
ec01292 at 2024-04-05T17:38:49.507Z :recycle:

Please sign in to comment.