[ARVADOS] updated: 1a97222f80188c878cd1a57aa8c6620748b1db16

Git user git at public.curoverse.com
Thu Sep 14 15:14:47 EDT 2017


Summary of changes:
 .../20170906224040_materialized_permission_view.rb |  8 ++--
 services/api/db/structure.sql                      | 50 ++++++++++++++++++++++
 services/api/lib/can_be_an_owner.rb                |  1 +
 services/api/lib/refresh_permission_view.rb        |  5 ++-
 services/api/test/unit/arvados_model_test.rb       |  1 +
 5 files changed, 61 insertions(+), 4 deletions(-)

       via  1a97222f80188c878cd1a57aa8c6620748b1db16 (commit)
      from  42f4a3b622432c24538b0599edd32c21ca4e898f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 1a97222f80188c878cd1a57aa8c6620748b1db16
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Thu Sep 14 15:06:17 2017 -0400

    12032: Add permission_refresh_lock
    
    This ensures that when refreshing the permission view in a transaction, any
    other transactions affecting permissions will either be committed (so that
    results are visible to the refresh) or blocked (waiting to perform its own
    refresh).
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/api/db/migrate/20170906224040_materialized_permission_view.rb b/services/api/db/migrate/20170906224040_materialized_permission_view.rb
index 00eae79..b864f75 100644
--- a/services/api/db/migrate/20170906224040_materialized_permission_view.rb
+++ b/services/api/db/migrate/20170906224040_materialized_permission_view.rb
@@ -4,7 +4,7 @@
 
 class MaterializedPermissionView < ActiveRecord::Migration
 
-  @@idxtables = [:collections, :container_requests, :groups, :jobs, :links, :pipeline_instances, :pipeline_templates, :repositories, :users, :virtual_machines, :workflows]
+  @@idxtables = [:collections, :container_requests, :groups, :jobs, :links, :pipeline_instances, :pipeline_templates, :repositories, :users, :virtual_machines, :workflows, :logs]
 
   def up
 
@@ -101,14 +101,16 @@ SELECT user_uuid,
       ActiveRecord::Base.connection.execute("CREATE INDEX index_#{table.to_s}_on_modified_at_uuid ON #{table.to_s} USING btree (modified_at desc, uuid asc)")
     end
 
-    ActiveRecord::Base.connection.exec_query("REFRESH MATERIALIZED VIEW #{PERMISSION_VIEW}")
+    create_table :permission_refresh_lock
+    ActiveRecord::Base.connection.execute("REFRESH MATERIALIZED VIEW materialized_permission_view")
   end
 
   def down
+    drop_table :permission_refresh_lock
     remove_index :materialized_permission_view, name: 'permission_target_trashed'
     remove_index :materialized_permission_view, name: 'permission_target_user_trashed_level'
     @@idxtables.each do |table|
-      ActiveRecord::Base.connection.execute("DROP INDEX index_#{table.to_s}_on_modified_at_uuid")
+      ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_modified_at_uuid")
     end
     ActiveRecord::Base.connection.execute("DROP MATERIALIZED VIEW IF EXISTS materialized_permission_view")
   end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index b788749..d6b74df 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -880,6 +880,34 @@ ALTER SEQUENCE nodes_id_seq OWNED BY nodes.id;
 
 
 --
+-- Name: permission_refresh_lock; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE permission_refresh_lock (
+    id integer NOT NULL
+);
+
+
+--
+-- Name: permission_refresh_lock_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE permission_refresh_lock_id_seq
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+--
+-- Name: permission_refresh_lock_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE permission_refresh_lock_id_seq OWNED BY permission_refresh_lock.id;
+
+
+--
 -- Name: pipeline_instances; Type: TABLE; Schema: public; Owner: -
 --
 
@@ -1293,6 +1321,13 @@ ALTER TABLE ONLY nodes ALTER COLUMN id SET DEFAULT nextval('nodes_id_seq'::regcl
 
 
 --
+-- Name: permission_refresh_lock id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY permission_refresh_lock ALTER COLUMN id SET DEFAULT nextval('permission_refresh_lock_id_seq'::regclass);
+
+
+--
 -- Name: pipeline_instances id; Type: DEFAULT; Schema: public; Owner: -
 --
 
@@ -1485,6 +1520,14 @@ ALTER TABLE ONLY nodes
 
 
 --
+-- Name: permission_refresh_lock permission_refresh_lock_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY permission_refresh_lock
+    ADD CONSTRAINT permission_refresh_lock_pkey PRIMARY KEY (id);
+
+
+--
 -- Name: pipeline_instances pipeline_instances_pkey; Type: CONSTRAINT; Schema: public; Owner: -
 --
 
@@ -2179,6 +2222,13 @@ CREATE INDEX index_logs_on_modified_at ON logs USING btree (modified_at);
 
 
 --
+-- Name: index_logs_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_logs_on_modified_at_uuid ON logs USING btree (modified_at DESC, uuid);
+
+
+--
 -- Name: index_logs_on_object_owner_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
diff --git a/services/api/lib/can_be_an_owner.rb b/services/api/lib/can_be_an_owner.rb
index f5b2fe9..1a990e1 100644
--- a/services/api/lib/can_be_an_owner.rb
+++ b/services/api/lib/can_be_an_owner.rb
@@ -15,6 +15,7 @@ module CanBeAnOwner
     ActiveRecord::Base.connection.tables.each do |t|
       next if t == base.table_name
       next if t == 'schema_migrations'
+      next if t == 'permission_refresh_lock'
       klass = t.classify.constantize
       next unless klass and 'owner_uuid'.in?(klass.columns.collect(&:name))
       base.has_many(t.to_sym,
diff --git a/services/api/lib/refresh_permission_view.rb b/services/api/lib/refresh_permission_view.rb
index 4d3df7d..4ee45ab 100644
--- a/services/api/lib/refresh_permission_view.rb
+++ b/services/api/lib/refresh_permission_view.rb
@@ -5,5 +5,8 @@
 PERMISSION_VIEW = "materialized_permission_view"
 
 def refresh_permission_view
-  ActiveRecord::Base.connection.exec_query("REFRESH MATERIALIZED VIEW #{PERMISSION_VIEW}")
+  ActiveRecord::Base.transaction do
+    ActiveRecord::Base.connection.execute("LOCK TABLE permission_refresh_lock")
+    ActiveRecord::Base.connection.execute("REFRESH MATERIALIZED VIEW #{PERMISSION_VIEW}")
+  end
 end
diff --git a/services/api/test/unit/arvados_model_test.rb b/services/api/test/unit/arvados_model_test.rb
index 1e26798..c6b76c4 100644
--- a/services/api/test/unit/arvados_model_test.rb
+++ b/services/api/test/unit/arvados_model_test.rb
@@ -139,6 +139,7 @@ class ArvadosModelTest < ActiveSupport::TestCase
   test "search index exists on models that go into projects" do
     all_tables =  ActiveRecord::Base.connection.tables
     all_tables.delete 'schema_migrations'
+    all_tables.delete 'permission_refresh_lock'
 
     all_tables.each do |table|
       table_class = table.classify.constantize

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list