johnsonjh/jleveldb

View on GitHub

Showing 142 of 166 total issues

Method Reader.nextChunk has 55 lines of code (exceeds 50 allowed). Consider refactoring.
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: Minor
Found in leveldb/journal/journal.go - About 1 hr to fix

    Method DB.recoverJournal has 12 return statements (exceeds 4 allowed).
    Open

    func (db *DB) recoverJournal() 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 1 hr to fix

      Function NewReader has 12 return statements (exceeds 4 allowed).
      Open

      func NewReader(f io.ReaderAt, size int64, fd storage.FileDesc, cache *cache.NamespaceGetter, bpool *util.BufferPool, o *opt.Options) (*Reader, error) {
          if f == nil {
              return nil, errors.New("leveldb/table: nil file")
          }
      
      
      Severity: Major
      Found in leveldb/table/reader.go - About 1 hr to fix

        Method DB.checkAndCleanFiles has 54 lines of code (exceeds 50 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

          Method tFiles.getOverlaps has 54 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (tf tFiles) getOverlaps(dst tFiles, icmp *iComparer, umin, umax []byte, overlapped bool) tFiles {
              // Short circuit if tf is empty
              if len(tf) == 0 {
                  return nil
              }
          Severity: Minor
          Found in leveldb/table.go - About 1 hr to fix

            Function KeyValue_Generate has 54 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func KeyValue_Generate(rnd *rand.Rand, n, incr, minlen, maxlen, vminlen, vmaxlen int) *KeyValue {
                if rnd == nil {
                    rnd = NewRand()
                }
                if maxlen < minlen {
            Severity: Minor
            Found in leveldb/testutil/kv.go - About 1 hr to fix

              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

                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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language