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#![register_tool(rw)]
46
47#[cfg_attr(not(test), allow(unused_extern_crates))]
48extern crate self as risingwave_common;
49
50// Re-export all macros from `risingwave_error` crate for code compatibility,
51// since they were previously defined and exported from `risingwave_common`.
52#[macro_use]
53extern crate risingwave_error;
54use std::sync::OnceLock;
55
56pub use risingwave_error::common::{
57    bail_no_function, bail_not_implemented, no_function, not_implemented,
58};
59pub use risingwave_error::macros::*;
60
61#[macro_use]
62pub mod jemalloc;
63#[macro_use]
64pub mod error;
65#[macro_use]
66pub mod array;
67#[macro_use]
68pub mod util;
69pub mod acl;
70pub mod bitmap;
71pub mod cache;
72pub mod cast;
73pub mod lru;
74pub mod operator;
75pub mod opts;
76pub mod range;
77pub mod row;
78pub mod sequence;
79pub mod session_config;
80pub mod system_param;
81
82pub mod catalog;
83pub mod config;
84pub mod constants;
85pub mod field_generator;
86pub mod gap_fill;
87pub mod global_jvm;
88pub mod hash;
89pub mod id {
90    pub use risingwave_pb::id::*;
91}
92pub mod memory;
93pub mod metrics_reader;
94pub mod telemetry;
95pub mod test_utils;
96pub mod transaction;
97pub mod types;
98pub mod vector;
99pub mod vnode_mapping;
100
101pub mod test_prelude {
102    pub use super::array::{DataChunkTestExt, StreamChunkTestExt};
103    pub use super::catalog::test_utils::ColumnDescTestExt;
104}
105
106pub use risingwave_common_metrics::{
107    monitor, register_guarded_gauge_vec_with_registry,
108    register_guarded_histogram_vec_with_registry, register_guarded_int_counter_vec_with_registry,
109    register_guarded_int_gauge_vec_with_registry, register_guarded_uint_gauge_vec_with_registry,
110};
111pub use {
112    risingwave_common_log as log, risingwave_common_metrics as metrics,
113    risingwave_common_secret as secret, risingwave_license as license,
114};
115
116pub const RW_VERSION: &str = env!("CARGO_PKG_VERSION");
117
118/// Placeholder for unknown git sha.
119pub const UNKNOWN_GIT_SHA: &str = "unknown";
120
121// The single source of truth of the pg parameters, Used in SessionConfig and current_cluster_version.
122// The version of PostgreSQL that Risingwave claims to be.
123pub const PG_VERSION: &str = "13.14.0";
124/// The version of PostgreSQL that Risingwave claims to be.
125pub const SERVER_VERSION_NUM: i32 = 130014;
126/// 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`.
127pub const SERVER_ENCODING: &str = "UTF8";
128/// see <https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STANDARD-CONFORMING-STRINGS>
129pub const STANDARD_CONFORMING_STRINGS: &str = "on";
130
131pub static STATE_STORE_URL: OnceLock<String> = OnceLock::new();
132pub static DATA_DIRECTORY: OnceLock<String> = OnceLock::new();
133
134#[macro_export]
135macro_rules! git_sha {
136    ($env:literal) => {
137        match option_env!($env) {
138            Some(v) if !v.is_empty() => v,
139            _ => $crate::UNKNOWN_GIT_SHA,
140        }
141    };
142}
143
144// FIXME: We expand `unwrap_or` since it's unavailable in const context now.
145// `const_option_ext` was broken by https://github.com/rust-lang/rust/pull/110393
146// Tracking issue: https://github.com/rust-lang/rust/issues/91930
147pub const GIT_SHA: &str = git_sha!("GIT_SHA");
148
149pub fn current_cluster_version() -> String {
150    format!(
151        "PostgreSQL {}-RisingWave-{} ({})",
152        PG_VERSION, RW_VERSION, GIT_SHA
153    )
154}
155
156/// Panics if `debug_assertions` is set, otherwise logs a warning.
157///
158/// Note: unlike `panic` which returns `!`, this macro returns `()`,
159/// which cannot be used like `result.unwrap_or_else(|| panic_if_debug!(...))`.
160#[macro_export]
161macro_rules! panic_if_debug {
162    ($($arg:tt)*) => {
163        if cfg!(debug_assertions) {
164            panic!($($arg)*)
165        } else {
166            tracing::warn!($($arg)*)
167        }
168    };
169}