Skip to content

Commit

Permalink
Detect cyclic soruces by distributed search planner
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Dec 26, 2013
1 parent 3f2553f commit 9622b64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/droonga/plugin/distributor/distributed_search_planner.rb
Expand Up @@ -36,6 +36,10 @@ def initialize(search_request_message)
UNLIMITED = -1

def build_messages
if Searcher.have_circular_source?(@queries)
raise Searcher::CircularReferenceSource.new(@queries)
end

ensure_unifiable!

@queries.each do |input_name, query|
Expand Down
16 changes: 16 additions & 0 deletions lib/droonga/searcher.rb
Expand Up @@ -44,6 +44,22 @@ def initialize(queries)
end
end

class << self
def have_circular_source?(queries)
query_sorter = QuerySorter.new
queries.each do |name, query|
source = query["source"]
query_sorter.add(name, [source])
end
begin
sorted_queries = query_sorter.tsort
rescue TSort::Cyclic
return true
end
false
end
end

def initialize(context)
@context = context
end
Expand Down

0 comments on commit 9622b64

Please sign in to comment.