reinhardt-db 0.1.0

Django-style database layer for Reinhardt framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
//! PostgreSQL-specific Two-Phase Commit implementation
//!
//! This module implements the `TwoPhaseParticipant` trait for PostgreSQL using
//! the PREPARE TRANSACTION, COMMIT PREPARED, and ROLLBACK PREPARED SQL commands.

use chrono::{DateTime, Utc};
use sqlx::{PgPool, Postgres, Row, pool::PoolConnection};
use std::sync::Arc;

use crate::backends::error::{DatabaseError, Result};

/// Session for a PostgreSQL two-phase commit transaction
///
/// Owns a dedicated database connection for the entire lifecycle of the transaction.
/// This ensures that BEGIN, all data modifications, and PREPARE TRANSACTION execute
/// on the same connection, which is required for correct 2PC semantics.
pub struct PgSession {
	/// The dedicated PostgreSQL connection for this transaction
	pub connection: PoolConnection<Postgres>,
	/// The transaction identifier
	pub xid: String,
	/// Current state of the transaction
	pub state: PgTwoPhaseState,
}

/// State of a PostgreSQL two-phase transaction
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PgTwoPhaseState {
	/// Transaction is active (after BEGIN)
	Active,
	/// Transaction has been prepared (after PREPARE TRANSACTION)
	Prepared,
}

/// PostgreSQL Two-Phase Commit participant
///
/// Manages two-phase commit transactions using PostgreSQL's PREPARE TRANSACTION feature.
///
/// # Requirements
///
/// PostgreSQL must be configured with `max_prepared_transactions > 0` (default is 0).
///
/// # Two-Phase Transaction Flow
///
/// 1. BEGIN - Start a transaction
/// 2. ... perform operations ...
/// 3. PREPARE TRANSACTION 'xid' - Prepare the transaction
/// 4. COMMIT PREPARED 'xid' or ROLLBACK PREPARED 'xid' - Finalize
///
/// # Examples
///
/// ```no_run
/// use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
/// use sqlx::PgPool;
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let pool = PgPool::connect("postgres://localhost/mydb").await?;
/// let participant = PostgresTwoPhaseParticipant::new(pool);
///
/// // Start a transaction and get a session
/// let mut session = participant.begin("txn_001").await?;
///
/// // ... perform operations using session.connection ...
///
/// // Prepare the transaction
/// participant.prepare(&mut session).await?;
///
/// // Commit the prepared transaction
/// participant.commit(session).await?;
/// # Ok(())
/// # }
/// ```
#[derive(Clone)]
pub struct PostgresTwoPhaseParticipant {
	pool: Arc<PgPool>,
	// Internal session storage for ORM layer compatibility
	// XID -> Session mapping for managing active transactions
	sessions: Arc<std::sync::Mutex<std::collections::HashMap<String, PgSession>>>,
}

impl PostgresTwoPhaseParticipant {
	/// Create a new PostgreSQL two-phase commit participant
	///
	/// # Examples
	///
	/// ```no_run
	/// use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// use sqlx::PgPool;
	///
	/// # async fn example() -> Result<(), sqlx::Error> {
	/// let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// let participant = PostgresTwoPhaseParticipant::new(pool);
	/// # Ok(())
	/// # }
	/// ```
	pub fn new(pool: PgPool) -> Self {
		Self {
			pool: Arc::new(pool),
			sessions: Arc::new(std::sync::Mutex::new(std::collections::HashMap::new())),
		}
	}

	/// Create from an `Arc<PgPool>`
	pub fn from_pool_arc(pool: Arc<PgPool>) -> Self {
		Self {
			pool,
			sessions: Arc::new(std::sync::Mutex::new(std::collections::HashMap::new())),
		}
	}

	/// Get a reference to the underlying PgPool
	///
	/// This method is useful for tests and advanced use cases where direct
	/// access to the pool is required.
	pub fn pool(&self) -> &PgPool {
		self.pool.as_ref()
	}

	/// Begin a transaction and return a session
	///
	/// Acquires a dedicated connection from the pool and starts a transaction.
	/// The returned session owns this connection for the entire transaction lifetime.
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// let mut session = participant.begin("txn_001").await?;
	/// // ... perform operations using session.connection ...
	/// # Ok(())
	/// # }
	/// ```
	pub async fn begin(&self, xid: &str) -> Result<PgSession> {
		// Acquire dedicated connection for the transaction
		let mut connection = self.pool.acquire().await.map_err(DatabaseError::from)?;

		// Start transaction on the dedicated connection
		sqlx::query("BEGIN")
			.execute(&mut *connection)
			.await
			.map_err(DatabaseError::from)?;

		Ok(PgSession {
			connection,
			xid: xid.to_string(),
			state: PgTwoPhaseState::Active,
		})
	}

