risingwave_common/
lib.rs

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