I have a bit code that looks all records in an array of unique keys, creates new records for all keys not found, and updates the records of the found records. There is a race condition, if another request tries the same thing at the same time with an overlapping array of keys, the inserts may fail because the other request did its inserts between the find and the inserts. My current solution is to just serialize all these requests, by that doesn''t scale very well. The only locking solution I can see is to lock the whole table. I suppose transactions could be used, but the thought of endless retries is not pleasant. Is there a way to do an update with any missing records created with default values? Or some other solution I''m not aware of? TIA, Jeffrey -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
did you try INSERT with IGNORE -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Jeffrey L. Taylor wrote:> I have a bit code that looks all records in an array of unique keys, > creates > new records for all keys not found, and updates the records of the found > records. There is a race condition, if another request tries the same > thing > at the same time with an overlapping array of keys, the inserts may fail > because the other request did its inserts between the find and the > inserts. > > My current solution is to just serialize all these requests, by that > doesn''t > scale very well. The only locking solution I can see is to lock the > whole > table. I suppose transactions could be used, but the thought of endless > retries is not pleasant. Is there a way to do an update with any > missing > records created with default values? Or some other solution I''m not > aware of?You *really* want transactions here.> > TIA, > JeffreyBest, -- Marnen Laibow-Koser marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.