Skip to content

Commit

Permalink
Fix ValueThreshold for in-memory mode (#1235)
Browse files Browse the repository at this point in the history
This commit increases the ValueThreshold for in-memory mode. The
existing threshold was of 1 MB which means badger would crash if
len(value) was greater than 1 MB. This commit sets the value threshold
to MaxInt32 (around 2 GB). Badger transaction would return an error if
badger is running in in-memory mode and length of value is greater than
the value threshold.

Fixes #1234
  • Loading branch information
Ibrahim Jarif authored Mar 3, 2020
1 parent 617ed7c commit 5b4c0a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ func Open(opt Options) (db *DB, err error) {

if db.opt.InMemory {
db.opt.SyncWrites = false
db.opt.ValueThreshold = maxValueThreshold
// If badger is running in memory mode, push everything into the LSM Tree.
db.opt.ValueThreshold = math.MaxInt32
}
krOpt := KeyRegistryOptions{
ReadOnly: opt.ReadOnly,
Expand Down
2 changes: 2 additions & 0 deletions txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ func (txn *Txn) modify(e *Entry) error {
return exceedsSize("Key", maxKeySize, e.Key)
case int64(len(e.Value)) > txn.db.opt.ValueLogFileSize:
return exceedsSize("Value", txn.db.opt.ValueLogFileSize, e.Value)
case txn.db.opt.InMemory && len(e.Value) > txn.db.opt.ValueThreshold:
return exceedsSize("Value", int64(txn.db.opt.ValueThreshold), e.Value)
}

if err := txn.checkSize(e); err != nil {
Expand Down

0 comments on commit 5b4c0a6

Please sign in to comment.