Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfbc9944

Browse files
Connection string config for replication.
Co-authored-by: Petros Angelatos <petrosagg@gmail.com>
1 parent786b4be commitfbc9944

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

‎tokio-postgres/src/config.rs‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ pub enum LoadBalanceHosts {
7272
Random,
7373
}
7474

75+
/// Replication mode configuration.
76+
///
77+
/// It is recommended that you use a PostgreSQL server patch version
78+
/// of at least: 14.0, 13.2, 12.6, 11.11, 10.16, 9.6.21, or
79+
/// 9.5.25. Earlier patch levels have a bug that doesn't properly
80+
/// handle pipelined requests after streaming has stopped.
81+
#[derive(Debug,Copy,Clone,PartialEq,Eq)]
82+
#[non_exhaustive]
83+
pubenumReplicationMode{
84+
/// Physical replication.
85+
Physical,
86+
/// Logical replication.
87+
Logical,
88+
}
89+
7590
/// A host specification.
7691
#[derive(Debug,Clone,PartialEq,Eq)]
7792
pubenumHost{
@@ -209,6 +224,7 @@ pub struct Config {
209224
pub(crate)target_session_attrs:TargetSessionAttrs,
210225
pub(crate)channel_binding:ChannelBinding,
211226
pub(crate)load_balance_hosts:LoadBalanceHosts,
227+
pub(crate)replication_mode:Option<ReplicationMode>,
212228
}
213229

214230
implDefaultforConfig{
@@ -242,6 +258,7 @@ impl Config {
242258
target_session_attrs:TargetSessionAttrs::Any,
243259
channel_binding:ChannelBinding::Prefer,
244260
load_balance_hosts:LoadBalanceHosts::Disable,
261+
replication_mode:None,
245262
}
246263
}
247264

@@ -524,6 +541,22 @@ impl Config {
524541
self.load_balance_hosts
525542
}
526543

544+
/// Set replication mode.
545+
///
546+
/// It is recommended that you use a PostgreSQL server patch version
547+
/// of at least: 14.0, 13.2, 12.6, 11.11, 10.16, 9.6.21, or
548+
/// 9.5.25. Earlier patch levels have a bug that doesn't properly
549+
/// handle pipelined requests after streaming has stopped.
550+
pubfnreplication_mode(&mutself,replication_mode:ReplicationMode) ->&mutConfig{
551+
self.replication_mode =Some(replication_mode);
552+
self
553+
}
554+
555+
/// Get replication mode.
556+
pubfnget_replication_mode(&self) ->Option<ReplicationMode>{
557+
self.replication_mode
558+
}
559+
527560
fnparam(&mutself,key:&str,value:&str) ->Result<(),Error>{
528561
match key{
529562
"user" =>{
@@ -660,6 +693,17 @@ impl Config {
660693
};
661694
self.load_balance_hosts(load_balance_hosts);
662695
}
696+
"replication" =>{
697+
let mode =match value{
698+
"off" =>None,
699+
"true" =>Some(ReplicationMode::Physical),
700+
"database" =>Some(ReplicationMode::Logical),
701+
_ =>returnErr(Error::config_parse(Box::new(InvalidValue("replication")))),
702+
};
703+
ifletSome(mode) = mode{
704+
self.replication_mode(mode);
705+
}
706+
}
663707
key =>{
664708
returnErr(Error::config_parse(Box::new(UnknownOption(
665709
key.to_string(),
@@ -744,6 +788,7 @@ impl fmt::Debug for Config {
744788
config_dbg
745789
.field("target_session_attrs",&self.target_session_attrs)
746790
.field("channel_binding",&self.channel_binding)
791+
.field("replication",&self.replication_mode)
747792
.finish()
748793
}
749794
}

‎tokio-postgres/src/connect_raw.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
usecrate::codec::{BackendMessage,BackendMessages,FrontendMessage,PostgresCodec};
2-
usecrate::config::{self,Config};
2+
usecrate::config::{self,Config,ReplicationMode};
33
usecrate::connect_tls::connect_tls;
44
usecrate::maybe_tls_stream::MaybeTlsStream;
55
usecrate::tls::{TlsConnect,TlsStream};
@@ -133,6 +133,12 @@ where
133133
ifletSome(application_name) =&config.application_name{
134134
params.push(("application_name",&**application_name));
135135
}
136+
ifletSome(replication_mode) =&config.replication_mode{
137+
match replication_mode{
138+
ReplicationMode::Physical => params.push(("replication","true")),
139+
ReplicationMode::Logical => params.push(("replication","database")),
140+
}
141+
}
136142

137143
letmut buf =BytesMut::new();
138144
frontend::startup_message(params,&mut buf).map_err(Error::encode)?;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp