risingwave_common/
lib.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![expect(
16    refining_impl_trait,
17    reason = "Some of the Row::iter() implementations returns ExactSizeIterator. Is this reasonable?"
18)]
19#![feature(trait_alias)]
20#![feature(type_alias_impl_trait)]
21#![feature(test)]
22#![feature(trusted_len)]
23#![feature(allocator_api)]
24#![feature(coroutines)]
25#![feature(map_try_insert)]
26#![feature(error_generic_member_access)]
27#![feature(portable_simd)]
28#![feature(once_cell_try)]
29#![allow(incomplete_features)]
30#![feature(iterator_try_collect)]
31#![feature(iter_order_by)]
32#![feature(binary_heap_into_iter_sorted)]
33#![feature(impl_trait_in_assoc_type)]
34#![feature(negative_impls)]
35#![feature(register_tool)]
36#![feature(btree_cursors)]
37#![feature(assert_matches)]
38#![feature(anonymous_lifetime_in_impl_trait)]
39#![feature(vec_into_raw_parts)]
40#![feature(exact_div)]
41#![feature(used_with_arg)]
42#![feature(iter_array_chunks)]
43#![feature(exact_size_is_empty)]
44#![feature(debug_closure_helpers)]
45#![feature(iter_from_coroutine)]
46#![register_tool(rw)]
47
48#[cfg_attr(not(test), allow(unused_extern_crates))]
49extern crate self as risingwave_common;
50
51// Re-export all macros from `risingwave_error` crate for code compatibility,
52// since they were previously defined and exported from `risingwave_common`.
53#[macro_use]
54extern crate risingwave_error;
55use std::sync::OnceLock;
56
57pub use risingwave_error::common::{
58    bail_no_function, bail_not_implemented, no_function, not_implemented,
59};
60pub use risingwave_error::macros::*;
61
62#[macro_use]
63pub mod jemalloc;
64#[macro_use]
65pub mod error;
66#[macro_use]
67pub mod array;
68#[macro_use]
69pub mod util;
70pub mod acl;
71pub mod bitmap;
72pub mod cache;
73pub mod cast;
74pub mod lru;
75pub mod operator;
76pub mod opts;
77pub mod range;
78pub mod row;
79pub mod sequence;
80pub mod session_config;
81pub mod system_param;
82
83pub mod catalog;
84pub mod config;
85pub mod constants;
86pub mod field_generator;
87pub mod gap_fill;
88pub mod global_jvm;
89pub mod hash;
90pub mod id {
91    pub use risingwave_pb::id::*;
92}
93pub mod memory;
94pub mod metrics_reader;
95pub mod telemetry;
96pub mod test_utils;
97pub mod transaction;
98pub mod types;
99pub mod vector;
100pub mod vnode_mapping;
101
102pub mod test_prelude {
103    pub use super::array::{DataChunkTestExt, StreamChunkTestExt};
104    pub use super::catalog::test_utils::ColumnDescTestExt;
105}
106
107pub use risingwave_common_metrics::{
108    monitor, register_guarded_gauge_vec_with_registry,
109    register_guarded_histogram_vec_with_registry, register_guarded_int_counter_vec_with_registry,
110    register_guarded_int_gauge_vec_with_registry, register_guarded_uint_gauge_vec_with_registry,
111};
112pub use {
113    risingwave_common_log as log, risingwave_common_metrics as metrics,
114    risingwave_common_secret as secret, risingwave_license as license,
115};
116
117pub const RW_VERSION: &str = env!("CARGO_PKG_VERSION");
118
119/// Placeholder for unknown git sha.
120pub const UNKNOWN_GIT_SHA: &str = "unknown";
121
122// The single source of truth of the pg parameters, Used in SessionConfig and current_cluster_version.
123// The version of PostgreSQL that Risingwave claims to be.
124pub const PG_VERSION: &str = "13.14.0";
125/// The version of PostgreSQL that Risingwave claims to be.
126pub const SERVER_VERSION_NUM: i32 = 130014;
127/// Shows the server-side character set encoding. At present, this parameter can be shown but not set, because the encoding is determined at database creation time. It is also the default value of `client_encoding`.
128pub const SERVER_ENCODING: &str = "UTF8";
129/// see <https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STANDARD-CONFORMING-STRINGS>
130pub const STANDARD_CONFORMING_STRINGS: &str = "on";
131
132pub static STATE_STORE_URL: OnceLock<String> = OnceLock::new();
133pub static DATA_DIRECTORY: OnceLock<String> = OnceLock::new();
134
135#[macro_export]
136macro_rules! git_sha {
137    ($env:literal) => {
138        match option_env!($env) {
139            Some(v) if !v.is_empty() => v,
140            _ => $crate::UNKNOWN_GIT_SHA,
141        }
142    };
143}
144
145// FIXME: We expand `unwrap_or` since it's unavailable in const context now.
146// `const_option_ext` was broken by https://github.com/rust-lang/rust/pull/110393
147// Tracking issue: https://github.com/rust-lang/rust/issues/91930
148pub const GIT_SHA: &str = git_sha!("GIT_SHA");
149
150pub fn current_cluster_version() -> String {
151    format!(
152        "PostgreSQL {}-RisingWave-{} ({})",
153        PG_VERSION, RW_VERSION, GIT_SHA
154    )
155}
156
157/// Panics if `debug_assertions` is set, otherwise logs a warning.
158///
159/// Note: unlike `panic` which returns `!`, this macro returns `()`,
160/// which cannot be used like `result.unwrap_or_else(|| panic_if_debug!(...))`.
161#[macro_export]
162macro_rules! panic_if_debug {
163    ($($arg:tt)*) => {
164        if cfg!(debug_assertions) {
165            panic!($($arg)*)
166        } else {
167            tracing::warn!($($arg)*)
168        }
169    };
170}