X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/98ec1f0093bb097f9ccb78ac43a9858f20084ad6..c7dfdc3f58e993abad5ef7fb898ac137cca62e02:/services/api/lib/update_permissions.rb diff --git a/services/api/lib/update_permissions.rb b/services/api/lib/update_permissions.rb index 4c2e72d955..23e60c8ed9 100644 --- a/services/api/lib/update_permissions.rb +++ b/services/api/lib/update_permissions.rb @@ -8,6 +8,8 @@ REVOKE_PERM = 0 CAN_MANAGE_PERM = 3 def update_permissions perm_origin_uuid, starting_uuid, perm_level, edge_id=nil + return if Thread.current[:suppress_update_permissions] + # # Update a subset of the permission table affected by adding or # removing a particular permission relationship (ownership or a @@ -60,10 +62,12 @@ def update_permissions perm_origin_uuid, starting_uuid, perm_level, edge_id=nil ActiveRecord::Base.transaction do - # "Conflicts with the ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE - # ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. This - # mode protects a table against concurrent data changes." - ActiveRecord::Base.connection.execute "LOCK TABLE #{PERMISSION_VIEW} in SHARE MODE" + # "Conflicts with the ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE + # EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS + # EXCLUSIVE lock modes. This mode allows only concurrent ACCESS + # SHARE locks, i.e., only reads from the table can proceed in + # parallel with a transaction holding this lock mode." + ActiveRecord::Base.connection.execute "LOCK TABLE #{PERMISSION_VIEW} in EXCLUSIVE MODE" # Workaround for # BUG #15160: planner overestimates number of rows in join when there are more than 200 rows coming from CTE @@ -140,7 +144,7 @@ end def check_permissions_against_full_refresh # No-op except when running tests - return unless Rails.env == 'test' and !Thread.current[:no_check_permissions_against_full_refresh] + return unless Rails.env == 'test' and !Thread.current[:no_check_permissions_against_full_refresh] and !Thread.current[:suppress_update_permissions] # For checking correctness of the incremental permission updates. # Check contents of the current 'materialized_permission' table @@ -191,6 +195,17 @@ def skip_check_permissions_against_full_refresh end end +def batch_update_permissions + check_perm_was = Thread.current[:suppress_update_permissions] + Thread.current[:suppress_update_permissions] = true + begin + yield + ensure + Thread.current[:suppress_update_permissions] = check_perm_was + refresh_permissions + end +end + # Used to account for permissions that a user gains by having # can_manage on another user. #