[ARVADOS] created: adf03c329338e04bc47bae7743c6af29f18af7dc

Git user git at public.curoverse.com
Mon Feb 13 13:43:46 EST 2017


        at  adf03c329338e04bc47bae7743c6af29f18af7dc (commit)


commit adf03c329338e04bc47bae7743c6af29f18af7dc
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Feb 13 13:40:31 2017 -0500

    11097: Reuse containers even if we can detect they are impure. Fix expensive "all readable collections" query.

diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 7731a8d..b6a16d1 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -94,31 +94,25 @@ class Container < ArvadosModel
     # Check for Completed candidates that had consistent outputs.
     completed = candidates.where(state: Complete).where(exit_code: 0)
     outputs = completed.select('output').group('output').limit(2)
-    if outputs.count.count != 1
-      Rails.logger.debug("Found #{outputs.count.length} different outputs")
-    elsif Collection.
-        readable_by(current_user).
-        where(portable_data_hash: outputs.first.output).
-        count < 1
+    output_count = outputs.count.count
+    if output_count > 0
+      if output_count > 1
+        Rails.logger.info("Found #{output_count} different outputs")
+      end
+      readable = Collection.readable_by(current_user)
+      completed.order('finished_at asc').select('uuid, log, output').
+        each do |candidate|
+        if readable.where('portable_data_hash in (?)',
+                          [candidate.output, candidate.log]).
+            select('portable_data_hash').
+            group('portable_data_hash').
+            count == 2
+          return Container.find_by_uuid(candidate.uuid)
+        end
+      end
       Rails.logger.info("Found reusable container(s) " +
-                        "but output #{outputs.first} is not readable " +
+                        "but none with both output and log readable " +
                         "by user #{current_user.uuid}")
-    else
-      # Return the oldest eligible container whose log is still
-      # present and readable by current_user.
-      readable_pdh = Collection.
-        readable_by(current_user).
-        select('portable_data_hash')
-      completed = completed.
-        where("log in (#{readable_pdh.to_sql})").
-        order('finished_at asc').
-        limit(1)
-      if completed.first
-        return completed.first
-      else
-        Rails.logger.info("Found reusable container(s) but none with a log " +
-                          "readable by user #{current_user.uuid}")
-      end
     end
 
     # Check for Running candidates and return the most likely to finish sooner.

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list