Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(frontend): Move some pg wire value into common and make them const #14519

Merged
merged 7 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ pub const RW_VERSION: &str = env!("CARGO_PKG_VERSION");
/// Placeholder for unknown git sha.
pub const UNKNOWN_GIT_SHA: &str = "unknown";

// The single source of truth of the pg parameters, Used in ConfigMap and current_cluster_version.
// The version of PostgreSQL that Risingwave claims to be.
pub const PG_VERSION: &str = "9.5.0";
/// The version of PostgreSQL that Risingwave claims to be.
pub const SERVER_VERSION_NUM: i32 = 90500;
/// 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.
pub const CLIENT_ENCODING: &str = "UTF8";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment does not match the name. Let's rename it to SERVER_ENCODING and add "it is also the default for CLIENT_ENCODING"

https://www.postgresql.org/docs/16/runtime-config-preset.html#GUC-SERVER-ENCODING
https://www.postgresql.org/docs/16/runtime-config-client.html#GUC-CLIENT-ENCODING

/// see <https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STANDARD-CONFORMING-STRINGS>
pub const STANDARD_CONFORMING_STRINGS: &str = "on";

#[macro_export]
macro_rules! git_sha {
($env:literal) => {
Expand All @@ -107,5 +117,8 @@ macro_rules! git_sha {
pub const GIT_SHA: &str = git_sha!("GIT_SHA");

pub fn current_cluster_version() -> String {
format!("PostgreSQL 9.5-RisingWave-{} ({})", RW_VERSION, GIT_SHA)
format!(
"PostgreSQL {}-RisingWave-{} ({})",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hzxa21 FYI there would be an extra .0 starting next release

-       PostgreSQL 9.5-RisingWave-1.6.0 (abc)
+       PostgreSQL 9.5.0-RisingWave-1.7.0 (def)

PG_VERSION, RW_VERSION, GIT_SHA
)
}
13 changes: 8 additions & 5 deletions src/common/src/session_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ mod visibility_mode;
use chrono_tz::Tz;
pub use over_window::OverWindowCachePolicy;
pub use query_mode::QueryMode;
use risingwave_common::{
CLIENT_ENCODING, PG_VERSION, SERVER_VERSION_NUM, STANDARD_CONFORMING_STRINGS,
};
use risingwave_common_proc_macro::SessionConfig;
pub use search_path::{SearchPath, USER_NAME_WILD_CARD};
use thiserror::Error;
Expand Down Expand Up @@ -175,19 +178,19 @@ pub struct ConfigMap {
batch_parallelism: ConfigNonZeroU64,

/// The version of PostgreSQL that Risingwave claims to be.
#[parameter(default = "9.5.0")]
#[parameter(default = PG_VERSION)]
server_version: String,

/// The version of PostgreSQL that Risingwave claims to be.
#[parameter(default = 90500)]
#[parameter(default = SERVER_VERSION_NUM)]
server_version_num: i32,

/// see <https://www.postgresql.org/docs/15/runtime-config-client.html#GUC-CLIENT-MIN-MESSAGES>
#[parameter(default = "notice")]
client_min_messages: String,

/// see <https://www.postgresql.org/docs/15/runtime-config-client.html#GUC-CLIENT-ENCODING>
#[parameter(default = "UTF8", check_hook = check_client_encoding)]
#[parameter(default = CLIENT_ENCODING , check_hook = check_client_encoding)]
client_encoding: String,

/// Enable decoupling sink and internal streaming graph or not
Expand Down Expand Up @@ -217,7 +220,7 @@ pub struct ConfigMap {
row_security: bool,

/// see <https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STANDARD-CONFORMING-STRINGS>
#[parameter(default = "on")]
#[parameter(default = STANDARD_CONFORMING_STRINGS)]
standard_conforming_strings: String,

/// Set streaming rate limit (rows per second) for each parallelism for mv backfilling
Expand All @@ -234,7 +237,7 @@ pub struct ConfigMap {
background_ddl: bool,

/// 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.
#[parameter(default = "UTF8")]
#[parameter(default = CLIENT_ENCODING)]
server_encoding: String,

#[parameter(default = "hex", check_hook = check_bytea_output)]
Expand Down
7 changes: 4 additions & 3 deletions src/utils/pgwire/src/pg_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use openssl::ssl::{SslAcceptor, SslContext, SslContextRef, SslMethod};
use risingwave_common::types::DataType;
use risingwave_common::util::panic::FutureCatchUnwindExt;
use risingwave_common::util::query_log::*;
use risingwave_common::{CLIENT_ENCODING, PG_VERSION, STANDARD_CONFORMING_STRINGS};
use risingwave_sqlparser::ast::Statement;
use risingwave_sqlparser::parser::Parser;
use thiserror_ext::AsReport;
Expand Down Expand Up @@ -973,13 +974,13 @@ where

fn write_parameter_status_msg_no_flush(&mut self, status: &ParameterStatus) -> io::Result<()> {
self.write_no_flush(&BeMessage::ParameterStatus(
BeParameterStatusMessage::ClientEncoding("UTF8"),
BeParameterStatusMessage::ClientEncoding(CLIENT_ENCODING),
))?;
self.write_no_flush(&BeMessage::ParameterStatus(
BeParameterStatusMessage::StandardConformingString("on"),
BeParameterStatusMessage::StandardConformingString(STANDARD_CONFORMING_STRINGS),
))?;
self.write_no_flush(&BeMessage::ParameterStatus(
BeParameterStatusMessage::ServerVersion("9.5.0"),
BeParameterStatusMessage::ServerVersion(PG_VERSION),
))?;
if let Some(application_name) = &status.application_name {
self.write_no_flush(&BeMessage::ParameterStatus(
Expand Down
Loading