Skip to content
  • Adrianna Chang's avatar
    eabcff22
    Retry known idempotent SELECT queries on connection-related exceptions · eabcff22
    Adrianna Chang authored
    This commit makes two types of queries retry-able by opting into our `allow_retry` flag:
    1) SELECT queries we construct by walking the Arel tree via `#to_sql_and_binds`. We use a
    new `retryable` attribute on collector classes, which defaults to true for most node types,
    but will be set to false for non-idempotent node types (functions, SQL literals, etc). The
    `retryable` value is returned from  `#to_sql_and_binds` and used by `#select_all` and
    passed down the call stack, eventually reaching the adapter's `#internal_exec_query` method.
    
    Internally-generated SQL literals are marked as retryable via a new `retryable` attribute on
    `Arel::Nodes::SqlLiteral`.
    
    2) `#find` and `#find_by` queries with known attributes. We set `allow_retry: true` in `#cached_find_by`,
    and pass this down to `#find_by_sql` and `#_query_by_sql`.
    
    These changes ensure that queries we know are safe to retry can be retried automatically.
    eabcff22
    Retry known idempotent SELECT queries on connection-related exceptions
    Adrianna Chang authored
    This commit makes two types of queries retry-able by opting into our `allow_retry` flag:
    1) SELECT queries we construct by walking the Arel tree via `#to_sql_and_binds`. We use a
    new `retryable` attribute on collector classes, which defaults to true for most node types,
    but will be set to false for non-idempotent node types (functions, SQL literals, etc). The
    `retryable` value is returned from  `#to_sql_and_binds` and used by `#select_all` and
    passed down the call stack, eventually reaching the adapter's `#internal_exec_query` method.
    
    Internally-generated SQL literals are marked as retryable via a new `retryable` attribute on
    `Arel::Nodes::SqlLiteral`.
    
    2) `#find` and `#find_by` queries with known attributes. We set `allow_retry: true` in `#cached_find_by`,
    and pass this down to `#find_by_sql` and `#_query_by_sql`.
    
    These changes ensure that queries we know are safe to retry can be retried automatically.
Loading