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