Skip to content
Open
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
8 changes: 4 additions & 4 deletions quickwit/quickwit-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const QW_ENABLE_TOKIO_CONSOLE_ENV_KEY: &str = "QW_ENABLE_TOKIO_CONSOLE";
/// The main tokio runtime takes num_cores / 3 threads by default, and can be overridden by the
/// QW_RUNTIME_NUM_THREADS environment variable.
fn get_main_runtime_num_threads() -> usize {
let default_num_runtime_threads: usize = quickwit_common::num_cpus().div_ceil(3);
quickwit_common::get_from_env(
quickwit_common::get_from_env_cached!(
usize,
"QW_TOKIO_RUNTIME_NUM_THREADS",
default_num_runtime_threads,
quickwit_common::num_cpus().div_ceil(3),
false,
)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ fn init_telemetry(
)> {
#[cfg(feature = "tokio-console")]
{
if quickwit_common::get_bool_from_env(QW_ENABLE_TOKIO_CONSOLE_ENV_KEY, false) {
if quickwit_common::get_bool_from_env_cached!(QW_ENABLE_TOKIO_CONSOLE_ENV_KEY, false) {
let telemetry_handle =
quickwit_telemetry_exporters::init_meter_provider_only(service_version)?;
console_subscriber::init();
Expand Down
20 changes: 10 additions & 10 deletions quickwit/quickwit-common/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ pub fn parse_bool_lenient(bool_str: &str) -> Option<bool> {
}

/// Reads and parses an environment variable exactly once, caching the result for the lifetime of
/// the process via a per-call-site [`std::sync::LazyLock`].
/// the process via a per-call-site [`std::sync::OnceLock`].
///
/// Prefer this over [`get_from_env`](crate::get_from_env) on paths that may run repeatedly (e.g.
/// constructors that are re-invoked): it avoids re-reading and, more importantly, re-logging the
/// same variable on every call.
///
/// The type is required because the backing `static` needs a concrete type. The key and default
/// must be `const` expressions or literals — a `static` initializer cannot capture locals.
/// are evaluated only on the first invocation and may reference local values.
///
/// ```no_run
/// # use quickwit_common::get_from_env_cached;
Expand All @@ -94,12 +94,13 @@ pub fn parse_bool_lenient(bool_str: &str) -> Option<bool> {
#[macro_export]
macro_rules! get_from_env_cached {
($ty:ty, $key:expr, $default:expr, $sensitive:expr $(,)?) => {{
static CACHED: ::std::sync::LazyLock<$ty> =
::std::sync::LazyLock::new(|| $crate::get_from_env::<$ty>($key, $default, $sensitive));
// `LazyLock<T>` derefs to `T`; clone so callers receive an owned value, matching
// `get_from_env`'s return type (a no-op copy for the common `Copy` cases).
static CACHED: ::std::sync::OnceLock<$ty> = ::std::sync::OnceLock::new();
// Clone so callers receive an owned value, matching `get_from_env`'s return type (a no-op
// copy for the common `Copy` cases).
#[allow(clippy::clone_on_copy)]
let value = (*CACHED).clone();
let value = CACHED
.get_or_init(|| $crate::get_from_env::<$ty>($key, $default, $sensitive))
.clone();
value
}};
}
Expand All @@ -115,9 +116,8 @@ macro_rules! get_from_env_cached {
#[macro_export]
macro_rules! get_bool_from_env_cached {
($key:expr, $default:expr $(,)?) => {{
static CACHED: ::std::sync::LazyLock<bool> =
::std::sync::LazyLock::new(|| $crate::get_bool_from_env($key, $default));
*CACHED
static CACHED: ::std::sync::OnceLock<bool> = ::std::sync::OnceLock::new();
*CACHED.get_or_init(|| $crate::get_bool_from_env($key, $default))
}};
}

Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-common/src/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Default for RuntimesConfig {
fn start_runtimes(config: RuntimesConfig) -> HashMap<RuntimeType, Runtime> {
let mut runtimes = HashMap::with_capacity(2);

let disable_lifo_slot = crate::get_bool_from_env("QW_DISABLE_TOKIO_LIFO_SLOT", true);
let disable_lifo_slot = crate::get_bool_from_env_cached!("QW_DISABLE_TOKIO_LIFO_SLOT", true);

let mut blocking_runtime_builder = tokio::runtime::Builder::new_multi_thread();
if disable_lifo_slot {
Expand Down
3 changes: 2 additions & 1 deletion quickwit/quickwit-common/src/shared_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ pub fn split_deletion_grace_period() -> Duration {
const DEFAULT_DELETION_GRACE_PERIOD: Duration = Duration::from_secs(60 * 32); // 32 min

static SPLIT_DELETION_GRACE_PERIOD_SECS_LOCK: LazyLock<Duration> = LazyLock::new(|| {
let deletion_grace_period_secs: u64 = crate::get_from_env(
let deletion_grace_period_secs: u64 = crate::get_from_env_cached!(
u64,
"QW_SPLIT_DELETION_GRACE_PERIOD_SECS",
DEFAULT_DELETION_GRACE_PERIOD.as_secs(),
false,
Expand Down
14 changes: 4 additions & 10 deletions quickwit/quickwit-config/src/storage_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
// limitations under the License.

use std::ops::Deref;
use std::sync::OnceLock;
use std::{env, fmt};

use anyhow::ensure;
use itertools::Itertools;
use quickwit_common::get_bool_from_env;
use serde::{Deserialize, Serialize};
use serde_with::{EnumMap, serde_as};

Expand Down Expand Up @@ -406,14 +404,10 @@ impl S3StorageConfig {
}

pub fn force_path_style_access(&self) -> Option<bool> {
static FORCE_PATH_STYLE: OnceLock<Option<bool>> = OnceLock::new();
*FORCE_PATH_STYLE.get_or_init(|| {
let force_path_style_access = get_bool_from_env(
"QW_S3_FORCE_PATH_STYLE_ACCESS",
self.force_path_style_access,
);
Some(force_path_style_access)
})
Some(quickwit_common::get_bool_from_env_cached!(
"QW_S3_FORCE_PATH_STYLE_ACCESS",
self.force_path_style_access,
))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ impl IndexingService {
merge_scheduler_service,
max_concurrent_split_uploads: self.max_concurrent_split_uploads,
event_broker: self.event_broker.clone(),
skip_initial_seed: quickwit_common::get_bool_from_env(
skip_initial_seed: quickwit_common::get_bool_from_env_cached!(
super::parquet_pipeline::PARQUET_MERGE_SKIP_INITIAL_SEED_ENV_KEY,
false,
),
Expand Down
3 changes: 2 additions & 1 deletion quickwit/quickwit-ingest/src/ingest_v2/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ fn ingest_request_timeout() -> Duration {
Duration::from_secs(35)
};
static TIMEOUT: LazyLock<Duration> = LazyLock::new(|| {
let duration_ms = quickwit_common::get_from_env(
let duration_ms = quickwit_common::get_from_env_cached!(
u64,
"QW_INGEST_REQUEST_TIMEOUT_MS",
DEFAULT_INGEST_REQUEST_TIMEOUT.as_millis() as u64,
false,
Expand Down
16 changes: 12 additions & 4 deletions quickwit/quickwit-metastore/src/metastore/postgres/migrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use std::collections::BTreeMap;

use quickwit_common::get_bool_from_env;
use quickwit_metrics::{counter, labels};
use quickwit_proto::metastore::{MetastoreError, MetastoreResult};
use sqlx::migrate::{Migrate, Migrator};
Expand Down Expand Up @@ -63,9 +62,18 @@ impl Migrations {
pub(super) fn from_env(connection_pool: TrackedPool<Postgres>) -> Self {
Self {
connection_pool,
skip_migrations: get_bool_from_env(QW_POSTGRES_SKIP_MIGRATIONS_ENV_KEY, false),
skip_locking: get_bool_from_env(QW_POSTGRES_SKIP_MIGRATION_LOCKING_ENV_KEY, false),
skip_deferred: get_bool_from_env(QW_POSTGRES_SKIP_DEFERRED_MIGRATIONS_ENV_KEY, false),
skip_migrations: quickwit_common::get_bool_from_env_cached!(
QW_POSTGRES_SKIP_MIGRATIONS_ENV_KEY,
false
),
skip_locking: quickwit_common::get_bool_from_env_cached!(
QW_POSTGRES_SKIP_MIGRATION_LOCKING_ENV_KEY,
false
),
skip_deferred: quickwit_common::get_bool_from_env_cached!(
QW_POSTGRES_SKIP_DEFERRED_MIGRATIONS_ENV_KEY,
false
),
}
}

Expand Down
7 changes: 3 additions & 4 deletions quickwit/quickwit-proto/src/types/split_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ impl SplitId {
/// Layout with prefix enabled: `<4 random chars>_<22 remaining ULID chars>`
/// (27 chars total vs the usual 26).
pub fn new() -> Self {
static RANDOM_PREFIX_ENABLED: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {
quickwit_common::get_bool_from_env("QW_RANDOM_SPLIT_PREFIX", false)
});
Self::from_ulid(ulid::Ulid::new(), *RANDOM_PREFIX_ENABLED)
let random_prefix_enabled =
quickwit_common::get_bool_from_env_cached!("QW_RANDOM_SPLIT_PREFIX", false);
Self::from_ulid(ulid::Ulid::new(), random_prefix_enabled)
}

/// Constructs a `SplitId` from a `Ulid`, optionally prepending a random prefix.
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/datafusion_api/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(crate) fn build_datafusion_session_builder(
if !node_config.is_service_enabled(QuickwitService::Searcher) {
return Ok(None);
}
if !quickwit_common::get_bool_from_env("QW_ENABLE_DATAFUSION_ENDPOINT", false) {
if !quickwit_common::get_bool_from_env_cached!("QW_ENABLE_DATAFUSION_ENDPOINT", false) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Don't cache the DataFusion enable flag globally

When the datafusion feature is tested in-process, many ClusterSandboxBuilder::build_and_start* tests can start a searcher before metrics_distributed_tests sets QW_ENABLE_DATAFUSION_ENDPOINT=true; this new OnceLock then caches false for the whole test process, so the later DataFusion sandbox never mounts the gRPC service and its client calls fail. This toggle should remain evaluated at node startup (or be made explicitly test-scoped) rather than using a process-wide cached read.

Useful? React with 👍 / 👎.

return Ok(None);
}

Expand Down
7 changes: 4 additions & 3 deletions quickwit/quickwit-serve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ use quickwit_common::pubsub::{EventBroker, EventSubscriptionHandle};
use quickwit_common::rate_limiter::RateLimiterSettings;
use quickwit_common::retry::RetryParams;
use quickwit_common::runtimes::RuntimesConfig;
use quickwit_common::spawn_named_task;
use quickwit_common::tower::{
BalanceChannel, BoxFutureInfaillible, BufferLayer, Change, CircuitBreakerEvaluator,
ConstantRate, EstimateRateLayer, EventListenerLayer, GrpcMetricsLayer, LoadShedLayer,
RateLimitLayer, RetryLayer, RetryPolicy, SmaRateEstimator, TimeoutLayer,
};
use quickwit_common::uri::Uri;
use quickwit_common::{get_bool_from_env, spawn_named_task};
use quickwit_compaction::planner::CompactionPlanner;
use quickwit_compaction::{
CompactorSupervisor, notify_compactor_decommission, start_compactor_service,
Expand Down Expand Up @@ -159,7 +159,8 @@ const DEFAULT_METASTORE_CLIENT_MAX_CONCURRENCY: usize = 6;
const DISABLE_DELETE_TASK_SERVICE_ENV_KEY: &str = "QW_DISABLE_DELETE_TASK_SERVICE";

fn get_metastore_client_max_concurrency() -> usize {
quickwit_common::get_from_env(
quickwit_common::get_from_env_cached!(
usize,
METASTORE_CLIENT_MAX_CONCURRENCY_ENV_KEY,
DEFAULT_METASTORE_CLIENT_MAX_CONCURRENCY,
false,
Expand Down Expand Up @@ -882,7 +883,7 @@ pub async fn serve_quickwit(
search_job_placer,
storage_resolver.clone(),
event_broker.clone(),
!get_bool_from_env(DISABLE_DELETE_TASK_SERVICE_ENV_KEY, false),
!quickwit_common::get_bool_from_env_cached!(DISABLE_DELETE_TASK_SERVICE_ENV_KEY, false),
compaction_planner_handle_opt,
)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use crate::{
/// (R2, SeaweedFs...) return errors when too many concurrent requests are emitted.
static REQUEST_SEMAPHORE: LazyLock<Semaphore> = LazyLock::new(|| {
let num_permits: usize =
quickwit_common::get_from_env("QW_S3_MAX_CONCURRENCY", 10_000usize, false);
quickwit_common::get_from_env_cached!(usize, "QW_S3_MAX_CONCURRENCY", 10_000usize, false);
Semaphore::new(num_permits)
});

Expand Down
10 changes: 7 additions & 3 deletions quickwit/quickwit-telemetry-exporters/src/otlp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::str::FromStr;
use anyhow::Context;
use opentelemetry::KeyValue;
use opentelemetry_sdk::Resource;
use quickwit_common::{get_bool_from_env, get_from_env, get_from_env_opt};
use quickwit_common::get_from_env_opt;

pub const QW_ENABLE_OPENTELEMETRY_OTLP_EXPORTER_ENV_KEY: &str =
"QW_ENABLE_OPENTELEMETRY_OTLP_EXPORTER";
Expand Down Expand Up @@ -66,8 +66,12 @@ pub(crate) struct OtlpExporterConfig {
impl OtlpExporterConfig {
pub(crate) fn load_from_env() -> Self {
OtlpExporterConfig {
enabled: get_bool_from_env(QW_ENABLE_OPENTELEMETRY_OTLP_EXPORTER_ENV_KEY, false),
default_protocol: get_from_env(
enabled: quickwit_common::get_bool_from_env_cached!(
QW_ENABLE_OPENTELEMETRY_OTLP_EXPORTER_ENV_KEY,
false
),
default_protocol: quickwit_common::get_from_env_cached!(
String,
OTEL_EXPORTER_OTLP_PROTOCOL_ENV_KEY,
"grpc".to_string(),
false,
Expand Down
Loading