diff --git a/dgraph/cmd/zero/run.go b/dgraph/cmd/zero/run.go index 0a77e088168..0a828fc5a1d 100644 --- a/dgraph/cmd/zero/run.go +++ b/dgraph/cmd/zero/run.go @@ -34,6 +34,7 @@ import ( "google.golang.org/grpc" "github.com/dgraph-io/badger/v2" + bopt "github.com/dgraph-io/badger/v2/options" "github.com/dgraph-io/badger/v2/y" "github.com/dgraph-io/dgraph/conn" "github.com/dgraph-io/dgraph/ee/enc" @@ -108,6 +109,15 @@ instances to achieve high-availability. flag.Int64("cache_mb", 0, "Total size of cache (in MB) to be used in zero.") flag.String("cache_percentage", "100,0", "Cache percentages summing up to 100 for various caches (FORMAT: blockCache,indexCache).") + + // Badger flags + flag.String("badger.tables", "mmap", + "[ram, mmap, disk] Specifies how Badger LSM tree is stored for write-ahead log directory "+ + "write-ahead directory. Option sequence consume most to least RAM while providing "+ + "best to worst read performance respectively") + flag.String("badger.vlog", "mmap", + "[mmap, disk] Specifies how Badger Value log is stored for the write-ahead log directory "+ + "log directory. mmap consumes more RAM, but provides better performance.") } func setupListener(addr string, port int, kind string) (listener net.Listener, err error) { @@ -260,6 +270,27 @@ func run() { kvOpt.ZSTDCompressionLevel = 3 + // Set loading mode options. + switch Zero.Conf.GetString("badger.tables") { + case "mmap": + kvOpt.TableLoadingMode = bopt.MemoryMap + case "ram": + kvOpt.TableLoadingMode = bopt.LoadToRAM + case "disk": + kvOpt.TableLoadingMode = bopt.FileIO + default: + x.Fatalf("Invalid Badger Tables options") + } + switch Zero.Conf.GetString("badger.vlog") { + case "mmap": + kvOpt.ValueLogLoadingMode = bopt.MemoryMap + case "disk": + kvOpt.ValueLogLoadingMode = bopt.FileIO + default: + x.Fatalf("Invalid Badger Value log options") + } + glog.Infof("Opening zero BadgerDB with options: %+v\n", kvOpt) + kv, err := badger.Open(kvOpt) x.Checkf(err, "Error while opening WAL store") defer kv.Close()