	/// Prepare a transaction for two-phase commit
	///
	/// This executes `PREPARE TRANSACTION 'xid'` in PostgreSQL.
	/// Transitions the session state from Active to Prepared.
	///
	/// # Errors
	///
	/// Returns an error if:
	/// - The transaction is not active
	/// - `max_prepared_transactions` is set to 0
	/// - The transaction ID already exists
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// let mut session = participant.begin("txn_001").await?;
	/// // ... perform operations using session.connection ...
	/// participant.prepare(&mut session).await?;
	/// # Ok(())
	/// # }
	/// ```
	pub async fn prepare(&self, session: &mut PgSession) -> Result<()> {
		let xid_escaped = pg_escape::quote_literal(&session.xid);
		let sql = format!("PREPARE TRANSACTION {}", xid_escaped);
		sqlx::raw_sql(&sql)
			.execute(&mut *session.connection)
			.await
			.map_err(DatabaseError::from)?;

		session.state = PgTwoPhaseState::Prepared;
		Ok(())
	}

	/// Commit a prepared transaction
	///
	/// This executes `COMMIT PREPARED 'xid'` in PostgreSQL. Consumes the session.
	///
	/// # Errors
	///
	/// Returns an error if the prepared transaction does not exist.
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// let mut session = participant.begin("txn_001").await?;
	/// participant.prepare(&mut session).await?;
	/// participant.commit(session).await?;
	/// # Ok(())
	/// # }
	/// ```
	pub async fn commit(&self, mut session: PgSession) -> Result<()> {
		let xid_escaped = pg_escape::quote_literal(&session.xid);
		let sql = format!("COMMIT PREPARED {}", xid_escaped);
		sqlx::raw_sql(&sql)
			.execute(&mut *session.connection)
			.await
			.map_err(DatabaseError::from)?;

		// Session is consumed and connection is dropped
		Ok(())
	}

	/// Commit a prepared transaction by XID (for recovery scenarios)
	///
	/// This executes `COMMIT PREPARED 'xid'` in PostgreSQL using a new connection.
	/// Use this for recovery scenarios where you don't have the original session.
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// // Recovery scenario: commit by XID directly
	/// participant.commit_by_xid("txn_001").await?;
	/// # Ok(())
	/// # }
	/// ```
	pub async fn commit_by_xid(&self, xid: &str) -> Result<()> {
		let mut conn = self.pool.acquire().await.map_err(DatabaseError::from)?;
		let xid_escaped = pg_escape::quote_literal(xid);
		let sql = format!("COMMIT PREPARED {}", xid_escaped);
		sqlx::raw_sql(&sql)
			.execute(&mut *conn)
			.await
			.map_err(DatabaseError::from)?;
		Ok(())
	}

	/// Rollback a prepared transaction
	///
	/// This executes `ROLLBACK PREPARED 'xid'` in PostgreSQL. Consumes the session.
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// let mut session = participant.begin("txn_001").await?;
	/// participant.prepare(&mut session).await?;
	/// participant.rollback(session).await?;
	/// # Ok(())
	/// # }
	/// ```
	pub async fn rollback(&self, mut session: PgSession) -> Result<()> {
		let xid_escaped = pg_escape::quote_literal(&session.xid);
		let sql = format!("ROLLBACK PREPARED {}", xid_escaped);
		sqlx::raw_sql(&sql)
			.execute(&mut *session.connection)
			.await
			.map_err(DatabaseError::from)?;

		// Session is consumed and connection is dropped
		Ok(())
	}

	/// Rollback a prepared transaction by XID (for recovery scenarios)
	///
	/// This executes `ROLLBACK PREPARED 'xid'` in PostgreSQL using a new connection.
	/// Use this for recovery scenarios where you don't have the original session.
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// // Recovery scenario: rollback by XID directly
	/// participant.rollback_by_xid("txn_001").await?;
	/// # Ok(())
	/// # }
	/// ```
	pub async fn rollback_by_xid(&self, xid: &str) -> Result<()> {
		let mut conn = self.pool.acquire().await.map_err(DatabaseError::from)?;
		let xid_escaped = pg_escape::quote_literal(xid);
		let sql = format!("ROLLBACK PREPARED {}", xid_escaped);
		sqlx::raw_sql(&sql)
			.execute(&mut *conn)
			.await
			.map_err(DatabaseError::from)?;
		Ok(())
	}

