lib/roma/romad.rb

Summary

Maintainability
F
1 wk
Test Coverage

File romad.rb has 692 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'optparse'
require 'roma/version'
require 'roma/stats'
require 'roma/command_plugin'
require 'roma/async_process'
Severity: Major
Found in lib/roma/romad.rb - About 1 day to fix

    Method start has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
    Open

        def start
          # config version check
          if !Config.const_defined?(:VERSION)
            @log.error("ROMA FAIL TO BOOT! : config.rb's version is too old.")
            exit
    Severity: Minor
    Found in lib/roma/romad.rb - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method async_send_cmd has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        def async_send_cmd(nid, cmd, tout=nil)
          con = res = nil
          if tout
            Timeout.timeout(tout){
              con = Roma::Messaging::ConPool.instance.get_connection(nid)
    Severity: Minor
    Found in lib/roma/romad.rb - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method start has 100 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def start
          # config version check
          if !Config.const_defined?(:VERSION)
            @log.error("ROMA FAIL TO BOOT! : config.rb's version is too old.")
            exit
    Severity: Major
    Found in lib/roma/romad.rb - About 4 hrs to fix

      Class Romad has 28 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class Romad
          include AsyncProcess
          include WriteBehindProcess
      
          attr :storages
      Severity: Minor
      Found in lib/roma/romad.rb - About 3 hrs to fix

        Method initialize_rttable has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize_rttable
              if @stats.join_ap
                initialize_rttable_join
              else
                fname = "#{Roma::Config::RTTABLE_PATH}/#{@stats.ap_str}.route"
        Severity: Minor
        Found in lib/roma/romad.rb - About 3 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method options has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            def options(argv)
              opts = OptionParser.new
              opts.banner="usage:#{File.basename($0)} [options] address"
        
              @stats.daemon = false
        Severity: Minor
        Found in lib/roma/romad.rb - About 3 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method start_sync_routing_process has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def start_sync_routing_process
              return if @stats.run_join || @stats.run_recover || @stats.run_balance || @stats.run_sync_routing
        
              nodes = @rttable.nodes
              return if nodes.length == 1 && nodes[0] == @stats.ap_str
        Severity: Minor
        Found in lib/roma/romad.rb - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method timer_event_10sec has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def timer_event_10sec
              if @startup && @rttable.enabled_failover == false
                @log.debug("nodes_check start")
                nodes=@rttable.nodes
                nodes.delete(@stats.ap_str)
        Severity: Minor
        Found in lib/roma/romad.rb - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method initialize_rttable has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def initialize_rttable
              if @stats.join_ap
                initialize_rttable_join
              else
                fname = "#{Roma::Config::RTTABLE_PATH}/#{@stats.ap_str}.route"
        Severity: Minor
        Found in lib/roma/romad.rb - About 1 hr to fix

          Method options has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def options(argv)
                opts = OptionParser.new
                opts.banner="usage:#{File.basename($0)} [options] address"
          
                @stats.daemon = false
          Severity: Minor
          Found in lib/roma/romad.rb - About 1 hr to fix

            Method timer_event_10sec has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def timer_event_10sec
                  if @startup && @rttable.enabled_failover == false
                    @log.debug("nodes_check start")
                    nodes=@rttable.nodes
                    nodes.delete(@stats.ap_str)
            Severity: Minor
            Found in lib/roma/romad.rb - About 1 hr to fix

              Method initialize_storages has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def initialize_storages
                    @storages = {}
                    if Config.const_defined? :STORAGE_PATH
                      path = "#{Roma::Config::STORAGE_PATH}/#{@stats.ap_str}"
                    end
              Severity: Minor
              Found in lib/roma/romad.rb - About 1 hr to fix

                Method start_sync_routing_process has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def start_sync_routing_process
                      return if @stats.run_join || @stats.run_recover || @stats.run_balance || @stats.run_sync_routing
                
                      nodes = @rttable.nodes
                      return if nodes.length == 1 && nodes[0] == @stats.ap_str
                Severity: Minor
                Found in lib/roma/romad.rb - About 1 hr to fix

                  Method async_send_cmd has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def async_send_cmd(nid, cmd, tout=nil)
                        con = res = nil
                        if tout
                          Timeout.timeout(tout){
                            con = Roma::Messaging::ConPool.instance.get_connection(nid)
                  Severity: Minor
                  Found in lib/roma/romad.rb - About 1 hr to fix

                    Consider simplifying this complex logical expression.
                    Open

                          if (@rttable.enabled_failover &&
                              @stats.run_storage_clean_up == false &&
                              @stats.run_balance == false &&
                              @stats.run_recover == false &&
                              @stats.run_iterate_storage == false &&
                    Severity: Critical
                    Found in lib/roma/romad.rb - About 1 hr to fix

                      Method initialize_rttable_join has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def initialize_rttable_join
                            name = async_send_cmd(@stats.join_ap,"whoami\r\n")
                            unless name
                              raise "No respons from #{@stats.join_ap}."
                            end
                      Severity: Minor
                      Found in lib/roma/romad.rb - About 1 hr to fix

                        Method initialize_storages has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def initialize_storages
                              @storages = {}
                              if Config.const_defined? :STORAGE_PATH
                                path = "#{Roma::Config::STORAGE_PATH}/#{@stats.ap_str}"
                              end
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 1 hr to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method initialize_rttable_join has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def initialize_rttable_join
                              name = async_send_cmd(@stats.join_ap,"whoami\r\n")
                              unless name
                                raise "No respons from #{@stats.join_ap}."
                              end
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 1 hr to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method routing_hash_comparison has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def routing_hash_comparison(nid,id='0')
                              return :skip if @stats.run_join || @stats.run_recover || @stats.run_balance
                        
                              h = async_send_cmd(nid,"mklhash #{id}\r\n")
                              if h && h.start_with?("ERROR") == false && @rttable.mtree.get(id) != h
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 55 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method initialize_connection has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def initialize_connection
                              if Config.const_defined?(:CONNECTION_CONTINUOUS_LIMIT)
                                unless Event::Handler.set_ccl(Config::CONNECTION_CONTINUOUS_LIMIT)
                                  raise "config parse error : Config::CONNECTION_CONTINUOUS_LIMIT"
                                end
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 55 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method receive_routing_dump has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def receive_routing_dump(nid, cmd)
                              con = Messaging::ConPool.instance.get_connection(nid)
                              con.write(cmd)
                              unless select [con], nil, nil, 1
                                con.close
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 45 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method async_broadcast_cmd has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def async_broadcast_cmd(cmd,without_nids=nil,tout=nil)
                              without_nids=[@stats.ap_str] unless without_nids
                              res = {}
                              @rttable.nodes.each{ |nid|
                                res[nid] = async_send_cmd(nid,cmd,tout) unless without_nids.include?(nid)
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 45 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method node_check has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def node_check(nid)
                              if @startup && @rttable.enabled_failover == false
                                unless Roma::Messaging::ConPool.instance.check_connection(nid)
                                  @log.info("I'm waiting for booting the #{nid} instance.")
                                  return false
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 45 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method initialize_stats has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def initialize_stats
                              if Config.const_defined?(:REDUNDANT_ZREDUNDANT_SIZE)
                                @stats.size_of_zredundant = Config::REDUNDANT_ZREDUNDANT_SIZE
                              end
                              if Config.const_defined?(:DATACOPY_STREAM_COPY_WAIT_PARAM)
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 45 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method timer_event_1sec has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def timer_event_1sec
                              if @rttable.enabled_failover
                                nodes=@rttable.nodes
                                nodes.delete(@stats.ap_str)
                                nodes_check(nodes)
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 35 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method version_check has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def version_check
                              nodes=@rttable.nodes
                              nodes.each{|nid|
                                vs = async_send_cmd(nid,"version\r\n",2)
                                next unless vs
                        Severity: Minor
                        Found in lib/roma/romad.rb - About 25 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                con = Roma::Messaging::ConPool.instance.get_connection(nid)
                                unless con
                                  @rttable.proc_failed(nid) if @rttable
                                  @log.error("#{__FILE__}:#{__LINE__}:#{nid} connection refused,command is #{cmd}.")
                                  return nil
                        Severity: Minor
                        Found in lib/roma/romad.rb and 1 other location - About 35 mins to fix
                        lib/roma/romad.rb on lines 737..744

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 36.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                  con = Roma::Messaging::ConPool.instance.get_connection(nid)
                                  unless con
                                    @rttable.proc_failed(nid) if @rttable
                                    @log.error("#{__FILE__}:#{__LINE__}:#{nid} connection refused,command is #{cmd}.")
                                    return nil
                        Severity: Minor
                        Found in lib/roma/romad.rb and 1 other location - About 35 mins to fix
                        lib/roma/romad.rb on lines 747..754

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 36.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        There are no issues that match your filters.

                        Category
                        Status