From 9af03429f40bc8c9fcf8f680855c5c5c1fc4b2ad Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 12 Mar 2019 12:04:49 -0300 Subject: [PATCH 1/1] 13593: Cleans up old experimental code. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- services/api/app/models/group.rb | 2 +- services/api/app/models/link.rb | 2 +- services/api/app/models/user.rb | 11 ++--- services/api/config/application.default.yml | 6 --- services/api/script/permission-updater.rb | 47 --------------------- 5 files changed, 5 insertions(+), 63 deletions(-) delete mode 100755 services/api/script/permission-updater.rb diff --git a/services/api/app/models/group.rb b/services/api/app/models/group.rb index f4d5ec589d..46bb447d10 100644 --- a/services/api/app/models/group.rb +++ b/services/api/app/models/group.rb @@ -40,7 +40,7 @@ class Group < ArvadosModel def invalidate_permissions_cache # Ensure a new group can be accessed by the appropriate users # immediately after being created. - User.invalidate_permissions_cache db_current_time.to_i, self.async_permissions_update + User.invalidate_permissions_cache self.async_permissions_update end def assign_name diff --git a/services/api/app/models/link.rb b/services/api/app/models/link.rb index bf21cf4b67..ac3efe310d 100644 --- a/services/api/app/models/link.rb +++ b/services/api/app/models/link.rb @@ -68,7 +68,7 @@ class Link < ArvadosModel # permissions for head_uuid and tail_uuid, and invalidate the # cache for only those users. (This would require a browseable # cache.) - User.invalidate_permissions_cache db_current_time.to_i + User.invalidate_permissions_cache end end diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb index 2f3c6c89cb..8ed97e6b14 100644 --- a/services/api/app/models/user.rb +++ b/services/api/app/models/user.rb @@ -141,16 +141,11 @@ class User < ArvadosModel true end - def self.invalidate_permissions_cache(timestamp=nil, async=false) - if Rails.configuration.async_permissions_update - timestamp = DbCurrentTime::db_current_time.to_i if timestamp.nil? - connection.execute "NOTIFY invalidate_permissions_cache, '#{timestamp}'" - else - refresh_permission_view(async) - end + def self.invalidate_permissions_cache(async=false) + refresh_permission_view(async) end - def invalidate_permissions_cache(timestamp=nil) + def invalidate_permissions_cache User.invalidate_permissions_cache end diff --git a/services/api/config/application.default.yml b/services/api/config/application.default.yml index b752022824..8f0dbf4e49 100644 --- a/services/api/config/application.default.yml +++ b/services/api/config/application.default.yml @@ -496,12 +496,6 @@ common: # (included in vendor packages). package_version: false - # Enable asynchronous permission graph rebuild. Must run - # script/permission-updater.rb as a separate process. When the permission - # cache is invalidated, the background process will update the permission - # graph cache. This feature is experimental! - async_permissions_update: false - # Default value for container_count_max for container requests. This is the # number of times Arvados will create a new container to satisfy a container # request. If a container is cancelled it will retry a new container if diff --git a/services/api/script/permission-updater.rb b/services/api/script/permission-updater.rb deleted file mode 100755 index 985aa0542a..0000000000 --- a/services/api/script/permission-updater.rb +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) The Arvados Authors. All rights reserved. -# -# SPDX-License-Identifier: AGPL-3.0 - -ENV["RAILS_ENV"] = ARGV[0] || ENV["RAILS_ENV"] || "development" -require File.dirname(__FILE__) + '/../config/boot' -require File.dirname(__FILE__) + '/../config/environment' -include DbCurrentTime - -def update_permissions - timestamp = DbCurrentTime::db_current_time.to_i - Rails.logger.info "Begin updating permission cache" - User.all.each do |u| - u.calculate_group_permissions - end - Rails.cache.write "last_updated_permissions", timestamp - Rails.logger.info "Permission cache updated" -end - -ActiveRecord::Base.connection_pool.with_connection do |connection| - conn = connection.instance_variable_get(:@connection) - begin - conn.async_exec "LISTEN invalidate_permissions_cache" - - # Initial refresh of permissions graph - update_permissions - - while true - # wait_for_notify will block until there is a change - # notification from Postgres about the permission cache, - # and then rebuild the permission cache. - conn.wait_for_notify do |channel, pid, payload| - last_updated = Rails.cache.read("last_updated_permissions") - Rails.logger.info "Got notify #{payload} last update #{last_updated}" - if last_updated.nil? || last_updated.to_i <= payload.to_i - update_permissions - end - end - end - ensure - # Don't want the connection to still be listening once we return - # it to the pool - could result in weird behavior for the next - # thread to check it out. - conn.async_exec "UNLISTEN *" - end -end -- 2.30.2