johnsonjh/jleveldb

View on GitHub

Showing 166 of 166 total issues

Method mBucket.delete has 53 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (b *mBucket) delete(r *Cache, h *mNode, hash uint32, ns, key uint64) (done, deleted bool) {
    b.mu.Lock()

    if b.frozen {
        b.mu.Unlock()
Severity: Minor
Found in leveldb/cache/cache.go - About 1 hr to fix

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

    func (i *blockIter) Last() bool {
        if i.err != nil {
            return false
        } else if i.dir == dirReleased {
            i.err = ErrIterReleased
    Severity: Major
    Found in leveldb/table/reader.go and 1 other location - About 1 hr to fix
    leveldb/table/reader.go on lines 194..208

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

    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 (i *blockIter) First() bool {
        if i.err != nil {
            return false
        } else if i.dir == dirReleased {
            i.err = ErrIterReleased
    Severity: Major
    Found in leveldb/table/reader.go and 1 other location - About 1 hr to fix
    leveldb/table/reader.go on lines 210..224

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

    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 Reader.nextChunk has 11 return statements (exceeds 4 allowed).
    Open

    func (r *Reader) nextChunk(first bool) error {
        for {
            if r.j+headerSize <= r.n {
                checksum := binary.LittleEndian.Uint32(r.buf[r.j+0 : r.j+4])
                length := binary.LittleEndian.Uint16(r.buf[r.j+4 : r.j+6])
    Severity: Major
    Found in leveldb/journal/journal.go - About 1 hr to fix

      Method Cache.Get has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
      Open

      func (r *Cache) Get(ns, key uint64, setFunc func() (size int, value Value)) *Handle {
          r.mu.RLock()
          defer r.mu.RUnlock()
          if r.closed {
              return nil
      Severity: Minor
      Found in leveldb/cache/cache.go - 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 DB.checkAndCleanFiles has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
      Open

      func (db *DB) checkAndCleanFiles() error {
          v := db.s.version()
          defer v.release()
      
          tmap := make(map[int64]bool)
      Severity: Minor
      Found in leveldb/db_util.go - 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 Reader.find has 11 return statements (exceeds 4 allowed).
      Open

      func (r *Reader) find(key []byte, filtered bool, ro *opt.ReadOptions, noValue bool) (rkey, value []byte, err error) {
          r.mu.RLock()
          defer r.mu.RUnlock()
      
          if r.err != nil {
      Severity: Major
      Found in leveldb/table/reader.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 blockIter.Prev has 10 return statements (exceeds 4 allowed).
          Open

          func (i *blockIter) Prev() bool {
              if i.dir == dirSOI || i.err != nil {
                  return false
              } else if i.dir == dirReleased {
                  i.err = ErrIterReleased
          Severity: Major
          Found in leveldb/table/reader.go - About 1 hr to fix

            Method BufferPool.Get has 10 return statements (exceeds 4 allowed).
            Open

            func (p *BufferPool) Get(n int) []byte {
                if p == nil {
                    return make([]byte, n)
                }
            
            
            Severity: Major
            Found in leveldb/util/buffer_pool.go - About 1 hr to fix

              Method session.recover has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
              Open

              func (s *session) recover() (err error) {
                  defer func() {
                      if os.IsNotExist(err) {
                          // Don't return os.ErrNotExist if the underlying storage contains
                          // other files that belong to LevelDB. So the DB won't get trashed.
              Severity: Minor
              Found in leveldb/session.go - 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 version.get has 8 return statements (exceeds 4 allowed).
              Open

              func (v *version) get(aux tFiles, ikey internalKey, ro *opt.ReadOptions, noValue bool) (value []byte, tcomp bool, err error) {
                  if v.closing {
                      return nil, false, ErrClosed
                  }
              
              
              Severity: Major
              Found in leveldb/version.go - About 50 mins to fix

                Method blockIter.Next has 8 return statements (exceeds 4 allowed).
                Open

                func (i *blockIter) Next() bool {
                    if i.dir == dirEOI || i.err != nil {
                        return false
                    } else if i.dir == dirReleased {
                        i.err = ErrIterReleased
                Severity: Major
                Found in leveldb/table/reader.go - About 50 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

                                        if !del && i.icmp.uCompare(ukey, i.key) < 0 {
                                            return true
                                        }
                    Severity: Major
                    Found in leveldb/db_iter.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

                      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

                                            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

                          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 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
                              Severity
                              Category
                              Status
                              Source
                              Language