Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/common/metrics/src/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn set_sampler_ratio(ratio: f64) -> anyhow::Result<()> {
}

fn resource() -> Resource {
let mut resource = Resource::builder()
let resource = Resource::builder()
.with_service_name(rivet_env::service_name())
.with_schema_url(
[KeyValue::new(SERVICE_VERSION, env!("CARGO_PKG_VERSION"))],
Expand Down
13 changes: 8 additions & 5 deletions packages/common/universaldb/src/driver/postgres/database.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::{
sync::{Arc, Mutex},
sync::{
Arc,
atomic::{AtomicI32, Ordering},
},
time::Duration,
};

Expand All @@ -23,7 +26,7 @@ const GC_INTERVAL: Duration = Duration::from_secs(5);

pub struct PostgresDatabaseDriver {
pool: Arc<Pool>,
max_retries: Arc<Mutex<i32>>,
max_retries: AtomicI32,
gc_handle: JoinHandle<()>,
}

Expand Down Expand Up @@ -162,7 +165,7 @@ impl PostgresDatabaseDriver {

Ok(PostgresDatabaseDriver {
pool: Arc::new(pool),
max_retries: Arc::new(Mutex::new(100)),
max_retries: AtomicI32::new(100),
gc_handle,
})
}
Expand All @@ -182,7 +185,7 @@ impl DatabaseDriver for PostgresDatabaseDriver {
) -> BoxFut<'a, Result<Erased>> {
Box::pin(async move {
let mut maybe_committed = MaybeCommitted(false);
let max_retries = *self.max_retries.lock().unwrap();
let max_retries = self.max_retries.load(Ordering::SeqCst);

for attempt in 0..max_retries {
let tx = self.create_trx()?;
Expand Down Expand Up @@ -227,7 +230,7 @@ impl DatabaseDriver for PostgresDatabaseDriver {
fn set_option(&self, opt: DatabaseOption) -> Result<()> {
match opt {
DatabaseOption::TransactionRetryLimit(limit) => {
*self.max_retries.lock().unwrap() = limit;
self.max_retries.store(limit, Ordering::SeqCst);
Ok(())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ impl TransactionDriver for PostgresTransactionDriver {

let (operations, conflict_ranges) = self.operations.consume();

// We have operations but no transaction - create one just for commit
let tx_sender = self.ensure_transaction().await?;

// Send commit command
Expand All @@ -250,8 +249,8 @@ impl TransactionDriver for PostgresTransactionDriver {
self.operations.clear_all();
self.committed.store(false, Ordering::SeqCst);

// Note: We can't reset the transaction once it's created
// The transaction task will continue running
// Replace tx sender to get a new txn version
self.tx_sender = OnceCell::new();
}

fn cancel(&self) {
Expand Down
Loading
Loading