Skip to content

Commit

Permalink
allow users to specify badger table options (#1188)
Browse files Browse the repository at this point in the history
allow users to specify badger table options and make it loadtoram by default
  • Loading branch information
Janardhan Reddy authored Jul 14, 2017
1 parent b61e228 commit 57815c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
4 changes: 4 additions & 0 deletions cmd/dgraph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func setupConfigOpts() {
defaults := dgraph.DefaultConfig
flag.StringVar(&config.PostingDir, "p", defaults.PostingDir,
"Directory to store posting lists.")
flag.StringVar(&config.PostingTables, "posting_tables", defaults.PostingTables,
"Specifies how Badger LSM tree is stored. Options are loadtoram, memorymap and "+
"nothing; which consume most to least RAM while providing best to worst "+
"performance respectively.")
flag.StringVar(&config.WALDir, "w", defaults.WALDir,
"Directory to store raft write-ahead logs.")
flag.BoolVar(&config.Nomutations, "nomutations", defaults.Nomutations,
Expand Down
1 change: 1 addition & 0 deletions cmd/dgraph/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func prepare() (dir1, dir2 string, ps *badger.KV, rerr error) {
}

dgraph.Config.PostingDir = dir1
dgraph.Config.PostingTables = "loadtoram"
dgraph.Config.WALDir = dir2
dgraph.State = dgraph.NewServerState()

Expand Down
21 changes: 12 additions & 9 deletions dgraph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@
package dgraph

import (
"path/filepath"

"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/worker"
"github.com/dgraph-io/dgraph/x"
"path/filepath"
)

type Options struct {
PostingDir string
WALDir string
Nomutations bool
NumPending int
PostingDir string
PostingTables string
WALDir string
Nomutations bool
NumPending int

AllottedMemory float64
CommitFraction float64
Expand All @@ -52,10 +54,11 @@ type Options struct {
var Config Options

var DefaultConfig = Options{
PostingDir: "p",
WALDir: "w",
Nomutations: false,
NumPending: 1000,
PostingDir: "p",
PostingTables: "loadtoram",
WALDir: "w",
Nomutations: false,
NumPending: 1000,

AllottedMemory: 1024.0,
CommitFraction: 0.10,
Expand Down
13 changes: 11 additions & 2 deletions dgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *ServerState) initStorage() {
kvOpt.SyncWrites = true
kvOpt.Dir = Config.WALDir
kvOpt.ValueDir = Config.WALDir
kvOpt.MapTablesTo = table.Nothing
kvOpt.MapTablesTo = table.MemoryMap

var err error
s.WALstore, err = badger.NewKV(&kvOpt)
Expand All @@ -77,7 +77,16 @@ func (s *ServerState) initStorage() {
opt.SyncWrites = true
opt.Dir = Config.PostingDir
opt.ValueDir = Config.PostingDir
opt.MapTablesTo = table.MemoryMap
switch Config.PostingTables {
case "memorymap":
opt.MapTablesTo = table.MemoryMap
case "loadtoram":
opt.MapTablesTo = table.LoadToRAM
case "nothing":
opt.MapTablesTo = table.Nothing
default:
x.Fatalf("Invalid Posting Tables options")
}
s.Pstore, err = badger.NewKV(&opt)
x.Checkf(err, "Error while creating badger KV posting store")
}
Expand Down

0 comments on commit 57815c7

Please sign in to comment.