Skip to content

Commit

Permalink
Update storage components to edition 2024 (#10919)
Browse files Browse the repository at this point in the history
Updates storage components to edition 2024. We like to stay on the
latest edition if possible. There is no functional changes, however some
code changes had to be done to accommodate the edition's breaking
changes.

The PR has two commits:

* the first commit updates storage crates to edition 2024 and appeases
`cargo clippy` by changing code. i have accidentially ran the formatter
on some files that had other edits.
* the second commit performs a `cargo fmt`

I would recommend a closer review of the first commit and a less close
review of the second one (as it just runs `cargo fmt`).

part of #10918
  • Loading branch information
arpad-m authored Feb 25, 2025
1 parent dc975d5 commit 920040e
Show file tree
Hide file tree
Showing 221 changed files with 3,479 additions and 3,547 deletions.
2 changes: 1 addition & 1 deletion libs/pageserver_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pageserver_api"
version = "0.1.0"
edition.workspace = true
edition = "2024"
license.workspace = true

[features]
Expand Down
21 changes: 10 additions & 11 deletions libs/pageserver_api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ pub const DEFAULT_PG_LISTEN_ADDR: &str = formatcp!("127.0.0.1:{DEFAULT_PG_LISTEN
pub const DEFAULT_HTTP_LISTEN_PORT: u16 = 9898;
pub const DEFAULT_HTTP_LISTEN_ADDR: &str = formatcp!("127.0.0.1:{DEFAULT_HTTP_LISTEN_PORT}");

use std::collections::HashMap;
use std::num::{NonZeroU64, NonZeroUsize};
use std::str::FromStr;
use std::time::Duration;

use postgres_backend::AuthType;
use remote_storage::RemoteStorageConfig;
use serde_with::serde_as;
use std::{
collections::HashMap,
num::{NonZeroU64, NonZeroUsize},
str::FromStr,
time::Duration,
};
use utils::{logging::LogFormat, postgres_client::PostgresClientProtocol};
use utils::logging::LogFormat;
use utils::postgres_client::PostgresClientProtocol;

use crate::models::ImageCompressionAlgorithm;
use crate::models::LsnLease;
use crate::models::{ImageCompressionAlgorithm, LsnLease};

// Certain metadata (e.g. externally-addressable name, AZ) is delivered
// as a separate structure. This information is not neeed by the pageserver
Expand Down Expand Up @@ -367,10 +366,10 @@ pub struct TenantConfigToml {
}

pub mod defaults {
use crate::models::ImageCompressionAlgorithm;

pub use storage_broker::DEFAULT_ENDPOINT as BROKER_DEFAULT_ENDPOINT;

use crate::models::ImageCompressionAlgorithm;

pub const DEFAULT_WAIT_LSN_TIMEOUT: &str = "300 s";
pub const DEFAULT_WAL_REDO_TIMEOUT: &str = "60 s";

Expand Down
12 changes: 5 additions & 7 deletions libs/pageserver_api/src/controller_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ use std::time::{Duration, Instant};
use serde::{Deserialize, Serialize};
use utils::id::{NodeId, TenantId};

use crate::models::PageserverUtilization;
use crate::{
models::{ShardParameters, TenantConfig},
shard::{ShardStripeSize, TenantShardId},
};
use crate::models::{PageserverUtilization, ShardParameters, TenantConfig};
use crate::shard::{ShardStripeSize, TenantShardId};

#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -354,7 +351,7 @@ impl FromStr for SkSchedulingPolicy {
_ => {
return Err(anyhow::anyhow!(
"Unknown scheduling policy '{s}', try active,pause,decomissioned"
))
));
}
})
}
Expand Down Expand Up @@ -457,9 +454,10 @@ pub struct SafekeeperSchedulingPolicyRequest {

#[cfg(test)]
mod test {
use super::*;
use serde_json;

use super::*;

/// Check stability of PlacementPolicy's serialization
#[test]
fn placement_policy_encoding() -> anyhow::Result<()> {
Expand Down
30 changes: 14 additions & 16 deletions libs/pageserver_api/src/key.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use anyhow::{bail, Result};
use byteorder::{ByteOrder, BE};
use std::fmt;
use std::ops::Range;

use anyhow::{Result, bail};
use byteorder::{BE, ByteOrder};
use bytes::Bytes;
use postgres_ffi::relfile_utils::{FSM_FORKNUM, VISIBILITYMAP_FORKNUM};
use postgres_ffi::Oid;
use postgres_ffi::RepOriginId;
use postgres_ffi::{Oid, RepOriginId};
use serde::{Deserialize, Serialize};
use std::{fmt, ops::Range};
use utils::const_assert;

use crate::reltag::{BlockNumber, RelTag, SlruKind};
Expand Down Expand Up @@ -954,25 +955,22 @@ impl std::str::FromStr for Key {
mod tests {
use std::str::FromStr;

use crate::key::is_metadata_key_slice;
use crate::key::Key;

use rand::Rng;
use rand::SeedableRng;
use rand::{Rng, SeedableRng};

use super::AUX_KEY_PREFIX;
use crate::key::{Key, is_metadata_key_slice};

#[test]
fn display_fromstr_bijection() {
let mut rng = rand::rngs::StdRng::seed_from_u64(42);

let key = Key {
field1: rng.gen(),
field2: rng.gen(),
field3: rng.gen(),
field4: rng.gen(),
field5: rng.gen(),
field6: rng.gen(),
field1: rng.r#gen(),
field2: rng.r#gen(),
field3: rng.r#gen(),
field4: rng.r#gen(),
field5: rng.r#gen(),
field6: rng.r#gen(),
};

assert_eq!(key, Key::from_str(&format!("{key}")).unwrap());
Expand Down
19 changes: 8 additions & 11 deletions libs/pageserver_api/src/keyspace.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use postgres_ffi::BLCKSZ;
use std::ops::Range;

use crate::{
key::Key,
shard::{ShardCount, ShardIdentity},
};
use itertools::Itertools;
use postgres_ffi::BLCKSZ;

use crate::key::Key;
use crate::shard::{ShardCount, ShardIdentity};

///
/// Represents a set of Keys, in a compact form.
Expand Down Expand Up @@ -609,15 +608,13 @@ pub fn singleton_range(key: Key) -> Range<Key> {

#[cfg(test)]
mod tests {
use rand::{RngCore, SeedableRng};
use std::fmt::Write;

use crate::{
models::ShardParameters,
shard::{ShardCount, ShardNumber},
};
use rand::{RngCore, SeedableRng};

use super::*;
use std::fmt::Write;
use crate::models::ShardParameters;
use crate::shard::{ShardCount, ShardNumber};

// Helper function to create a key range.
//
Expand Down
50 changes: 22 additions & 28 deletions libs/pageserver_api/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,30 @@ pub mod detach_ancestor;
pub mod partitioning;
pub mod utilization;

#[cfg(feature = "testing")]
use camino::Utf8PathBuf;
pub use utilization::PageserverUtilization;

use core::ops::Range;
use std::{
collections::HashMap,
fmt::Display,
io::{BufRead, Read},
num::{NonZeroU32, NonZeroU64, NonZeroUsize},
str::FromStr,
time::{Duration, SystemTime},
};
use std::collections::HashMap;
use std::fmt::Display;
use std::io::{BufRead, Read};
use std::num::{NonZeroU32, NonZeroU64, NonZeroUsize};
use std::str::FromStr;
use std::time::{Duration, SystemTime};

use byteorder::{BigEndian, ReadBytesExt};
use bytes::{Buf, BufMut, Bytes, BytesMut};
#[cfg(feature = "testing")]
use camino::Utf8PathBuf;
use postgres_ffi::BLCKSZ;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::serde_as;
use utils::{
completion,
id::{NodeId, TenantId, TimelineId},
lsn::Lsn,
postgres_client::PostgresClientProtocol,
serde_system_time,
};

use crate::{
key::{CompactKey, Key},
reltag::RelTag,
shard::{ShardCount, ShardStripeSize, TenantShardId},
};
use bytes::{Buf, BufMut, Bytes, BytesMut};
pub use utilization::PageserverUtilization;
use utils::id::{NodeId, TenantId, TimelineId};
use utils::lsn::Lsn;
use utils::postgres_client::PostgresClientProtocol;
use utils::{completion, serde_system_time};

use crate::key::{CompactKey, Key};
use crate::reltag::RelTag;
use crate::shard::{ShardCount, ShardStripeSize, TenantShardId};

/// The state of a tenant in this pageserver.
///
Expand Down Expand Up @@ -332,7 +324,8 @@ pub struct ImportPgdataIdempotencyKey(pub String);

impl ImportPgdataIdempotencyKey {
pub fn random() -> Self {
use rand::{distributions::Alphanumeric, Rng};
use rand::Rng;
use rand::distributions::Alphanumeric;
Self(
rand::thread_rng()
.sample_iter(&Alphanumeric)
Expand Down Expand Up @@ -2288,9 +2281,10 @@ impl Default for PageTraceEvent {

#[cfg(test)]
mod tests {
use serde_json::json;
use std::str::FromStr;

use serde_json::json;

use super::*;

#[test]
Expand Down
14 changes: 8 additions & 6 deletions libs/pageserver_api/src/models/utilization.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::time::SystemTime;
use utils::{serde_percent::Percent, serde_system_time};

use utils::serde_percent::Percent;
use utils::serde_system_time;

/// Pageserver current utilization and scoring for how good candidate the pageserver would be for
/// the next tenant.
Expand Down Expand Up @@ -131,12 +133,12 @@ impl PageserverUtilization {

/// Test helper
pub mod test_utilization {
use super::PageserverUtilization;
use std::time::SystemTime;
use utils::{
serde_percent::Percent,
serde_system_time::{self},
};

use utils::serde_percent::Percent;
use utils::serde_system_time::{self};

use super::PageserverUtilization;

// Parameters of the imaginary node used for test utilization instances
const TEST_DISK_SIZE: u64 = 1024 * 1024 * 1024 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion libs/pageserver_api/src/record.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module defines the WAL record format used within the pageserver.
use bytes::Bytes;
use postgres_ffi::walrecord::{describe_postgres_wal_record, MultiXactMember};
use postgres_ffi::walrecord::{MultiXactMember, describe_postgres_wal_record};
use postgres_ffi::{MultiXactId, MultiXactOffset, TimestampTz, TransactionId};
use serde::{Deserialize, Serialize};
use utils::bin_ser::DeserializeError;
Expand Down
6 changes: 3 additions & 3 deletions libs/pageserver_api/src/reltag.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::fmt;

use postgres_ffi::pg_constants::GLOBALTABLESPACE_OID;
use postgres_ffi::relfile_utils::{forkname_to_number, forknumber_to_name, MAIN_FORKNUM};
use postgres_ffi::Oid;
use postgres_ffi::pg_constants::GLOBALTABLESPACE_OID;
use postgres_ffi::relfile_utils::{MAIN_FORKNUM, forkname_to_number, forknumber_to_name};
use serde::{Deserialize, Serialize};

///
/// Relation data file segment id throughout the Postgres cluster.
Expand Down
10 changes: 6 additions & 4 deletions libs/pageserver_api/src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
use std::hash::{Hash, Hasher};

use crate::{key::Key, models::ShardParameters};
#[doc(inline)]
pub use ::utils::shard::*;
use postgres_ffi::relfile_utils::INIT_FORKNUM;
use serde::{Deserialize, Serialize};

#[doc(inline)]
pub use ::utils::shard::*;
use crate::key::Key;
use crate::models::ShardParameters;

/// The ShardIdentity contains enough information to map a [`Key`] to a [`ShardNumber`],
/// and to check whether that [`ShardNumber`] is the same as the current shard.
Expand Down Expand Up @@ -337,7 +338,8 @@ pub fn describe(
mod tests {
use std::str::FromStr;

use utils::{id::TenantId, Hex};
use utils::Hex;
use utils::id::TenantId;

use super::*;

Expand Down
10 changes: 5 additions & 5 deletions libs/pageserver_api/src/upcall_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use serde::{Deserialize, Serialize};
use utils::id::NodeId;

use crate::{
controller_api::NodeRegisterRequest, models::LocationConfigMode, shard::TenantShardId,
};
use crate::controller_api::NodeRegisterRequest;
use crate::models::LocationConfigMode;
use crate::shard::TenantShardId;

/// Upcall message sent by the pageserver to the configured `control_plane_api` on
/// startup.
Expand All @@ -30,7 +30,7 @@ fn default_mode() -> LocationConfigMode {
pub struct ReAttachResponseTenant {
pub id: TenantShardId,
/// Mandatory if LocationConfigMode is None or set to an Attached* mode
pub gen: Option<u32>,
pub r#gen: Option<u32>,

/// Default value only for backward compat: this field should be set
#[serde(default = "default_mode")]
Expand All @@ -44,7 +44,7 @@ pub struct ReAttachResponse {
#[derive(Serialize, Deserialize)]
pub struct ValidateRequestTenant {
pub id: TenantShardId,
pub gen: u32,
pub r#gen: u32,
}

#[derive(Serialize, Deserialize)]
Expand Down
7 changes: 4 additions & 3 deletions libs/pageserver_api/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
//! Note that the [`Value`] type is used for the permananent storage format, so any
//! changes to it must be backwards compatible.
use crate::record::NeonWalRecord;
use bytes::Bytes;
use serde::{Deserialize, Serialize};

use crate::record::NeonWalRecord;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Value {
/// An Image value contains a full copy of the value
Expand Down Expand Up @@ -83,11 +84,11 @@ impl ValueBytes {

#[cfg(test)]
mod test {
use super::*;

use bytes::Bytes;
use utils::bin_ser::BeSer;

use super::*;

macro_rules! roundtrip {
($orig:expr, $expected:expr) => {{
let orig: Value = $orig;
Expand Down
2 changes: 1 addition & 1 deletion libs/remote_storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "remote_storage"
version = "0.1.0"
edition.workspace = true
edition = "2024"
license.workspace = true

[dependencies]
Expand Down
Loading

1 comment on commit 920040e

@github-actions
Copy link

@github-actions github-actions bot commented on 920040e Feb 26, 2025

Choose a reason for hiding this comment

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

1410 tests run: 1371 passed, 1 failed, 38 skipped (full report)


Failures on Postgres 17

# Run all failed tests locally:
scripts/pytest -vv -n $(nproc) -k "test_neon_cli_basics[release-pg17]"
Flaky tests (1)

Postgres 17

Test coverage report is not available

The comment gets automatically updated with the latest test results
920040e at 2025-02-26T02:37:36.033Z :recycle:

Please sign in to comment.