Skip to main content

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#![cfg_attr(test, feature(test))]
21#![feature(trusted_len)]
22#![feature(allocator_api)]
23#![feature(coroutines)]
24#![feature(error_generic_member_access)]
25#![feature(portable_simd)]
26#![feature(once_cell_try)]
27#![allow(incomplete_features)]
28#![feature(iter_order_by)]
29#![feature(binary_heap_into_iter_sorted)]
30#![feature(negative_impls)]
31#![feature(register_tool)]
32#![feature(float_gamma)]
33#![feature(anonymous_lifetime_in_impl_trait)]
34#![feature(used_with_arg)]
35#![feature(iter_array_chunks)]
36#![feature(exact_size_is_empty)]
37#![feature(iter_from_coroutine)]
38#![register_tool(rw)]
39
40#[cfg_attr(not(test), allow(unused_extern_crates))]
41extern crate self as risingwave_common;
42
43// Re-export all macros from `risingwave_error` crate for code compatibility,
44// since they were previously defined and exported from `risingwave_common`.
45#[macro_use]
46extern crate risingwave_error;
47use std::sync::OnceLock;
48
49pub use risingwave_error::common::{
50    bail_no_function, bail_not_implemented, no_function, not_implemented,
51};
52pub use risingwave_error::macros::*;
53
54#[macro_use]
55pub mod jemalloc;
56#[macro_use]
57pub mod error;
58#[macro_use]
59pub mod array;
60#[macro_use]
61pub mod util;
62pub mod acl;
63pub mod bitmap;
64pub mod cache;
65pub mod cast;
66pub mod lru;
67pub mod operator;
68pub mod opts;
69pub mod range;
70pub mod row;
71pub mod sequence;
72pub mod session_config;
73pub mod system_param;
74
75pub mod catalog;
76pub mod config;
77pub mod constants;
78pub mod field_generator;
79pub mod gap_fill;
80pub mod global_jvm;
81pub mod hash;
82pub mod id {
83    pub use risingwave_pb::id::*;
84}
85pub mod memory;
86pub mod metrics_reader;
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_log as log;
100pub use risingwave_common_metrics as metrics;
101pub use risingwave_common_metrics::{
102    monitor, register_guarded_gauge_vec_with_registry,
103    register_guarded_histogram_vec_with_registry, register_guarded_int_counter_vec_with_registry,
104    register_guarded_int_gauge_vec_with_registry, register_guarded_uint_gauge_vec_with_registry,
105};
106pub use risingwave_common_secret as secret;
107pub use risingwave_license as license;
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
124pub static STATE_STORE_URL: OnceLock<String> = OnceLock::new();
125pub static DATA_DIRECTORY: OnceLock<String> = OnceLock::new();
126
127#[macro_export]
128macro_rules! git_sha {
129    ($env:literal) => {
130        match option_env!($env) {
131            Some(v) if !v.is_empty() => v,
132            _ => $crate::UNKNOWN_GIT_SHA,
133        }
134    };
135}
136
137// FIXME: We expand `unwrap_or` since it's unavailable in const context now.
138// `const_option_ext` was broken by https://github.com/rust-lang/rust/pull/110393
139// Tracking issue: https://github.com/rust-lang/rust/issues/91930
140pub const GIT_SHA: &str = git_sha!("GIT_SHA");
141
142pub fn current_cluster_version() -> String {
143    format!(
144        "PostgreSQL {}-RisingWave-{} ({})",
145        PG_VERSION, RW_VERSION, GIT_SHA
146    )
147}
148
149/// Panics if `debug_assertions` is set, otherwise logs a warning.
150///
151/// Note: unlike `panic` which returns `!`, this macro returns `()`,
152/// which cannot be used like `result.unwrap_or_else(|| panic_if_debug!(...))`.
153#[macro_export]
154macro_rules! panic_if_debug {
155    ($($arg:tt)*) => {
156        if cfg!(debug_assertions) {
157            panic!($($arg)*)
158        } else {
159            tracing::warn!($($arg)*)
160        }
161    };
162}