mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/retryable.rb

Summary

Maintainability
D
2 days
Test Coverage

Method write_with_retry has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    def write_with_retry(write_concern, ending_transaction: false, context:, &block)
      session = context.session

      if ending_transaction && !session
        raise ArgumentError, 'Cannot end a transaction without a session'
Severity: Minor
Found in lib/mongo/retryable.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

File retryable.rb has 274 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Mongo

  # Defines basic behavior around retrying operations.
  #
  # @since 2.1.0
Severity: Minor
Found in lib/mongo/retryable.rb - About 2 hrs to fix

    Method write_with_retry has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def write_with_retry(write_concern, ending_transaction: false, context:, &block)
          session = context.session
    
          if ending_transaction && !session
            raise ArgumentError, 'Cannot end a transaction without a session'
    Severity: Minor
    Found in lib/mongo/retryable.rb - About 1 hr to fix

      Method legacy_read_with_retry has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def legacy_read_with_retry(session, server_selector)
            attempt = 0
            server = select_server(cluster, server_selector, session)
            begin
              attempt += 1
      Severity: Minor
      Found in lib/mongo/retryable.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 legacy_read_with_retry has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def legacy_read_with_retry(session, server_selector)
            attempt = 0
            server = select_server(cluster, server_selector, session)
            begin
              attempt += 1
      Severity: Minor
      Found in lib/mongo/retryable.rb - About 1 hr to fix

        Method retry_write has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def retry_write(original_error, txn_num, context:, &block)
              session = context.session
        
              # We do not request a scan of the cluster here, because error handling
              # for the error which triggered the retry should have updated the
        Severity: Minor
        Found in lib/mongo/retryable.rb - About 1 hr to fix

          Method retry_read has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def retry_read(original_error, server_selector, session, &block)
                begin
                  server = select_server(cluster, server_selector, session)
                rescue Error, Error::AuthError => e
                  original_error.add_note("later retry failed: #{e.class}: #{e}")
          Severity: Minor
          Found in lib/mongo/retryable.rb - About 1 hr to fix

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

                def read_with_retry(session = nil, server_selector = nil, &block)
                  if session.nil? && server_selector.nil?
                    # Older versions of Mongoid call read_with_retry without arguments.
                    # This is already not correct in a MongoDB 3.6+ environment with
                    # sessions. For compatibility we emulate the legacy driver behavior
            Severity: Minor
            Found in lib/mongo/retryable.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 retry_read has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def retry_read(original_error, server_selector, session, &block)
                  begin
                    server = select_server(cluster, server_selector, session)
                  rescue Error, Error::AuthError => e
                    original_error.add_note("later retry failed: #{e.class}: #{e}")
            Severity: Minor
            Found in lib/mongo/retryable.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 legacy_write_with_retry has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def legacy_write_with_retry(server = nil, context:)
                  session = context.session
            
                  # This is the pre-session retry logic, and is not subject to
                  # current retryable write specifications.
            Severity: Minor
            Found in lib/mongo/retryable.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 retry_write_allowed? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def retry_write_allowed?(session, write_concern)
                  unless session && session.retry_writes?
                    return false
                  end
            
            
            Severity: Minor
            Found in lib/mongo/retryable.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 retry_write has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def retry_write(original_error, txn_num, context:, &block)
                  session = context.session
            
                  # We do not request a scan of the cluster here, because error handling
                  # for the error which triggered the retry should have updated the
            Severity: Minor
            Found in lib/mongo/retryable.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 modern_read_with_retry has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def modern_read_with_retry(session, server_selector, &block)
                  server = select_server(cluster, server_selector, session)
                  begin
                    yield server
                  rescue Error::SocketError, Error::SocketTimeoutError => e
            Severity: Minor
            Found in lib/mongo/retryable.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

            There are no issues that match your filters.

            Category
            Status