cbrain
cbrain copied to clipboard
Race condition when creating new meta data keys
There's a tiny race condition when two processes try to create the same meta data key on the same object. The save! method raises an exception because the object trying to be created already exists.
The code is this method:
def set_attribute(mykey,myval) #:nodoc:
return delete_attribute(mykey) if myval.nil?
mykey = mykey.to_s
md = self.md_cache[mykey] || MetaDataStore.new( :ar_id => self.ar_id, :ar_table_name => self.ar_table_name, :meta_key => mykey )
md_cache[mykey] = md
if md.meta_value != myval
md.meta_value = myval
md.save!
end
myval
end
The solution might involved a ruby redo, or trying to reload the object, or ignoring altogether the exception!