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