Skip to content

Destination Snowflake: add snowflake transaction wrapper for rollback support - #46989

Merged
Edward Gao (edgao) merged 11 commits into
airbytehq:masterfrom
zeev-finaloop:zeev-finaloop/destination-snowflake-transaction-handling-fix
Oct 31, 2024
Merged

Edward Gao (edgao) merged 11 commits into
airbytehq:masterfrom
zeev-finaloop:zeev-finaloop/destination-snowflake-transaction-handling-fix

Conversation

@zeev-finaloop

@zeev-finaloop zeev-finaloop commented Oct 18, 2024 •

Copy link
Copy Markdown
Contributor

What

This PR is solving transaction rollback in Snowflake.
Currently in destination-snowflake we may have corrupt state of data in the destination due to incorrect assumptions on snowflake transaction management.

fixes #46936

How

We have added a dedicated transactionally method for snowflake that wraps the transaction in a script block, catches an exceptions and rolls back the changes.

Review guide

  1. SnowflakeDestinationHandler.kt

User Impact

No visible impact

Can this PR be safely reverted and rolled back?

  • YES 💚
  • NO ❌

@zeev-finaloop
zeev-finaloop requested a review from a team as a code owner October 18, 2024 09:39
@vercel

vercel Bot commented Oct 18, 2024

Copy link
Copy Markdown

zeev-finaloop is attempting to deploy a commit to the Airbyte Growth Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Oct 18, 2024 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@natikgadzhi

Natik Gadzhi (natikgadzhi) commented Oct 18, 2024 •

Copy link
Copy Markdown
Contributor

/bump-version type="patch" changelog="Adding Snowflake transaction wrapper"

Bump Version job started... Check job output.

🔴 Job completed successfully (no changes, this is sus).

@natikgadzhi

Copy link
Copy Markdown
Contributor

Thank you for this!

I kicked off the CI and bumped the version of the connector. This needs a proper review from @airbytehq/destinations team.

@vercel

vercel Bot commented Oct 28, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
airbyte-docs ⬜️ Ignored (Inspect) Visit Preview Oct 31, 2024 6:51pm

@edgao Edward Gao (edgao) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this work if instead of manually wrapping the sql, you replace the sql.asSqlStrings (line 249) call with this: (I'm probably getting the syntax wrong, but approximately something like it)

val transactions = sql.asSqlStrings(
  "BEGIN; BEGIN TRANSACTION",
  """
  COMMIT;
  EXCEPTION
    WHEN OTHER THEN
      ROLLBACK;
      BEGIN
      RAISE;
        END;
  END;
  """.trimIndent()
)

@zeev-finaloop

Copy link
Copy Markdown
Contributor Author

does this work if instead of manually wrapping the sql, you replace the sql.asSqlStrings (line 249) call with this: (I'm probably getting the syntax wrong, but approximately something like it)

val transactions = sql.asSqlStrings(
  "BEGIN; BEGIN TRANSACTION",
  """
  COMMIT;
  EXCEPTION
    WHEN OTHER THEN
      ROLLBACK;
      BEGIN
      RAISE;
        END;
  END;
  """.trimIndent()
)

Edward Gao (@edgao) I think this may work with slight changes. I wanted to separate between transaction wrapping and snowflake script block wrapping. As I thought about it, sql.asSqlStrings would handle the transaction wrap and the new method adds the script block. Would you prefer me to implement as you suggested? I can make the change and run it

@edgao

Copy link
Copy Markdown
Contributor

yeah I think it would be preferable to use the same string-wrapper for both, to avoid future maintainers needing to notice the separate implementation

(obviously if it makes things really messy for some reason, we can go with what you have though)

@zeev-finaloop

Copy link
Copy Markdown
Contributor Author

yeah I think it would be preferable to use the same string-wrapper for both, to avoid future maintainers needing to notice the separate implementation

(obviously if it makes things really messy for some reason, we can go with what you have though)

change submitted, please trigger the pipeline

@edgao Edward Gao (edgao) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

M. Marx (@marcosmarxm) how do I trigger CI 😀

@marcosmarxm

Copy link
Copy Markdown
Contributor

Done for you

@edgao
Edward Gao (edgao) merged commit 96429ea into airbytehq:master Oct 31, 2024

This branch was successfully deployed

1 active (outdated) and 2 inactive deployments
community-ci-auto — 50ec9d98 Deployed Oct 31, 2024 by zeev-finaloop
community-ci — 50ec9d98 Deployed Oct 31, 2024 by zeev-finaloop
Preview — 93c2b878 Deployed Oct 28, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/connectors Connector related issues area/documentation Improvements or additions to documentation community connectors/destination/snowflake

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[destination-snowflake] incorrect transaction handling leads to missing data

6 participants