YUKI Hiroshi
null+****@clear*****
Thu Nov 28 10:09:58 JST 2013
YUKI Hiroshi 2013-11-28 10:09:58 +0900 (Thu, 28 Nov 2013) New Revision: 461c0d3845401d059051a6dc923c64e9d8a3a9df https://github.com/droonga/fluent-plugin-droonga/commit/461c0d3845401d059051a6dc923c64e9d8a3a9df Message: Override limit of distributed search requests correctly Modified files: lib/droonga/plugin/distributor/search.rb test/unit/plugin/distributor/test_search.rb Modified: lib/droonga/plugin/distributor/search.rb (+8 -7) =================================================================== --- lib/droonga/plugin/distributor/search.rb 2013-11-28 10:09:01 +0900 (f9821b2) +++ lib/droonga/plugin/distributor/search.rb 2013-11-28 10:09:58 +0900 (ce17042) @@ -115,22 +115,22 @@ module Droonga # we have to calculate limit based on offset. # <A, B = limited integer (0...MAXINT)> - # | sort | output | => | worker's sort limit | worker's output limit | final limit | - # ========================= ================================================================== - # | UNLIMITED | UNLIMITED | => | UNLIMITED | UNLIMITED | UNLIMITED | - # | UNLIMITED | B | => | final_offset + B | UNLIMITED | B | - # | A | UNLIMITED | => | final_offset + A | UNLIMITED | A | - # | A | B | => | final_offset + min(A, B) | UNLIMITED | min(A, B) | + # | sort | output | => | worker's sort limit | worker's output limit | final limit | + # ========================= ==================================================================== + # | UNLIMITED | UNLIMITED | => | UNLIMITED | UNLIMITED | UNLIMITED | + # | UNLIMITED | B | => | final_offset + B | final_offset + B | B | + # | A | UNLIMITED | => | final_offset + A | final_offset + A | A | + # | A | B | => | final_offset + min(A, B) | final_offset + min(A, B)| min(A, B) | sort_limit = UNLIMITED if rich_sort sort_limit = query["sortBy"]["limit"] || UNLIMITED end output_limit = query["output"]["limit"] || 0 - query["output"]["limit"] = UNLIMITED if have_records final_limit = 0 if sort_limit == UNLIMITED && output_limit == UNLIMITED final_limit = UNLIMITED + query["output"]["limit"] = UNLIMITED else if sort_limit == UNLIMITED final_limit = output_limit @@ -140,6 +140,7 @@ module Droonga final_limit = [sort_limit, output_limit].min end query["sortBy"]["limit"] = final_offset + final_limit if rich_sort + query["output"]["limit"] = final_offset + final_limit end [final_offset, final_limit] Modified: test/unit/plugin/distributor/test_search.rb (+164 -0) =================================================================== --- test/unit/plugin/distributor/test_search.rb 2013-11-28 10:09:01 +0900 (fbbd39e) +++ test/unit/plugin/distributor/test_search.rb 2013-11-28 10:09:58 +0900 (8832ae9) @@ -28,6 +28,170 @@ class SearchDistributorTest < Test::Unit::TestCase teardown_database end + def test_multiple_queries + envelope = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "query1" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "offset" => 0, + "limit" => 10, + }, + }, + "query2" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "offset" => 0, + "limit" => 20, + }, + }, + "query3" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "offset" => 0, + "limit" => 30, + }, + }, + }, + }, + } + + @plugin.process("search", envelope) + + message = [] + + message << { + "type" => "reduce", + "body" => { + "query1" => { + "query1_reduced" => { + "count" => { + "type" => "sum", + }, + "records" => { + "type" => "sort", + "order" => ["<"], + "offset" => 0, + "limit" => 10, + }, + }, + }, + }, + "inputs" => ["query1"], + "outputs" => ["query1_reduced"], + } + message << { + "type" => "reduce", + "body" => { + "query2" => { + "query2_reduced" => { + "count" => { + "type" => "sum", + }, + "records" => { + "type" => "sort", + "order" => ["<"], + "offset" => 0, + "limit" => 20, + }, + }, + }, + }, + "inputs" => ["query2"], + "outputs" => ["query2_reduced"], + } + message << { + "type" => "reduce", + "body" => { + "query3" => { + "query3_reduced" => { + "count" => { + "type" => "sum", + }, + "records" => { + "type" => "sort", + "order" => ["<"], + "offset" => 0, + "limit" => 30, + }, + }, + }, + }, + "inputs" => ["query3"], + "outputs" => ["query3_reduced"], + } + + gatherer = { + "type" => "gather", + "body" => { + "query1_reduced" => "query1", + "query2_reduced" => "query2", + "query3_reduced" => "query3", + }, + "inputs" => [ + "query1_reduced", + "query2_reduced", + "query3_reduced", + ], + "post" => true, + } + message << gatherer + + searcher = { + "type" => "broadcast", + "command" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "query1" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "offset" => 0, + "limit" => 10, + }, + }, + "query2" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "offset" => 0, + "limit" => 20, + }, + }, + "query3" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "offset" => 0, + "limit" => 30, + }, + }, + }, + }, + "outputs" => [ + "query1", + "query2", + "query3", + ], + "replica" => "random", + } + message << searcher + assert_equal(message, @posted.last.last) + end + def test_distribute envelope = { "type" => "search", -------------- next part -------------- HTML����������������������������... Descargar