	/// Query all prepared transactions from pg_prepared_xacts
	///
	/// Returns a list of prepared transaction IDs. This is useful for recovery
	/// scenarios where you need to find orphaned prepared transactions.
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// let prepared_txns = participant.list_prepared_transactions().await?;
	/// for txn_info in prepared_txns {
	///     println!("Prepared transaction: {}", txn_info.gid);
	/// }
	/// # Ok(())
	/// # }
	/// ```
	pub async fn list_prepared_transactions(&self) -> Result<Vec<PreparedTransactionInfo>> {
		let rows = sqlx::query(
			"SELECT gid, prepared, owner, database FROM pg_prepared_xacts ORDER BY prepared",
		)
		.fetch_all(self.pool.as_ref())
		.await
		.map_err(DatabaseError::from)?;

		let mut transactions = Vec::new();
		for row in rows {
			transactions.push(PreparedTransactionInfo {
				gid: row.try_get("gid").map_err(DatabaseError::from)?,
				prepared: row.try_get("prepared").map_err(DatabaseError::from)?,
				owner: row.try_get("owner").map_err(DatabaseError::from)?,
				database: row.try_get("database").map_err(DatabaseError::from)?,
			});
		}

		Ok(transactions)
	}

	/// Recover a specific prepared transaction
	///
	/// This is a convenience method that checks if a transaction is prepared
	/// and returns its information.
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// if let Some(info) = participant.find_prepared_transaction("txn_001").await? {
	///     println!("Found prepared transaction: {:?}", info);
	///     // Decide whether to commit or rollback
	///     participant.commit_by_xid("txn_001").await?;
	/// }
	/// # Ok(())
	/// # }
	/// ```
	pub async fn find_prepared_transaction(
		&self,
		xid: &str,
	) -> Result<Option<PreparedTransactionInfo>> {
		let row = sqlx::query(
			"SELECT gid, prepared, owner, database FROM pg_prepared_xacts WHERE gid = $1",
		)
		.bind(xid)
		.fetch_optional(self.pool.as_ref())
		.await
		.map_err(DatabaseError::from)?;

		if let Some(row) = row {
			Ok(Some(PreparedTransactionInfo {
				gid: row.try_get("gid").map_err(DatabaseError::from)?,
				prepared: row.try_get("prepared").map_err(DatabaseError::from)?,
				owner: row.try_get("owner").map_err(DatabaseError::from)?,
				database: row.try_get("database").map_err(DatabaseError::from)?,
			}))
		} else {
			Ok(None)
		}
	}

	/// Cleanup stale prepared transactions older than the specified duration
	///
	/// This is useful for recovering from failures where prepared transactions
	/// were abandoned. Use with caution as this may affect in-progress distributed
	/// transactions.
	///
	/// # Examples
	///
	/// ```no_run
	/// # use reinhardt_db::backends::drivers::postgresql::two_phase::PostgresTwoPhaseParticipant;
	/// # use sqlx::PgPool;
	/// # use std::time::Duration;
	/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
	/// # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
	/// # let participant = PostgresTwoPhaseParticipant::new(pool);
	/// // Rollback transactions older than 1 hour
	/// let cleaned = participant.cleanup_stale_transactions(Duration::from_secs(3600)).await?;
	/// println!("Cleaned up {} stale transactions", cleaned);
	/// # Ok(())
	/// # }
	/// ```
	pub async fn cleanup_stale_transactions(&self, max_age: std::time::Duration) -> Result<usize> {
		let max_age_secs = max_age.as_secs() as i32;
		let rows = sqlx::query(
			"SELECT gid FROM pg_prepared_xacts
             WHERE EXTRACT(EPOCH FROM (NOW() - prepared)) > $1",
		)
		.bind(max_age_secs)
		.fetch_all(self.pool.as_ref())
		.await
		.map_err(DatabaseError::from)?;

		let mut cleaned = 0;
		for row in rows {
			let gid: String = row.try_get("gid").map_err(DatabaseError::from)?;
			if self.rollback_by_xid(&gid).await.is_ok() {
				cleaned += 1;
			}
		}

		Ok(cleaned)
	}

