johnsonjh/jleveldb

View on GitHub

Showing 166 of 166 total issues

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

func (o *Options) GetCompactionTotalSize(level int) int64 {
    var (
        base = DefaultCompactionTotalSize
        mult float64
    )
Severity: Major
Found in leveldb/opt/options.go and 1 other location - About 2 hrs to fix
leveldb/opt/options.go on lines 458..477

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

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 (o *Options) GetCompactionTableSize(level int) int {
    var (
        base = DefaultCompactionTableSize
        mult float64
    )
Severity: Major
Found in leveldb/opt/options.go and 1 other location - About 2 hrs to fix
leveldb/opt/options.go on lines 479..498

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

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

func (db *DB) compactionTransact(name string, t compactionTransactInterface) {
    defer func() {
        if x := recover(); x != nil {
            if x == errCompactionTransactExiting {
                if err := t.revert(); err != nil {
Severity: Major
Found in leveldb/db_compaction.go - About 2 hrs to fix

    IteratorTesting has 21 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type IteratorTesting struct {
        KeyValue
        Iter         iterator.Iterator
        Rand         *rand.Rand
        PostFn       func(t *IteratorTesting)
    Severity: Minor
    Found in leveldb/testutil/iter.go - About 2 hrs to fix

      Reader has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type Reader struct {
          mu     sync.RWMutex
          fd     storage.FileDesc
          reader io.ReaderAt
          cache  *cache.NamespaceGetter
      Severity: Minor
      Found in leveldb/table/reader.go - About 2 hrs to fix

        Method DB.tCompaction has 77 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (db *DB) tCompaction() {
            var (
                x     cCmd
                waitQ []cCmd
            )
        Severity: Major
        Found in leveldb/db_compaction.go - About 2 hrs to fix

          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

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

            func (r *reader) Read(p []byte) (n int, err error) {
                err = r.s.emulateError(ModeRead, r.fd.Type)
                if err == nil {
                    r.s.stall(ModeRead, r.fd.Type)
                    n, err = r.Reader.Read(p)
            Severity: Major
            Found in leveldb/testutil/storage.go and 1 other location - About 2 hrs to fix
            leveldb/testutil/storage.go on lines 218..229

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

            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 (w *writer) Write(p []byte) (n int, err error) {
                err = w.s.emulateError(ModeWrite, w.fd.Type)
                if err == nil {
                    w.s.stall(ModeWrite, w.fd.Type)
                    n, err = w.Writer.Write(p)
            Severity: Major
            Found in leveldb/testutil/storage.go and 1 other location - About 2 hrs to fix
            leveldb/testutil/storage.go on lines 182..193

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

            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 tableCompactionBuilder.run has 74 lines of code (exceeds 50 allowed). Consider refactoring.
            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: Minor
            Found in leveldb/db_compaction.go - About 1 hr to fix

              Method versionStaging.finish has 73 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (p *versionStaging) finish(trivial bool) *version {
                  // Build new version.
                  nv := newVersion(p.base.s)
                  numLevel := len(p.levels)
                  if len(p.base.levels) > numLevel {
              Severity: Minor
              Found in leveldb/version.go - About 1 hr to fix

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

                  Function KeyValueTesting has 70 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func KeyValueTesting(rnd *rand.Rand, kv KeyValue, p DB, setup func(KeyValue) DB, teardown func(DB)) {
                      if rnd == nil {
                          rnd = NewRand()
                      }
                  
                  
                  Severity: Minor
                  Found in leveldb/testutil/kvtest.go - About 1 hr to fix

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

                      Method blockIter.Prev has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
                      Open

                      func (i *blockIter) Prev() bool {
                          if i.dir == dirSOI || i.err != nil {
                              return false
                          } else if i.dir == dirReleased {
                              i.err = ErrIterReleased
                      Severity: Minor
                      Found in leveldb/table/reader.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 testingStorage.scanTable has 68 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func (ts *testingStorage) scanTable(fd storage.FileDesc, checksum bool) (corrupted bool) {
                          r, err := ts.Open(fd)
                          if err != nil {
                              log.Fatal(err)
                          }
                      Severity: Minor
                      Found in manualtest/dbstress/main.go - About 1 hr to fix

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

                        func (i *mergedIterator) next() bool {
                            var key []byte
                            if i.dir == dirForward {
                                key = i.keys[i.index]
                            }
                        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 181..198

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

                        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 *mergedIterator) prev() bool {
                            var key []byte
                            if i.dir == dirBackward {
                                key = i.keys[i.index]
                            }
                        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 130..147

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

                        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

                        Function recoverTable has 18 return statements (exceeds 4 allowed).
                        Open

                        func recoverTable(s *session, o *opt.Options) error {
                            o = dupOptions(o)
                            // Mask StrictReader, lets StrictRecovery doing its job.
                            o.Strict &= ^opt.StrictReader
                        
                        
                        Severity: Major
                        Found in leveldb/db.go - About 1 hr to fix

                          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

                          Severity
                          Category
                          Status
                          Source
                          Language