2013-06-17 7 views
0

Solr에서 색인 된 모델과 MySQL 데이터베이스가있는 Rails 3.2 응용 프로그램과 함께 작업하고 있습니다.sunspot : reindex 오류 - getaddrinfo : 노드 이름도 servname도 제공되지 않거나 알려지지 않음

을 나는 다음과 같은 명령을 실행하고 있습니다 :

여기 무슨 일이 일어나고 있는지의 (이 때마다 다른 비율 비록)이 400 만 개 기록의 색인 약 12 ​​% 후

RAILS_ENV=development bundle exec rake sunspot:reindex[1000] --trace 

을, 과정 필연적으로 다음 오류 및 스택 추적으로 폭탄이 튀어 나옵니다.

rake aborted! 
getaddrinfo: nodename nor servname provided, or not known 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:762:in `initialize' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:762:in `open' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:762:in `block in connect' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/timeout.rb:54:in `timeout' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/timeout.rb:99:in `timeout' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:762:in `connect' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:755:in `do_start' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:744:in `start' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:1284:in `request' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/connection.rb:15:in `execute' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/solr_instrumentation.rb:14:in `block in execute_with_as_instrumentation' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/solr_instrumentation.rb:12:in `execute_with_as_instrumentation' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:167:in `execute' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:161:in `send_and_receive' 
(eval):2:in `post' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:67:in `update' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:87:in `add' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/indexer.rb:106:in `add_documents' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/indexer.rb:30:in `add' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session.rb:91:in `index' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb:17:in `method_missing' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot.rb:184:in `index' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:261:in `block (2 levels) in solr_index' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:365:in `solr_benchmark' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:260:in `block in solr_index' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/batches.rb:72:in `find_in_batches' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/querying.rb:8:in `find_in_batches' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:259:in `solr_index' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:203:in `solr_reindex' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/tasks.rb:64:in `block (3 levels) in <top (required)>' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/class_set.rb:16:in `each' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/class_set.rb:16:in `each' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/tasks.rb:63:in `block (2 levels) in <top (required)>' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/bin/rake:23:in `load' 
/Users/tchapin/.rbenv/versions/1.9.3-p392/bin/rake:23:in `<main>' 

앱이 de velopment 모드는 localhost : 3000이고 solr은 localhost : 8982에서 실행 중입니다. 내 solr.rake 파일은 다음과 같습니다.

Rake::Task['sunspot:reindex'].enhance ['sunspot:scope_models_for_index'] 
Rake::Task['sunspot:solr:reindex'].enhance ['sunspot:scope_models_for_index'] 

namespace 'sunspot' do 
    task :scope_models_for_index => :environment do 
    require 'rsolr/error' 
    Dir.glob(Rails.root.join('app/models/**/*.rb')).each { |path| require path } 

    # Add the GC 
    commit_extension = Module.new do 
     def commit 
     GC.start 
     super 
     end 
    end 

    Sunspot.extend commit_extension 

    # Set all the models default scopes the index scope 
    Sunspot.searchable.each do |model| 
     model.class_eval do 
     default_scope ->{ sunspot_index } if model.respond_to?(:sunspot_index) 
     end 
    end 
    end 
end 

이 오류의 원인 또는 해결 방법은 누구나 알고 계십니까?

답변

1

명백하게 문제는 예외로 인한 것입니다. SocketError.

예외는 /Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/connection 파일에서 발생합니다. RB :

def execute client, request_context 
    h = http request_context[:uri], request_context[:proxy], request_context[:read_timeout], request_context[:open_timeout] 
    request = setup_raw_request request_context 
    request.body = request_context[:data] if request_context[:method] == :post and request_context[:data] 
    begin 
     response = h.request request 
     charset = response.type_params["charset"] 
     {:status => response.code.to_i, :headers => response.to_hash, :body => force_charset(response.body, charset)} 
    rescue Errno::ECONNREFUSED => e 
     raise(Errno::ECONNREFUSED.new(request_context.inspect)) 
    # catch the undefined closed? exception -- this is a confirmed ruby bug 
    rescue NoMethodError 
     $!.message == "undefined method `closed?' for nil:NilClass" ? 
     raise(Errno::ECONNREFUSED.new) : 
     raise($!) 
    end 
    end 

그것은 예쁜 수정이 아니라, 그것은 분명히 생산 코드에 대한 해결책이 아니다,하지만 일시적으로 그렇게처럼 소켓 오류 예외에 대한 구조 핸들러를 추가하여 문제를 해결할 수 있었다 :

def execute client, request_context 
    h = http request_context[:uri], request_context[:proxy], request_context[:read_timeout], request_context[:open_timeout] 
    request = setup_raw_request request_context 
    request.body = request_context[:data] if request_context[:method] == :post and request_context[:data] 
    retries = 10 
    begin 
     response = h.request request 
     charset = response.type_params["charset"] 
     {:status => response.code.to_i, :headers => response.to_hash, :body => force_charset(response.body, charset)} 
    rescue Errno::ECONNREFUSED => e 
     raise(Errno::ECONNREFUSED.new(request_context.inspect)) 
    # catch the undefined closed? exception -- this is a confirmed ruby bug 
    rescue NoMethodError 
     $!.message == "undefined method `closed?' for nil:NilClass" ? 
     raise(Errno::ECONNREFUSED.new) : 
     raise($!) 
    rescue SocketError => e 
     puts e 
     if retries > 0 
     puts "SocketError! Retrying connection after 1 second..." 
     retries -= 1 
     sleep(1) 
     retry 
     else 
     puts "SocketError: Not responding after 10 retries! Giving up!") 
     exit 
     end 
    end 
    end 

또한 Solr의 로컬 복사본에 메모리 부족 문제가있는 것 같습니다. 이에 따라 sunspot.yml 파일을 업데이트하여 메모리 문제를 해결했습니다.

development: 
    solr: 
    hostname: 127.0.0.1 
    port: 8982 
    min_memory: 512M 
    max_memory: 2G 
    log_level: INFO 
    # open_timeout: 3 
    # read_timeout: 3 
+0

와우, 인상적인 발견. 내 rsolr 제기 Errno : : ECONNREFUSED 다른 스레드에서 요청이 실패하고 있습니다. 다른 스레드에서 발생하기 때문에 컨트롤러에서 캡처 할 수도 없습니다. 나는 앱이 더 탄력적이어야하고 Solr이 다운 되었기 때문에 사용자에게 예외를 제기해서는 안된다고 생각한다. 다른 스레드에서 시작되는 모델 콜백에서 해당 예외를 캡처하는 방법을 알고 있습니까? – Chloe