johnsonjh/jleveldb

View on GitHub
leveldb/db_write.go

Summary

Maintainability
D
1 day
Test Coverage

Method DB.writeLocked has a Cognitive Complexity of 42 (exceeds 20 allowed). Consider refactoring.
Open

func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
    // Try to flush memdb. This method would also trying to throttle writes
    // if it is too fast and compaction cannot catch-up.
    mdb, mdbFree, err := db.flush(batch.internalLen)
    if err != nil {
Severity: Minor
Found in leveldb/db_write.go - 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 DB.writeLocked has 75 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
    // Try to flush memdb. This method would also trying to throttle writes
    // if it is too fast and compaction cannot catch-up.
    mdb, mdbFree, err := db.flush(batch.internalLen)
    if err != nil {
Severity: Minor
Found in leveldb/db_write.go - About 2 hrs to fix

    Method DB.flush has 62 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (db *DB) flush(n int) (mdb *memDB, mdbFree int, err error) {
        delayed := false
        slowdownTrigger := db.s.o.GetWriteL0SlowdownTrigger()
        pauseTrigger := db.s.o.GetWriteL0PauseTrigger()
        // 请问您知道这里为什么要用匿名函数吗,我理解的是直接用循环就可以
    Severity: Minor
    Found in leveldb/db_write.go - About 1 hr to fix

      Method DB.Write has 10 return statements (exceeds 4 allowed).
      Open

      func (db *DB) Write(batch *Batch, wo *opt.WriteOptions) error {
          if err := db.ok(); err != nil || batch == nil || batch.Len() == 0 {
              return err
          }
      
      
      Severity: Major
      Found in leveldb/db_write.go - About 1 hr to fix

        Method DB.flush has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
        Open

        func (db *DB) flush(n int) (mdb *memDB, mdbFree int, err error) {
            delayed := false
            slowdownTrigger := db.s.o.GetWriteL0SlowdownTrigger()
            pauseTrigger := db.s.o.GetWriteL0PauseTrigger()
            // 请问您知道这里为什么要用匿名函数吗,我理解的是直接用循环就可以
        Severity: Minor
        Found in leveldb/db_write.go - 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

        Avoid deeply nested control flow statements.
        Open

                            if ourBatch == nil {
                                ourBatch = db.batchPool.Get().(*Batch)
                                ourBatch.Reset()
                                batches = append(batches, ourBatch)
                            }
        Severity: Major
        Found in leveldb/db_write.go - About 45 mins to fix

          Method DB.putRec has 7 return statements (exceeds 4 allowed).
          Open

          func (db *DB) putRec(kt keyType, key, value []byte, wo *opt.WriteOptions) error {
              if err := db.ok(); err != nil {
                  return err
              }
          
          
          Severity: Major
          Found in leveldb/db_write.go - About 45 mins to fix

            Method DB.CompactRange has 7 return statements (exceeds 4 allowed).
            Open

            func (db *DB) CompactRange(r util.Range) error {
                if err := db.ok(); err != nil {
                    return err
                }
            
            
            Severity: Major
            Found in leveldb/db_write.go - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if incoming.batch.internalLen > mergeLimit {
                                      overflow = true
                                      break merge
                                  }
              Severity: Major
              Found in leveldb/db_write.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if internalLen > mergeLimit {
                                        overflow = true
                                        break merge
                                    }
                Severity: Major
                Found in leveldb/db_write.go - About 45 mins to fix

                  Method DB.SetReadOnly has 6 return statements (exceeds 4 allowed).
                  Open

                  func (db *DB) SetReadOnly() error {
                      if err := db.ok(); err != nil {
                          return err
                      }
                  
                  
                  Severity: Major
                  Found in leveldb/db_write.go - About 40 mins to fix

                    Method DB.flush has 6 return statements (exceeds 4 allowed).
                    Open

                    func (db *DB) flush(n int) (mdb *memDB, mdbFree int, err error) {
                        delayed := false
                        slowdownTrigger := db.s.o.GetWriteL0SlowdownTrigger()
                        pauseTrigger := db.s.o.GetWriteL0PauseTrigger()
                        // 请问您知道这里为什么要用匿名函数吗,我理解的是直接用循环就可以
                    Severity: Major
                    Found in leveldb/db_write.go - About 40 mins to fix

                      Method DB.writeJournal has 5 return statements (exceeds 4 allowed).
                      Open

                      func (db *DB) writeJournal(batches []*Batch, seq uint64, sync bool) error {
                          wr, err := db.journal.Next()
                          if err != nil {
                              return err
                          }
                      Severity: Major
                      Found in leveldb/db_write.go - About 35 mins to fix

                        There are no issues that match your filters.

                        Category
                        Status