Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Due to database collisions, retry when finding or creating a tag #809

Merged
merged 1 commit into from
May 3, 2017

Conversation

fearenales
Copy link
Contributor

This PR closes #693

Since the link posted by @adam-e-trepanier is returning 404, I just implemented a retrial strategy described by Mark Quezada in this blog post.

Any suggestions are welcome! :)

@fearenales fearenales changed the title Due to database collisions, retry while finding or creating a tag Due to database collisions, retry when finding or creating a tag Mar 2, 2017
@rbritom
Copy link
Contributor

rbritom commented May 3, 2017

@fearenales Ill add a test to this

@seuros
Copy link
Collaborator

seuros commented May 3, 2017

@rbritom Please add a reference in the Changelog too .

@seuros seuros merged commit f0a2e47 into mbleigh:master May 3, 2017
@jdelStrother
Copy link
Contributor

I think this approach causes silent data loss.

If you have two simultaneous processes which call TaggableModel.create!(tag_list: "hashtag"), afterwards you'd expect to have 2 TaggableModels stored in the database.
If one of those hits the rollback logic introduced in this PR, you've rolled back the INSERT INTO taggable_models, and nothing outside of the retry-loop knows anything about it. You're left with 1 TaggableModel and no indication that anything went wrong.

@fearenales WDYT?

@gmcnaughton
Copy link
Contributor

gmcnaughton commented Feb 27, 2018

I share @jdelStrother 's concern about data loss.

The ROLLBACK here will roll back whatever transaction you're in, undoing any changes made to the db during that transaction. For example:

transaction do
  u = User.create(...)
  u.tag_list.add("foo") # <= a collision here would undo the User.create
end

Out of curiosity, what's the reason for the ROLLBACK?

tekniklr pushed a commit to tekniklr/acts-as-taggable-on that referenced this pull request Mar 19, 2021
Due to database collisions, retry when finding or creating a tag
@jakswa
Copy link

jakswa commented Jul 12, 2023

Very surprising to me that this ROLLBACK is still in this gem since 2018, with multiple concerns/issues raised over the years. I'm thinking now that I gotta hunt for a way to remove this gem or replace it with another 😩.

@seuros
Copy link
Collaborator

seuros commented Jul 12, 2023

@jakswa or open a PR to fix it.

@jakswa
Copy link

jakswa commented Jul 12, 2023

@jakswa or open a PR to fix it.

@seuros it is open #1081

@seuros
Copy link
Collaborator

seuros commented Jul 12, 2023

@jakswa great.
Thanks. I will check it asap.

@jakswa
Copy link

jakswa commented Jul 12, 2023

Thank you. Sorry if my original comment came off too negative -- we have been troubleshooting borked transactions that led us to this ROLLBACK throwing away data sometimes (but reliably/persistent). If you have two new records getting tagged the same, new tag, you are risking one of those records being ROLLBACK'd silently :-\

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.

How to deal with race conditions caused by concurrency
6 participants