	/// Acquire the sessions mutex lock with poison recovery and logging
	///
	/// On poison, clears all sessions to prevent inconsistent state and returns
	/// an error if the state cannot be recovered.
	fn acquire_sessions_lock(
		sessions: &std::sync::Mutex<std::collections::HashMap<String, PgSession>>,
	) -> Result<std::sync::MutexGuard<'_, std::collections::HashMap<String, PgSession>>> {
		match sessions.lock() {
			Ok(guard) => Ok(guard),
			Err(poisoned) => {
				tracing::warn!(
					"2PC sessions mutex was poisoned, clearing all sessions to prevent inconsistent state"
				);
				let mut guard = poisoned.into_inner();
				guard.clear();
				Ok(guard)
			}
		}
	}

	// XID-based wrapper methods for ORM layer compatibility
	// These methods manage sessions internally using the sessions HashMap

	/// Begin a transaction by XID (ORM layer wrapper)
	///
	/// Creates a session and stores it internally for later use.
	pub async fn begin_by_xid(&self, xid: &str) -> Result<()> {
		let session = self.begin(xid).await?;
		let mut sessions = Self::acquire_sessions_lock(&self.sessions)?;
		sessions.insert(xid.to_string(), session);
		Ok(())
	}

	/// Prepare a transaction by XID (ORM layer wrapper)
	///
	/// Executes PREPARE TRANSACTION without exposing the session to the caller.
	pub async fn prepare_by_xid(&self, xid: &str) -> Result<()> {
		// Extract the session temporarily to avoid holding the lock across await
		let mut session = {
			let mut sessions = Self::acquire_sessions_lock(&self.sessions)?;
			sessions.remove(xid).ok_or_else(|| {
				DatabaseError::QueryError(format!("No active session for XID: {}", xid))
			})?
		};

		// Perform the prepare operation directly without calling self.prepare()
		let xid_escaped = pg_escape::quote_literal(xid);
		let sql = format!("PREPARE TRANSACTION {}", xid_escaped);
		sqlx::raw_sql(&sql)
			.execute(&mut *session.connection)
			.await
			.map_err(DatabaseError::from)?;

		// Update state and re-insert
		session.state = PgTwoPhaseState::Prepared;
		let mut sessions = Self::acquire_sessions_lock(&self.sessions)?;
		sessions.insert(xid.to_string(), session);

		Ok(())
	}

	/// Commit a transaction by XID (ORM layer wrapper)
	///
	/// Removes the session from internal storage, executes COMMIT PREPARED, and consumes the session.
	pub async fn commit_managed(&self, xid: &str) -> Result<()> {
		let mut session = Self::acquire_sessions_lock(&self.sessions)?
			.remove(xid)
			.ok_or_else(|| {
				DatabaseError::QueryError(format!("No active session for XID: {}", xid))
			})?;

		// Execute commit directly without calling self.commit()
		let xid_escaped = pg_escape::quote_literal(xid);
		let sql = format!("COMMIT PREPARED {}", xid_escaped);
		sqlx::raw_sql(&sql)
			.execute(&mut *session.connection)
			.await
			.map_err(DatabaseError::from)?;

		// Session is consumed and connection is dropped
		Ok(())
	}

	/// Rollback a transaction by XID (ORM layer wrapper)
	///
	/// Removes the session from internal storage, executes ROLLBACK PREPARED, and consumes the session.
	pub async fn rollback_managed(&self, xid: &str) -> Result<()> {
		let mut session = Self::acquire_sessions_lock(&self.sessions)?
			.remove(xid)
			.ok_or_else(|| {
				DatabaseError::QueryError(format!("No active session for XID: {}", xid))
			})?;

		// Execute rollback directly without calling self.rollback()
		let xid_escaped = pg_escape::quote_literal(xid);
		let sql = format!("ROLLBACK PREPARED {}", xid_escaped);
		sqlx::raw_sql(&sql)
			.execute(&mut *session.connection)
			.await
			.map_err(DatabaseError::from)?;

		// Session is consumed and connection is dropped
		Ok(())
	}
}

/// Information about a prepared transaction
#[derive(Debug, Clone, PartialEq)]
pub struct PreparedTransactionInfo {
	/// Global transaction identifier
	pub gid: String,
	/// Timestamp when the transaction was prepared (with timezone)
	pub prepared: DateTime<Utc>,
	/// Owner (role) of the transaction
	pub owner: String,
	/// Database name
	pub database: String,
}

#[cfg(test)]
mod tests {
	use super::*;

	#[test]
	fn test_prepared_transaction_info_creation() {
		let info = PreparedTransactionInfo {
			gid: "txn_001".to_string(),
			prepared: DateTime::UNIX_EPOCH,
			owner: "postgres".to_string(),
			database: "testdb".to_string(),
		};

		assert_eq!(info.gid, "txn_001");
		assert_eq!(info.owner, "postgres");
		assert_eq!(info.database, "testdb");
	}

	#[tokio::test]
	async fn test_participant_clone() {
		// Test that PostgresTwoPhaseParticipant can be cloned
		// This is important for use in multi-threaded contexts
		let pool = Arc::new(
			PgPool::connect_lazy("postgresql://localhost/testdb")
				.expect("Failed to create lazy pool"),
		);
		let participant1 = PostgresTwoPhaseParticipant::from_pool_arc(pool.clone());
		let participant2 = participant1.clone();

		// Both should reference the same pool
		assert!(Arc::ptr_eq(&participant1.pool, &participant2.pool));
	}
}