Skip to content

Conversation

MasterPtato
Copy link
Contributor

Changes

Copy link
Contributor Author

MasterPtato commented Jun 3, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Adds SQL query retry mechanism with exponential backoff and improves memory efficiency across the codebase.

  • Added retry logic in sql_query_macros.rs with 100ms base retry and max 16 retries
  • Removed MaxSqlRetries error variant from WorkflowError in favor of macro-level retry handling
  • Renamed query to txn in database drivers for better semantic clarity
  • Added reference operators (&) to SQL query parameters across multiple services to prevent unnecessary cloning
  • Simplified transaction retry logic to use consistent backoff for all database errors

12 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 2001 to 2012
if is_retrying.load(Ordering::Relaxed) {
self.query(|| async {
sql_execute!(
[self, &pool]
"
DELETE FROM workflow_signal_events
WHERE location = jsonb(?1)
",
location,
)
.await
})
sql_execute!(
[self, &pool]
"
DELETE FROM workflow_signal_events
WHERE location = jsonb(?1)
",
location,
)
.await
.map_err(|x| fdb::FdbBindingError::CustomError(x.into()))?;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Potential race condition: the DELETE operation should be in the same transaction as the INSERT to maintain atomicity

Comment on lines +153 to +158
let mut backoff = $crate::__rivet_util::Backoff::new(
4,
None,
$crate::utils::sql_query_macros::QUERY_RETRY_MS,
50
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Backoff parameters are inconsistent - base=4 and factor=50 here vs QUERY_RETRY_MS=100 defined at the top. Consider aligning these values or documenting why they differ.

Comment on lines +185 to +186
Database(_) | Io(_) | Tls(_) | Protocol(_) | PoolTimedOut | PoolClosed
| WorkerCrashed => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding RowNotFound to non-retryable errors since retrying won't help if the row doesn't exist

Suggested change
Database(_) | Io(_) | Tls(_) | Protocol(_) | PoolTimedOut | PoolClosed
| WorkerCrashed => {
Database(_) | Io(_) | Tls(_) | Protocol(_) | PoolTimedOut | PoolClosed
| WorkerCrashed | RowNotFound => {

Copy link

cloudflare-workers-and-pages bot commented Jun 3, 2025

Deploying rivet with  Cloudflare Pages  Cloudflare Pages

Latest commit: c307626
Status: ✅  Deploy successful!
Preview URL: https://758a1d78.rivet.pages.dev
Branch Preview URL: https://06-03-feat-add-retries-to-sq.rivet.pages.dev

View logs

@MasterPtato MasterPtato force-pushed the 06-03-feat_add_retries_to_sql_macros branch from 200c987 to b3eae4a Compare June 4, 2025 00:34
Copy link

cloudflare-workers-and-pages bot commented Jun 4, 2025

Deploying rivet-studio with  Cloudflare Pages  Cloudflare Pages

Latest commit: c307626
Status: ✅  Deploy successful!
Preview URL: https://bb342d1e.rivet-studio.pages.dev
Branch Preview URL: https://06-03-feat-add-retries-to-sq.rivet-studio.pages.dev

View logs

Copy link

cloudflare-workers-and-pages bot commented Jun 4, 2025

Deploying rivet-hub with  Cloudflare Pages  Cloudflare Pages

Latest commit: c307626
Status: ✅  Deploy successful!
Preview URL: https://6498ef2a.rivet-hub-7jb.pages.dev
Branch Preview URL: https://06-03-feat-add-retries-to-sq.rivet-hub-7jb.pages.dev

View logs

@NathanFlurry NathanFlurry force-pushed the 06-03-feat_add_retries_to_sql_macros branch from 4fc5f51 to 406d6f9 Compare June 5, 2025 00:58
@NathanFlurry NathanFlurry force-pushed the 06-03-fix_add_create_ts_to_server_list branch from 7666132 to 20eace2 Compare June 5, 2025 00:58
@MasterPtato MasterPtato force-pushed the 06-03-fix_add_create_ts_to_server_list branch from 20eace2 to b77a826 Compare June 5, 2025 02:10
@MasterPtato MasterPtato force-pushed the 06-03-feat_add_retries_to_sql_macros branch from 406d6f9 to d44c0b9 Compare June 5, 2025 02:10
Copy link
Contributor

graphite-app bot commented Jun 9, 2025

Merge activity

  • Jun 9, 4:46 PM UTC: MasterPtato added this pull request to the Graphite merge queue.
  • Jun 9, 4:48 PM UTC: CI is running for this pull request on a draft pull request (#2574) due to your merge queue CI optimization settings.
  • Jun 9, 4:49 PM UTC: Merged by the Graphite merge queue via draft PR: #2574.

graphite-app bot pushed a commit that referenced this pull request Jun 9, 2025
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
@graphite-app graphite-app bot closed this Jun 9, 2025
@graphite-app graphite-app bot deleted the 06-03-feat_add_retries_to_sql_macros branch June 9, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant