[Groonga-commit] droonga/droonga-engine at 52f9bbe [master] Count total number of source records asynchronously.

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Apr 14 12:16:41 JST 2015


YUKI Hiroshi	2015-04-14 12:16:41 +0900 (Tue, 14 Apr 2015)

  New Revision: 52f9bbeeba040d576f76c404d69bd8b27e1637a3
  https://github.com/droonga/droonga-engine/commit/52f9bbeeba040d576f76c404d69bd8b27e1637a3

  Message:
    Count total number of source records asynchronously.
    
    Because Cool.io's loop is already running and synchornous API tries to run Cool.io's loop again.

  Modified files:
    lib/droonga/plugins/system/absorb_data.rb

  Modified: lib/droonga/plugins/system/absorb_data.rb (+22 -14)
===================================================================
--- lib/droonga/plugins/system/absorb_data.rb    2015-04-14 11:50:49 +0900 (05b5541)
+++ lib/droonga/plugins/system/absorb_data.rb    2015-04-14 12:16:41 +0900 (fd825ac)
@@ -61,7 +61,10 @@ module Droonga
             @start_time = Time.now
 
             begin
-              @total_n_source_records = count_total_n_source_records
+              @total_n_source_records = nil
+              get_total_n_source_records do |count|
+                @total_n_source_records = count
+              end
               dumper_error_message = dumper.run do |message|
                 message["dataset"] = current_dataset
                 @messenger.forward(message,
@@ -176,9 +179,9 @@ module Droonga
                                   Catalog::Dataset::DEFAULT_NAME
           end
 
-          def source_tables
-            response = source_client.request("dataset" => source_dataset,
-                                             "type"    => "table_list")
+          def get_source_tables(&block)
+            source_client.request("dataset" => source_dataset,
+                                  "type"    => "table_list") do |response|
 
             unless response
               raise EmptyResponse.new("table_list returns nil response")
@@ -190,9 +193,12 @@ module Droonga
             message_body = response["body"]
             body = message_body[1]
             tables = body[1..-1]
-            tables.collect do |table|
+            table_names = tables.collect do |table|
               table[1]
             end
+            yield(table_names)
+
+            end
           end
 
           def source_client_options
@@ -216,7 +222,8 @@ module Droonga
             @source_client ||= Droonga::Client.new(source_client_options)
           end
 
-          def count_total_n_source_records
+          def get_total_n_source_records(&block)
+            get_source_tables do |source_tables|
             queries = {}
             source_tables.each do |table|
               queries["n_records_of_#{table}"] = {
@@ -226,13 +233,12 @@ module Droonga
                 },
               }
             end
-            response = source_client.request("dataset" => source_dataset,
-                                             "type"    => "search",
-                                             "body"    => {
-                                               "timeout" => 10,
-                                               "queries" => queries,
-                                             })
-
+            source_client.request("dataset" => source_dataset,
+                                  "type"    => "search",
+                                  "body"    => {
+                                    "timeout" => 10,
+                                    "queries" => queries,
+                                  }) do |response|
             unless response
               raise EmptyResponse.new("search returns nil response")
             end
@@ -244,7 +250,9 @@ module Droonga
             response["body"].each do |query_name, result|
               n_records += result["count"]
             end
-            n_records
+            yield(n_records)
+            end
+            end
           end
 
           def log_tag
-------------- next part --------------
HTML����������������������������...
Descargar 



More information about the Groonga-commit mailing list
Back to archive index