Skip to content

Commit

Permalink
Merge pull request #188 from supabase/fix-read-only-txn
Browse files Browse the repository at this point in the history
fix: only update `wrappers_fdw_stats` table in a read-write transaction
  • Loading branch information
burmecia authored Nov 2, 2023
2 parents e7407c6 + abb7b70 commit be37e1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion wrappers/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions wrappers/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ fn get_stats_table() -> String {
.unwrap_or_else(|| panic!("cannot find fdw stats table '{}'", FDW_STATS_TABLE))
}

fn is_txn_read_only() -> bool {
Spi::get_one("show transaction_read_only") == Ok(Some("on"))
}

// increase stats value
#[allow(dead_code)]
pub(crate) fn inc_stats(fdw_name: &str, metric: Metric, inc: i64) {
if is_txn_read_only() {
return;
}

let sql = format!(
"insert into {} as s (fdw_name, {}) values($1, $2)
on conflict(fdw_name)
Expand Down Expand Up @@ -82,6 +90,10 @@ pub(crate) fn get_metadata(fdw_name: &str) -> Option<JsonB> {
// set metadata
#[allow(dead_code)]
pub(crate) fn set_metadata(fdw_name: &str, metadata: Option<JsonB>) {
if is_txn_read_only() {
return;
}

let sql = format!(
"insert into {} as s (fdw_name, metadata) values($1, $2)
on conflict(fdw_name)
Expand Down

0 comments on commit be37e1e

Please sign in to comment.