Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,5 @@ disallowed_types = "warn"
from_over_into = "warn"
mod_module_files = "warn"
needless_pass_by_ref_mut = "warn"
borrow_interior_mutable_const = "warn"
# END LINT CONFIG
3 changes: 3 additions & 0 deletions misc/python/materialize/cli/gen-lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
# We consistently don't use `mod.rs` files.
"mod_module_files",
"needless_pass_by_ref_mut",
# Helps prevent bugs caused by wrong usage of `const` instead of `static`
# to define global mutable values.
"borrow_interior_mutable_const",
]

MESSAGE_LINT_MISSING = (
Expand Down
1 change: 1 addition & 0 deletions misc/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@ disallowed_types = "warn"
from_over_into = "warn"
mod_module_files = "warn"
needless_pass_by_ref_mut = "warn"
borrow_interior_mutable_const = "warn"
# END LINT CONFIG
2 changes: 1 addition & 1 deletion src/adapter/src/coord/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ impl Coordinator {
///
/// (Note that the chosen timestamp won't be the same timestamp as the system table inserts,
/// unfortunately.)
async fn resolve_mz_now_for_create_materialized_view<'a>(
async fn resolve_mz_now_for_create_materialized_view(
&mut self,
cmvs: &CreateMaterializedViewStatement<Aug>,
resolved_ids: &ResolvedIds,
Expand Down
14 changes: 2 additions & 12 deletions src/adapter/src/coord/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use std::collections::{BTreeMap, BTreeSet};
use std::fmt;
use std::sync::Arc;
use std::sync::LazyLock;
use std::time::Duration;

use chrono::{DateTime, Utc};
use futures::Future;
Expand Down Expand Up @@ -711,16 +709,8 @@ impl Coordinator {
/// Convenience function for calculating the current upper bound that we want to
/// prevent the global timestamp from exceeding.
fn upper_bound(now: &mz_repr::Timestamp) -> mz_repr::Timestamp {
const TIMESTAMP_INTERVAL: LazyLock<mz_repr::Timestamp> = LazyLock::new(|| {
Duration::from_secs(5)
.as_millis()
.try_into()
.expect("5 seconds can fit into `Timestamp`")
});

const TIMESTAMP_INTERVAL_MS: u64 = 5000;
const TIMESTAMP_INTERVAL_UPPER_BOUND: u64 = 2;

now.saturating_add(
TIMESTAMP_INTERVAL.saturating_mul(Timestamp::from(TIMESTAMP_INTERVAL_UPPER_BOUND)),
)
now.saturating_add(TIMESTAMP_INTERVAL_MS * TIMESTAMP_INTERVAL_UPPER_BOUND)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idk what the meaning of the two constants here ("timestamp interval" and "timestamp interval upper bound") is, but it seems like maybe it could be a single constant?

}
17 changes: 6 additions & 11 deletions src/adapter/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,13 @@ where
#[mz_ore::instrument(target = "optimizer", level = "debug", name = "optimize")]
fn catch_unwind_optimize(&mut self, plan: From) -> Result<Self::To, OptimizerError> {
match mz_ore::panic::catch_unwind_str(AssertUnwindSafe(|| self.optimize(plan))) {
Ok(result) => {
match result.map_err(Into::into) {
Err(OptimizerError::TransformError(TransformError::CallerShouldPanic(msg))) => {
// Promote a `CallerShouldPanic` error from the result
// to a proper panic. This is needed in order to ensure
// that `mz_unsafe.mz_panic('forced panic')` calls still
// panic the caller.
panic!("{}", msg)
}
result => result,
}
Ok(Err(OptimizerError::TransformError(TransformError::CallerShouldPanic(msg)))) => {
// Promote a `CallerShouldPanic` error from the result to a proper panic. This is
// needed in order to ensure that `mz_unsafe.mz_panic('forced panic')` calls still
// panic the caller.
panic!("{msg}");
}
Ok(result) => result,
Err(panic) => {
let msg = format!("unexpected panic during query optimization: {panic}");
Err(OptimizerError::Internal(msg))
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ impl<T: TimestampManipulation> Session<T> {
datums: Row::pack(params.iter().map(|(d, _t)| d)),
types: params.into_iter().map(|(_d, t)| t).collect(),
},
result_formats: result_formats.into_iter().map(Into::into).collect(),
result_formats,
state: PortalState::NotStarted,
logging,
},
Expand Down
27 changes: 11 additions & 16 deletions src/catalog/src/durable/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,17 @@ const DEFAULT_ALLOCATOR_ID: u64 = 1;

pub const DEFAULT_USER_NETWORK_POLICY_ID: NetworkPolicyId = NetworkPolicyId::User(1);
pub const DEFAULT_USER_NETWORK_POLICY_NAME: &str = "default";
pub const DEFAULT_USER_NETWORK_POLICY_RULES: LazyLock<
Vec<(
&str,
mz_sql::plan::NetworkPolicyRuleAction,
mz_sql::plan::NetworkPolicyRuleDirection,
&str,
)>,
> = LazyLock::new(|| {
vec![(
"open_ingress",
mz_sql::plan::NetworkPolicyRuleAction::Allow,
mz_sql::plan::NetworkPolicyRuleDirection::Ingress,
"0.0.0.0/0",
)]
});
pub const DEFAULT_USER_NETWORK_POLICY_RULES: &[(
&str,
mz_sql::plan::NetworkPolicyRuleAction,
mz_sql::plan::NetworkPolicyRuleDirection,
&str,
)] = &[(
"open_ingress",
mz_sql::plan::NetworkPolicyRuleAction::Allow,
mz_sql::plan::NetworkPolicyRuleDirection::Ingress,
"0.0.0.0/0",
)];

static DEFAULT_USER_NETWORK_POLICY_PRIVILEGES: LazyLock<Vec<MzAclItem>> = LazyLock::new(|| {
vec![rbac::owner_privilege(
Expand Down Expand Up @@ -594,7 +590,6 @@ pub(crate) async fn initialize(
DEFAULT_USER_NETWORK_POLICY_ID,
DEFAULT_USER_NETWORK_POLICY_NAME.to_string(),
DEFAULT_USER_NETWORK_POLICY_RULES
.clone()
.into_iter()
.map(|(name, action, direction, ip_str)| NetworkPolicyRule {
name: name.to_string(),
Expand Down
6 changes: 3 additions & 3 deletions src/catalog/tests/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async fn test_persist_debug() {
test_debug(state_builder).await;
}

async fn test_debug<'a>(state_builder: TestCatalogStateBuilder) {
async fn test_debug(state_builder: TestCatalogStateBuilder) {
let state_builder = state_builder.with_default_deploy_generation();
let mut openable_state1 = state_builder.clone().unwrap_build().await;
// Check initial empty trace.
Expand Down Expand Up @@ -340,7 +340,7 @@ async fn test_persist_debug_edit_fencing() {
test_debug_edit_fencing(state_builder).await;
}

async fn test_debug_edit_fencing<'a>(state_builder: TestCatalogStateBuilder) {
async fn test_debug_edit_fencing(state_builder: TestCatalogStateBuilder) {
let mut state = state_builder
.clone()
.with_default_deploy_generation()
Expand Down Expand Up @@ -435,7 +435,7 @@ async fn test_persist_debug_delete_fencing() {
test_debug_delete_fencing(state_builder).await;
}

async fn test_debug_delete_fencing<'a>(state_builder: TestCatalogStateBuilder) {
async fn test_debug_delete_fencing(state_builder: TestCatalogStateBuilder) {
let mut state = state_builder
.clone()
.with_default_deploy_generation()
Expand Down
4 changes: 2 additions & 2 deletions src/expr-test-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl MirScalarExprDeserializeContext {
I: Iterator<Item = TokenTree>,
{
match &first_arg {
TokenTree::Ident(i) if i.to_string().to_ascii_lowercase() == "ok" => {
TokenTree::Ident(i) if i.to_string().eq_ignore_ascii_case("ok") => {
// literal definition is mandatory after OK token
let first_arg = if let Some(first_arg) = rest_of_stream.next() {
first_arg
Expand All @@ -251,7 +251,7 @@ impl MirScalarExprDeserializeContext {
_ => Err(format!("expected literal after Ident: `{}`", i)),
}
}
TokenTree::Ident(i) if i.to_string().to_ascii_lowercase() == "err" => {
TokenTree::Ident(i) if i.to_string().eq_ignore_ascii_case("err") => {
let error = deserialize_generic(rest_of_stream, "EvalError")?;
let typ: Option<ScalarType> =
deserialize_optional_generic(rest_of_stream, "ScalarType")?;
Expand Down
4 changes: 2 additions & 2 deletions src/frontegg-mock/src/handlers/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::sync::Arc;
use uuid::Uuid;

// https://docs.frontegg.com/reference/userscontrollerv2_getuserprofile
pub async fn handle_get_user_profile<'a>(
pub async fn handle_get_user_profile(
State(context): State<Arc<Context>>,
TypedHeader(authorization): TypedHeader<Authorization<Bearer>>,
) -> Result<Json<UserProfileResponse>, StatusCode> {
Expand All @@ -41,7 +41,7 @@ pub async fn handle_get_user_profile<'a>(
}

// https://docs.frontegg.com/reference/userapitokensv1controller_createtenantapitoken
pub async fn handle_post_user_api_token<'a>(
pub async fn handle_post_user_api_token(
State(context): State<Arc<Context>>,
TypedHeader(authorization): TypedHeader<Authorization<Bearer>>,
Json(request): Json<UserApiTokenRequest>,
Expand Down
4 changes: 2 additions & 2 deletions src/lsp-server/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ mod tests {
}

/// The file path used during the tests is where the SQL code resides.
const FILE_PATH: LazyLock<PathBuf> = LazyLock::new(|| temp_dir().join("foo.sql"));
static FILE_PATH: LazyLock<PathBuf> = LazyLock::new(|| temp_dir().join("foo.sql"));
/// The SQL code written inside [FILE_PATH].
const FILE_SQL_CONTENT: LazyLock<String> =
static FILE_SQL_CONTENT: LazyLock<String> =
LazyLock::new(|| "SELECT \t\t\t200, 200;".to_string());

/// Tests the different capabilities of [Backend](mz_lsp::backend::Backend)
Expand Down
2 changes: 1 addition & 1 deletion src/mz/src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl ConfigFile {
}

/// Removes a profile from the configuration file.
pub async fn remove_profile<'a>(&self, name: &str) -> Result<(), Error> {
pub async fn remove_profile(&self, name: &str) -> Result<(), Error> {
let mut editable = self.editable.clone();
let profiles = editable["profiles"]
.as_table_mut()
Expand Down
4 changes: 2 additions & 2 deletions src/persist-client/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,9 @@ mod pubsub_state {
use crate::rpc::{PubSubSenderInternal, PubSubState};
use crate::ShardId;

const SHARD_ID_0: LazyLock<ShardId> =
static SHARD_ID_0: LazyLock<ShardId> =
LazyLock::new(|| ShardId::from_str("s00000000-0000-0000-0000-000000000000").unwrap());
const SHARD_ID_1: LazyLock<ShardId> =
static SHARD_ID_1: LazyLock<ShardId> =
LazyLock::new(|| ShardId::from_str("s11111111-1111-1111-1111-111111111111").unwrap());

const VERSIONED_DATA_0: VersionedData = VersionedData {
Expand Down
2 changes: 1 addition & 1 deletion src/prof-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct FlamegraphTemplate<'a> {
}

#[allow(dropping_copy_types)]
async fn time_prof<'a>(
async fn time_prof(
merge_threads: bool,
build_info: &BuildInfo,
// the time in seconds to run the profiler for
Expand Down
4 changes: 2 additions & 2 deletions src/secrets/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use mz_repr::CatalogItemId;
use crate::{CachingPolicy, SecretsReader};

/// Default "time to live" for a single cache value, represented in __seconds__.
pub const DEFAULT_TTL_SECS: AtomicU64 = AtomicU64::new(Duration::from_secs(300).as_secs());
pub const DEFAULT_TTL_SECS: u64 = Duration::from_secs(300).as_secs();

#[derive(Debug)]
struct CachingParameters {
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Default for CachingParameters {
fn default() -> Self {
CachingParameters {
enabled: AtomicBool::new(true),
ttl_secs: DEFAULT_TTL_SECS,
ttl_secs: AtomicU64::new(DEFAULT_TTL_SECS),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sql/src/plan/statement/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ mod connection;
// more strict.
const MAX_NUM_COLUMNS: usize = 256;

const MANAGED_REPLICA_PATTERN: std::sync::LazyLock<regex::Regex> =
static MANAGED_REPLICA_PATTERN: std::sync::LazyLock<regex::Regex> =
std::sync::LazyLock::new(|| regex::Regex::new(r"^r(\d)+$").unwrap());

/// Given a relation desc and a column list, checks that:
Expand Down
72 changes: 36 additions & 36 deletions src/sql/src/session/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl SessionVars {
&WELCOME_MESSAGE,
]
.into_iter()
.chain(SystemVars::SESSION_VARS.iter().map(|(_name, var)| *var))
.chain(SESSION_SYSTEM_VARS.iter().map(|(_name, var)| *var))
.map(|var| (var.name, SessionVar::new(var.clone())))
.collect();

Expand Down Expand Up @@ -1070,37 +1070,6 @@ impl Default for SystemVars {
}

impl SystemVars {
/// Set of [`SystemVar`]s that can also get set at a per-Session level.
///
/// TODO(parkmycar): Instead of a separate list, make this a field on VarDefinition.
const SESSION_VARS: LazyLock<BTreeMap<&'static UncasedStr, &'static VarDefinition>> =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to move this outside the SystemVars impl because associated static items are not allowed.

LazyLock::new(|| {
[
&APPLICATION_NAME,
&CLIENT_ENCODING,
&CLIENT_MIN_MESSAGES,
&CLUSTER,
&CLUSTER_REPLICA,
&CURRENT_OBJECT_MISSING_WARNINGS,
&DATABASE,
&DATE_STYLE,
&EXTRA_FLOAT_DIGITS,
&INTEGER_DATETIMES,
&INTERVAL_STYLE,
&REAL_TIME_RECENCY_TIMEOUT,
&SEARCH_PATH,
&STANDARD_CONFORMING_STRINGS,
&STATEMENT_TIMEOUT,
&IDLE_IN_TRANSACTION_SESSION_TIMEOUT,
&TIMEZONE,
&TRANSACTION_ISOLATION,
&MAX_QUERY_RESULT_SIZE,
]
.into_iter()
.map(|var| (UncasedStr::new(var.name()), var))
.collect()
});

pub fn new() -> Self {
let system_vars = vec![
&MAX_KAFKA_CONNECTIONS,
Expand Down Expand Up @@ -1273,7 +1242,7 @@ impl SystemVars {
// Include all of our feature flags.
.chain(definitions::FEATURE_FLAGS.iter().copied())
// Include the subset of Session variables we allow system defaults for.
.chain(Self::SESSION_VARS.values().copied())
.chain(SESSION_SYSTEM_VARS.values().copied())
.cloned()
// Include Persist configs.
.chain(dyncfg_vars)
Expand Down Expand Up @@ -1341,7 +1310,7 @@ impl SystemVars {
self.vars
.values()
.map(|v| v.as_var())
.filter(|v| !Self::SESSION_VARS.contains_key(UncasedStr::new(v.name())))
.filter(|v| !SESSION_SYSTEM_VARS.contains_key(UncasedStr::new(v.name())))
}

/// Returns an iterator over the configuration parameters and their current
Expand All @@ -1356,12 +1325,12 @@ impl SystemVars {
self.vars
.values()
.map(|v| v.as_var())
.filter(|v| Self::SESSION_VARS.contains_key(UncasedStr::new(v.name())))
.filter(|v| SESSION_SYSTEM_VARS.contains_key(UncasedStr::new(v.name())))
}

/// Returns whether or not this parameter can be modified by a superuser.
pub fn user_modifiable(&self, name: &str) -> bool {
Self::SESSION_VARS.contains_key(UncasedStr::new(name))
SESSION_SYSTEM_VARS.contains_key(UncasedStr::new(name))
|| name == ENABLE_RBAC_CHECKS.name()
|| name == NETWORK_POLICY.name()
}
Expand Down Expand Up @@ -2332,6 +2301,37 @@ pub fn is_http_config_var(name: &str) -> bool {
name == WEBHOOK_CONCURRENT_REQUEST_LIMIT.name()
}

/// Set of [`SystemVar`]s that can also get set at a per-Session level.
///
/// TODO(parkmycar): Instead of a separate list, make this a field on VarDefinition.
static SESSION_SYSTEM_VARS: LazyLock<BTreeMap<&'static UncasedStr, &'static VarDefinition>> =
LazyLock::new(|| {
[
&APPLICATION_NAME,
&CLIENT_ENCODING,
&CLIENT_MIN_MESSAGES,
&CLUSTER,
&CLUSTER_REPLICA,
&CURRENT_OBJECT_MISSING_WARNINGS,
&DATABASE,
&DATE_STYLE,
&EXTRA_FLOAT_DIGITS,
&INTEGER_DATETIMES,
&INTERVAL_STYLE,
&REAL_TIME_RECENCY_TIMEOUT,
&SEARCH_PATH,
&STANDARD_CONFORMING_STRINGS,
&STATEMENT_TIMEOUT,
&IDLE_IN_TRANSACTION_SESSION_TIMEOUT,
&TIMEZONE,
&TRANSACTION_ISOLATION,
&MAX_QUERY_RESULT_SIZE,
]
.into_iter()
.map(|var| (UncasedStr::new(var.name()), var))
.collect()
});

// Provides a wrapper to express that a particular `ServerVar` is meant to be used as a feature
/// flag.
#[derive(Debug)]
Expand Down
4 changes: 1 addition & 3 deletions src/sql/src/session/vars/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,9 +914,7 @@ pub static SENTRY_FILTERS: VarDefinition = VarDefinition::new_lazy(
pub static WEBHOOKS_SECRETS_CACHING_TTL_SECS: VarDefinition = VarDefinition::new_lazy(
"webhooks_secrets_caching_ttl_secs",
lazy_value!(usize; || {
usize::cast_from(
mz_secrets::cache::DEFAULT_TTL_SECS.load(std::sync::atomic::Ordering::Relaxed),
)
usize::cast_from(mz_secrets::cache::DEFAULT_TTL_SECS)
}),
"Sets the time-to-live for values in the Webhooks secrets cache.",
false,
Expand Down
Loading