johnsonjh/jleveldb

View on GitHub

Showing 166 of 166 total issues

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

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

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

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 session.recover has 66 lines of code (exceeds 50 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 1 hr to fix

    Method tFiles.getOverlaps has a Cognitive Complexity of 28 (exceeds 20 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

    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 mBucket.delete has a Cognitive Complexity of 28 (exceeds 20 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

    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 sessionRecord.decode has 63 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (p *sessionRecord) decode(r io.Reader) error {
        br, ok := r.(byteReader)
        if !ok {
            br = bufio.NewReader(r)
        }
    Severity: Minor
    Found in leveldb/session_record.go - About 1 hr to fix

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

              if shrink && len(h.buckets) > mInitialSize && atomic.CompareAndSwapInt32(&h.resizeInProgess, 0, 1) {
                  nhLen := len(h.buckets) >> 1
                  nh := &mNode{
                      buckets:         make([]unsafe.Pointer, nhLen),
                      mask:            uint32(nhLen) - 1,
      Severity: Major
      Found in leveldb/cache/cache.go and 1 other location - About 1 hr to fix
      leveldb/cache/cache.go on lines 132..146

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

      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 parseInternalKey(ik []byte) (ukey []byte, seq uint64, kt keyType, err error) {
          if len(ik) < 8 {
              return nil, 0, 0, newErrInternalKeyCorrupted(ik, "invalid length")
          }
          num := binary.LittleEndian.Uint64(ik[len(ik)-8:])
      Severity: Major
      Found in leveldb/key.go and 1 other location - About 1 hr to fix
      manualtest/dbstress/key.go on lines 82..93

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

      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

          if grow && atomic.CompareAndSwapInt32(&h.resizeInProgess, 0, 1) {
              nhLen := len(h.buckets) << 1
              nh := &mNode{
                  buckets:         make([]unsafe.Pointer, nhLen),
                  mask:            uint32(nhLen) - 1,
      Severity: Major
      Found in leveldb/cache/cache.go and 1 other location - About 1 hr to fix
      leveldb/cache/cache.go on lines 201..215

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

      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 parseIkey(ik []byte) (ukey []byte, seq uint64, kt kType, err error) {
          if len(ik) < 8 {
              return nil, 0, 0, newErrIkeyCorrupted(ik, "invalid length")
          }
          num := binary.LittleEndian.Uint64(ik[len(ik)-8:])
      Severity: Major
      Found in manualtest/dbstress/key.go and 1 other location - About 1 hr to fix
      leveldb/key.go on lines 90..101

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

      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.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.memCompaction has 60 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (db *DB) memCompaction() {
            mdb := db.getFrozenMem()
            if mdb == nil {
                return
            }
        Severity: Minor
        Found in leveldb/db_compaction.go - About 1 hr to fix

          Method dbIter.prev has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
          Open

          func (i *dbIter) prev() bool {
              i.dir = dirBackward
              del := true
              if i.iter.Valid() {
                  for {
          Severity: Minor
          Found in leveldb/db_iter.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 mNode.initBucket has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
          Open

          func (n *mNode) initBucket(i uint32) *mBucket {
              if b := (*mBucket)(atomic.LoadPointer(&n.buckets[i])); b != nil {
                  return b
              }
          
          
          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 session.newManifest has 56 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (s *session) newManifest(rec *sessionRecord, v *version) (err error) {
              fd := storage.FileDesc{Type: storage.TypeManifest, Num: s.allocFileNum()}
              writer, err := s.stor.Create(fd)
              if err != nil {
                  return
          Severity: Minor
          Found in leveldb/session_util.go - About 1 hr to fix

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