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'
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
- Read upRead up
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)
- Read upRead up
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
Class Romad
has 28 methods (exceeds 20 allowed). Consider refactoring. Open
class Romad
include AsyncProcess
include WriteBehindProcess
attr :storages
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"
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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)
- Read upRead up
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"
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
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)
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
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
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)
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 &&
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
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
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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)
- Read upRead up
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
- Read upRead up
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)
- Read upRead up
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)
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76