Skip to content

Commit

Permalink
refactor(frontend): Move some pg wire value into common and make they…
Browse files Browse the repository at this point in the history
… const (#14519)
  • Loading branch information
yufansong authored and Little-Wallace committed Jan 20, 2024
1 parent a856a2e commit 154e0e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
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. It is also the default value of `client_encoding`.
pub const SERVER_ENCODING: &str = "UTF8";
/// 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-{} ({})",
PG_VERSION, RW_VERSION, GIT_SHA
)
}
11 changes: 6 additions & 5 deletions src/common/src/session_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use self::non_zero64::ConfigNonZeroU64;
use crate::session_config::sink_decouple::SinkDecouple;
use crate::session_config::transaction_isolation_level::IsolationLevel;
pub use crate::session_config::visibility_mode::VisibilityMode;
use crate::{PG_VERSION, SERVER_ENCODING, SERVER_VERSION_NUM, STANDARD_CONFORMING_STRINGS};

pub const SESSION_CONFIG_LIST_SEP: &str = ", ";

Expand Down Expand Up @@ -175,19 +176,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 = SERVER_ENCODING, check_hook = check_client_encoding)]
client_encoding: String,

/// Enable decoupling sink and internal streaming graph or not
Expand Down Expand Up @@ -217,7 +218,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 +235,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 = SERVER_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::{PG_VERSION, SERVER_ENCODING, 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(SERVER_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

0 comments on commit 154e0e3

Please sign in to comment.