johnsonjh/jleveldb

View on GitHub

Showing 166 of 166 total issues

Avoid deeply nested control flow statements.
Open

                    if i.dir == dirSOI || i.icmp.uCompare(ukey, i.key) > 0 {
                        i.key = append(i.key[:0], ukey...)
                        i.value = append(i.value[:0], i.iter.Value()...)
                        i.dir = dirForward
                        return true
Severity: Major
Found in leveldb/db_iter.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

      Method Writer.Close has 7 return statements (exceeds 4 allowed).
      Open

      func (w *Writer) Close() error {
          if w.err != nil {
              return w.err
          }
      
      
      Severity: Major
      Found in leveldb/table/writer.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            goto cont
        Severity: Major
        Found in leveldb/db_iter.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if !del {
                                  i.key = append(i.key[:0], ukey...)
                                  i.value = append(i.value[:0], i.iter.Value()...)
                              }
          Severity: Major
          Found in leveldb/db_iter.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if overlaps.size() > int64(v.s.o.GetCompactionGPOverlaps(level)) {
                                    break
                                }
            Severity: Major
            Found in leveldb/version.go - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if setFunc == nil {
                                      n.mu.Unlock()
                                      n.unref()
                                      return nil
                                  }
              Severity: Major
              Found in leveldb/cache/cache.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

                  Avoid deeply nested control flow statements.
                  Open

                                      if err := b.flush(b.stash(hasLastUkey, lastUkey, lastSeq, i)); err != nil {
                                          return err
                                      }
                  Severity: Major
                  Found in leveldb/db_compaction.go - About 45 mins 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

                    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 atomic.AddUint32(sizeHalfPtr, 1) == 20 {
                                              atomic.StoreUint32(sizePtr, uint32(cap(b)/2))
                                              atomic.StoreUint32(sizeHalfPtr, 0)
                                          } else {
                                              select {
                      Severity: Major
                      Found in leveldb/util/buffer_pool.go - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                        } else if v.levels[pLevel].overlaps(v.s.icmp, umin, umax, false) {
                                            break
                                        }
                        Severity: Major
                        Found in leveldb/version.go - About 45 mins to fix

                          Function NewReader has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          func NewReader(f io.ReaderAt, size int64, fd storage.FileDesc, cache *cache.NamespaceGetter, bpool *util.BufferPool, o *opt.Options) (*Reader, error) {
                          Severity: Minor
                          Found in leveldb/table/reader.go - About 45 mins to fix

                            Method indexedIterator.Prev has 7 return statements (exceeds 4 allowed).
                            Open

                            func (i *indexedIterator) Prev() bool {
                                if i.err != nil {
                                    return false
                                } else if i.Released() {
                                    i.err = ErrIterReleased
                            Severity: Major
                            Found in leveldb/iterator/indexed_iter.go - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                  if n.value == nil {
                                                      n.size = 0
                                                      n.mu.Unlock()
                                                      n.unref()
                                                      return nil
                              Severity: Major
                              Found in leveldb/cache/cache.go - About 45 mins to fix

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

                                func (tf tFiles) searchMinUkey(icmp *iComparer, umin []byte) int {
                                    return sort.Search(len(tf), func(i int) bool {
                                        return icmp.ucmp.Compare(tf[i].imin.ukey(), umin) > 0
                                    })
                                }
                                Severity: Minor
                                Found in leveldb/table.go and 1 other location - About 45 mins to fix
                                leveldb/table.go on lines 161..165

                                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 113.

                                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

                                func (tf tFiles) searchMaxUkey(icmp *iComparer, umax []byte) int {
                                    return sort.Search(len(tf), func(i int) bool {
                                        return icmp.ucmp.Compare(tf[i].imax.ukey(), umax) > 0
                                    })
                                }
                                Severity: Minor
                                Found in leveldb/table.go and 1 other location - About 45 mins to fix
                                leveldb/table.go on lines 153..157

                                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 113.

                                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

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

                                func (db *DB) recoverJournalRO() error {
                                    // Get all journals and sort it by file number.
                                    rawFds, err := db.s.stor.List(storage.TypeJournal)
                                    if err != nil {
                                        return err
                                Severity: Major
                                Found in leveldb/db.go - About 40 mins to fix

                                  Method tableCompactionBuilder.run has 6 return statements (exceeds 4 allowed).
                                  Open

                                  func (b *tableCompactionBuilder) run(cnt *compactionTransactCounter) (err error) {
                                      snapResumed := b.snapIter > 0
                                      hasLastUkey := b.snapHasLastUkey // The key might has zero length, so this is necessary.
                                      lastUkey := append([]byte{}, b.snapLastUkey...)
                                      lastSeq := b.snapLastSeq
                                  Severity: Major
                                  Found in leveldb/db_compaction.go - About 40 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language