|
1 | 1 | //! A collection of replicas and a primary. |
2 | 2 |
|
3 | 3 | use parking_lot::Mutex; |
4 | | -use pgdog_config::{PreparedStatements, QueryParserEngine, QueryParserLevel, Rewrite, RewriteMode}; |
| 4 | +use pgdog_config::{ |
| 5 | + CrossShardBackend, PreparedStatements, QueryParserEngine, QueryParserLevel, Rewrite, |
| 6 | + RewriteMode, |
| 7 | +}; |
5 | 8 | use std::{ |
6 | 9 | sync::{ |
7 | 10 | atomic::{AtomicBool, AtomicUsize, Ordering}, |
@@ -76,6 +79,7 @@ pub struct Cluster { |
76 | 79 | lb_strategy: LoadBalancingStrategy, |
77 | 80 | rw_split: ReadWriteSplit, |
78 | 81 | fdw_lb: Option<FdwLoadBalancer>, |
| 82 | + cross_shard_backend: CrossShardBackend, |
79 | 83 | } |
80 | 84 |
|
81 | 85 | /// Sharding configuration from the cluster. |
@@ -148,6 +152,7 @@ pub struct ClusterConfig<'a> { |
148 | 152 | pub query_parser_engine: QueryParserEngine, |
149 | 153 | pub connection_recovery: ConnectionRecovery, |
150 | 154 | pub lsn_check_interval: Duration, |
| 155 | + pub cross_shard_backend: CrossShardBackend, |
151 | 156 | } |
152 | 157 |
|
153 | 158 | impl<'a> ClusterConfig<'a> { |
@@ -195,6 +200,7 @@ impl<'a> ClusterConfig<'a> { |
195 | 200 | query_parser_engine: general.query_parser_engine, |
196 | 201 | connection_recovery: general.connection_recovery, |
197 | 202 | lsn_check_interval: Duration::from_millis(general.lsn_check_interval), |
| 203 | + cross_shard_backend: general.cross_shard_backend, |
198 | 204 | } |
199 | 205 | } |
200 | 206 | } |
@@ -228,6 +234,7 @@ impl Cluster { |
228 | 234 | connection_recovery, |
229 | 235 | lsn_check_interval, |
230 | 236 | query_parser_engine, |
| 237 | + cross_shard_backend, |
231 | 238 | } = config; |
232 | 239 |
|
233 | 240 | let identifier = Arc::new(DatabaseUser { |
@@ -276,9 +283,12 @@ impl Cluster { |
276 | 283 | lb_strategy, |
277 | 284 | rw_split, |
278 | 285 | fdw_lb: None, |
| 286 | + cross_shard_backend, |
279 | 287 | }; |
280 | 288 |
|
281 | | - cluster.fdw_lb = FdwLoadBalancer::new(&cluster).ok(); |
| 289 | + if cross_shard_backend.need_fdw() { |
| 290 | + cluster.fdw_lb = FdwLoadBalancer::new(&cluster).ok(); |
| 291 | + } |
282 | 292 |
|
283 | 293 | cluster |
284 | 294 | } |
@@ -460,6 +470,10 @@ impl Cluster { |
460 | 470 | true |
461 | 471 | } |
462 | 472 |
|
| 473 | + pub fn cross_shard_backend(&self) -> CrossShardBackend { |
| 474 | + self.cross_shard_backend |
| 475 | + } |
| 476 | + |
463 | 477 | /// This database/user pair is responsible for schema management. |
464 | 478 | pub fn schema_admin(&self) -> bool { |
465 | 479 | self.schema_admin |
|
0 commit comments