[ARVADOS] created: f40cef415e71c144c4c3b70dc7456e97561920d3

git at public.curoverse.com git at public.curoverse.com
Wed Dec 3 15:37:21 EST 2014


        at  f40cef415e71c144c4c3b70dc7456e97561920d3 (commit)


commit f40cef415e71c144c4c3b70dc7456e97561920d3
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed Dec 3 15:37:35 2014 -0500

    4533: Lock all tables before deleting contents.

diff --git a/services/api/app/controllers/database_controller.rb b/services/api/app/controllers/database_controller.rb
index a2e15ed..725e009 100644
--- a/services/api/app/controllers/database_controller.rb
+++ b/services/api/app/controllers/database_controller.rb
@@ -29,6 +29,12 @@ class DatabaseController < ApplicationController
     fixturesets = Dir.glob(Rails.root.join('test', 'fixtures', '*.yml')).
       collect { |yml| yml.match(/([^\/]*)\.yml$/)[1] }
 
+    # Avoid deadlock by locking all tables before doing anything
+    # drastic.
+    table_names = '"' + fixturesets.sort.join('","') + '"'
+    ActiveRecord::Base.connection.execute \
+      "LOCK TABLE #{table_names} IN SHARE ROW EXCLUSIVE MODE"
+
     # Delete existing fixtures (and everything else) from fixture
     # tables
     fixturesets.each do |x|

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list