leveldb/db_write.go
Method DB.writeLocked
has a Cognitive Complexity of 42 (exceeds 20 allowed). Consider refactoring. Open
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 {
- Read upRead up
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.writeLocked
has 75 lines of code (exceeds 50 allowed). Consider refactoring. Open
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 {
Method DB.flush
has 62 lines of code (exceeds 50 allowed). Consider refactoring. Open
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()
// 请问您知道这里为什么要用匿名函数吗,我理解的是直接用循环就可以
Method DB.Write
has 10 return statements (exceeds 4 allowed). Open
Open
func (db *DB) Write(batch *Batch, wo *opt.WriteOptions) error {
if err := db.ok(); err != nil || batch == nil || batch.Len() == 0 {
return err
}
Method DB.flush
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
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()
// 请问您知道这里为什么要用匿名函数吗,我理解的是直接用循环就可以
- Read upRead up
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
Open
if ourBatch == nil {
ourBatch = db.batchPool.Get().(*Batch)
ourBatch.Reset()
batches = append(batches, ourBatch)
}
Method DB.putRec
has 7 return statements (exceeds 4 allowed). Open
Open
func (db *DB) putRec(kt keyType, key, value []byte, wo *opt.WriteOptions) error {
if err := db.ok(); err != nil {
return err
}
Method DB.CompactRange
has 7 return statements (exceeds 4 allowed). Open
Open
func (db *DB) CompactRange(r util.Range) error {
if err := db.ok(); err != nil {
return err
}
Avoid deeply nested control flow statements. Open
Open
if incoming.batch.internalLen > mergeLimit {
overflow = true
break merge
}
Avoid deeply nested control flow statements. Open
Open
if internalLen > mergeLimit {
overflow = true
break merge
}
Method DB.SetReadOnly
has 6 return statements (exceeds 4 allowed). Open
Open
func (db *DB) SetReadOnly() error {
if err := db.ok(); err != nil {
return err
}
Method DB.flush
has 6 return statements (exceeds 4 allowed). Open
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()
// 请问您知道这里为什么要用匿名函数吗,我理解的是直接用循环就可以
Method DB.writeJournal
has 5 return statements (exceeds 4 allowed). Open
Open
func (db *DB) writeJournal(batches []*Batch, seq uint64, sync bool) error {
wr, err := db.journal.Next()
if err != nil {
return err
}