Skip to content

Commit 6030b45

Browse files
committed
store: Create the state_racker in PoolInner::create
1 parent c7a49a9 commit 6030b45

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

store/postgres/src/pool/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,9 @@ impl ConnectionPool {
263263
registry: Arc<MetricsRegistry>,
264264
coord: Arc<PoolCoordinator>,
265265
) -> ConnectionPool {
266-
let state_tracker = StateTracker::new();
267266
let shard =
268267
Shard::new(shard_name.to_string()).expect("shard_name is a valid name for a shard");
269-
let inner = {
268+
let (inner, state_tracker) = {
270269
let pool = PoolInner::create(
271270
shard.clone(),
272271
pool_name.as_str(),
@@ -275,12 +274,12 @@ impl ConnectionPool {
275274
fdw_pool_size,
276275
logger,
277276
registry,
278-
state_tracker.clone(),
279277
);
278+
let state_tracker = pool.state_tracker.clone();
280279
if pool_name.is_replica() {
281-
PoolState::ready(Arc::new(pool))
280+
(PoolState::ready(Arc::new(pool)), state_tracker)
282281
} else {
283-
PoolState::created(Arc::new(pool), coord)
282+
(PoolState::created(Arc::new(pool), coord), state_tracker)
284283
}
285284
};
286285
ConnectionPool {
@@ -398,6 +397,7 @@ pub struct PoolInner {
398397
fdw_pool: Option<AsyncPool>,
399398
postgres_url: String,
400399
pub(crate) wait_stats: PoolWaitStats,
400+
state_tracker: StateTracker,
401401

402402
// Limits the number of graphql queries that may execute concurrently. Since one graphql query
403403
// may require multiple DB queries, it is useful to organize the queue at the graphql level so
@@ -417,7 +417,6 @@ impl PoolInner {
417417
fdw_pool_size: Option<u32>,
418418
logger: &Logger,
419419
registry: Arc<MetricsRegistry>,
420-
state_tracker: StateTracker,
421420
) -> PoolInner {
422421
check_mirrored_tables();
423422

@@ -429,6 +428,9 @@ impl PoolInner {
429428
map.insert("shard".to_string(), shard.to_string());
430429
map
431430
};
431+
432+
let state_tracker = StateTracker::new();
433+
432434
// Note: deadpool provides built-in metrics via pool.status()
433435
// The r2d2-style ErrorHandler and EventHandler are not needed with deadpool.
434436
// Metrics can be obtained from pool.status() and custom hooks can be added
@@ -532,6 +534,7 @@ impl PoolInner {
532534
pool,
533535
fdw_pool,
534536
wait_stats,
537+
state_tracker,
535538
semaphore_wait_stats: Arc::new(RwLock::new(MovingStats::default())),
536539
query_semaphore,
537540
semaphore_wait_gauge,

0 commit comments

Comments
 (0)