Skip to content

Commit

Permalink
Cleaned up some code (#706)
Browse files Browse the repository at this point in the history
Made some changes to improve the quality of the code and comments:

* Only generate the defer code to release the lock on the value directory if it is different from the main directory
* Removed a period from ErrValueThreshold to keep it consistent with the other errors
* Removed an unused image
* Make explicit that if the directory or the value directory don't exist, they will try to be created
* Move a switch case to the appropriate place
* Replace ts += 1 for t++
  • Loading branch information
mariecurried authored and martinmr committed Jan 31, 2019
1 parent 5d71fbc commit 28ef9bf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ func Open(opt Options) (db *DB, err error) {
if err != nil {
return nil, err
}
defer func() {
if valueDirLockGuard != nil {
_ = valueDirLockGuard.release()
}
}()
}
defer func() {
if valueDirLockGuard != nil {
_ = valueDirLockGuard.release()
}
}()
if !(opt.ValueLogFileSize <= 2<<30 && opt.ValueLogFileSize >= 1<<20) {
return nil, ErrValueLogSize
}
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (

// ErrValueThreshold is returned when ValueThreshold is set to a value close to or greater than
// uint16.
ErrValueThreshold = errors.New("Invalid ValueThreshold, must be lower than uint16.")
ErrValueThreshold = errors.New("Invalid ValueThreshold, must be lower than uint16")

// ErrKeyNotFound is returned when key isn't found on a txn.Get.
ErrKeyNotFound = errors.New("Key not found")
Expand Down
Binary file removed images/sketch.jpg
Binary file not shown.
7 changes: 4 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (
type Options struct {
// 1. Mandatory flags
// -------------------
// Directory to store the data in. Should exist and be writable.
// Directory to store the data in. If it doesn't exist, Badger will
// try to create it for you.
Dir string
// Directory to store the value log in. Can be the same as Dir. Should
// exist and be writable.
// Directory to store the value log in. Can be the same as Dir. If it
// doesn't exist, Badger will try to create it for you.
ValueDir string

// 2. Frequently modified flags
Expand Down
4 changes: 2 additions & 2 deletions txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,13 @@ func runTxnCallback(cb *txnCb) {
switch {
case cb == nil:
panic("txn callback is nil")
case cb.user == nil:
panic("Must have caught a nil callback for txn.CommitWith")
case cb.err != nil:
cb.user(cb.err)
case cb.commit != nil:
err := cb.commit()
cb.user(err)
case cb.user == nil:
panic("Must have caught a nil callback for txn.CommitWith")
default:
cb.user(nil)
}
Expand Down
2 changes: 1 addition & 1 deletion value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestValueGCManaged(t *testing.T) {

var ts uint64
newTs := func() uint64 {
ts += 1
ts++
return ts
}

Expand Down

0 comments on commit 28ef9bf

Please sign in to comment.