def search_next_good(bad_idx)
        Orientdb4r::logger.warn "identified bad node, idx=#{bad_idx}, age=#{Time.now - @bad_nodes[bad_idx]} [s]"

        # alternative nodes of not found a good one
        timeout_candidate = nil

        # first round - try to find a first good one
        1.upto(nodes_count) do |i|
          candidate = (i + bad_idx) % nodes_count

          if @bad_nodes.include? candidate
            failure_time = @bad_nodes[candidate]
            now = Time.now
            # timeout candidate
            if (now - failure_time) > recover_time
              timeout_candidate = candidate
              Orientdb4r::logger.debug "node timeout recovery, idx=#{candidate}"
              good_one(candidate)
            end
          else
            Orientdb4r::logger.debug "found good node, idx=#{candidate}"
            return candidate
          end
        end

        # no good index found -> try timeouted one
        unless timeout_candidate.nil?
          Orientdb4r::logger.debug "good node not found, delivering timeouted one, idx=#{timeout_candidate}"
          return timeout_candidate
        end

        Orientdb4r::logger.error 'no nodes more, all invalid'
        nil
      end
def search_next_good(bad_idx)
        Orientdb4r::logger.warn "identified bad node, idx=#{bad_idx}, age=#{Time.now - @bad_nodes[bad_idx]} [s]"

        # alternative nodes of not found a good one
        timeout_candidate = nil

        # first round - try to find a first good one
        1.upto(nodes_count) do |i|
          candidate = (i + bad_idx) % nodes_count

          if @bad_nodes.include? candidate
            failure_time = @bad_nodes[candidate]
            now = Time.now
            # timeout candidate
            if (now - failure_time) > recover_time
              timeout_candidate = candidate
              Orientdb4r::logger.debug "node timeout recovery, idx=#{candidate}"
              good_one(candidate)
            end
          else
            Orientdb4r::logger.debug "found good node, idx=#{candidate}"
            return candidate
          end
        end

        # no good index found -> try timeouted one
        unless timeout_candidate.nil?
          Orientdb4r::logger.debug "good node not found, delivering timeouted one, idx=#{timeout_candidate}"
          return timeout_candidate
        end

        Orientdb4r::logger.error 'no nodes more, all invalid'
        nil
      end
Tries to find a new node if the given failed.
 Returns <i>nil</i> if no one found