Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Dgraph): Stop forcing RAM mode for the write-ahead log. #6142

Merged
merged 5 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,18 @@ they form a Raft group and provide synchronous replication.

// Options around how to set up Badger.
flag.String("badger.tables", "mmap",
"[ram, mmap, disk] Specifies how Badger LSM tree is stored. "+
"[ram, mmap, disk] Specifies how Badger LSM tree is stored for the postings 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."+
"[mmap, disk] Specifies how Badger Value log is stored for the postings directory."+
" mmap consumes more RAM, but provides better performance.")
flag.String("badger.wal_tables", "mmap",
"[ram, mmap, disk] Specifies how Badger LSM tree is stored for the write-ahead log. "+
"Option sequence consume most to least RAM while providing best to worst read "+
"performance respectively.")
flag.String("badger.wal_vlog", "mmap",
"[mmap, disk] Specifies how Badger Value log is stored for the write-ahead log."+
" mmap consumes more RAM, but provides better performance.")
flag.Int("badger.compression_level", 3,
"The compression level for Badger. A higher value uses more resources.")
Expand Down Expand Up @@ -575,6 +582,8 @@ func run() {
opts := worker.Options{
BadgerTables: Alpha.Conf.GetString("badger.tables"),
BadgerVlog: Alpha.Conf.GetString("badger.vlog"),
BadgerWalTables: Alpha.Conf.GetString("badger.wal_tables"),
BadgerWalVlog: Alpha.Conf.GetString("badger.wal_vlog"),
BadgerCompressionLevel: Alpha.Conf.GetInt("badger.compression_level"),
PostingDir: Alpha.Conf.GetString("postings"),
WALDir: Alpha.Conf.GetString("wal"),
Expand Down
9 changes: 7 additions & 2 deletions worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ const (
type Options struct {
// PostingDir is the path to the directory storing the postings..
PostingDir string
// BadgerTables is the name of the mode used to load the badger tables.
// BadgerTables is the name of the mode used to load the badger tables for the p directory.
BadgerTables string
// BadgerVlog is the name of the mode used to load the badger value log.
// BadgerVlog is the name of the mode used to load the badger value log for the p directory.
BadgerVlog string
// BadgerWalTables is the name of the mode used to load the badger tables for the w directory.
BadgerWalTables string
// BadgerWalVlog is the name of the mode used to load the badger value log for the w directory.
BadgerWalVlog string

// BadgerCompressionLevel is the ZSTD compression level used by badger. A
// higher value means more CPU intensive compression and better compression
// ratio.
Expand Down
29 changes: 17 additions & 12 deletions worker/server_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func InitServerState() {
x.WorkerConfig.ProposedGroupId = groupId
}

func setBadgerOptions(opt badger.Options) badger.Options {
func setBadgerOptions(opt badger.Options, wal bool) badger.Options {
opt = opt.WithSyncWrites(false).
WithTruncate(true).
WithLogger(&x.ToGlog{}).
Expand All @@ -86,8 +86,20 @@ func setBadgerOptions(opt badger.Options) badger.Options {
opt.ZSTDCompressionLevel = Config.BadgerCompressionLevel
}

var badgerTables string
var badgerVlog string
if wal {
// Settings for the write-ahead log.
badgerTables = Config.BadgerWalTables
badgerVlog = Config.BadgerWalVlog
} else {
// Settings for the data directory.
badgerTables = Config.BadgerTables
badgerVlog = Config.BadgerVlog
}

glog.Infof("Setting Badger table load option: %s", Config.BadgerTables)
switch Config.BadgerTables {
switch badgerTables {
case "mmap":
opt.TableLoadingMode = options.MemoryMap
case "ram":
Expand All @@ -99,7 +111,7 @@ func setBadgerOptions(opt badger.Options) badger.Options {
}

glog.Infof("Setting Badger value log load option: %s", Config.BadgerVlog)
switch Config.BadgerVlog {
switch badgerVlog {
case "mmap":
opt.ValueLogLoadingMode = options.MemoryMap
case "disk":
Expand Down Expand Up @@ -128,17 +140,10 @@ func (s *ServerState) initStorage() {
// Write Ahead Log directory
x.Checkf(os.MkdirAll(Config.WALDir, 0700), "Error while creating WAL dir.")
opt := badger.LSMOnlyOptions(Config.WALDir)
opt = setBadgerOptions(opt)
opt = setBadgerOptions(opt, true)
opt.ValueLogMaxEntries = 10000 // Allow for easy space reclamation.
opt.MaxCacheSize = 10 << 20 // 10 mb of cache size for WAL.

// We should always force load LSM tables to memory, disregarding user settings, because
// Raft.Advance hits the WAL many times. If the tables are not in memory, retrieval slows
// down way too much, causing cluster membership issues. Because of prefix compression and
// value separation provided by Badger, this is still better than using the memory based WAL
// storage provided by the Raft library.
opt.TableLoadingMode = options.LoadToRAM

// Print the options w/o exposing key.
// TODO: Build a stringify interface in Badger options, which is used to print nicely here.
key := opt.EncryptionKey
Expand All @@ -161,7 +166,7 @@ func (s *ServerState) initStorage() {
WithKeepBlockIndicesInCache(true).
WithKeepBlocksInCache(true).
WithMaxBfCacheSize(500 << 20) // 500 MB of bloom filter cache.
opt = setBadgerOptions(opt)
opt = setBadgerOptions(opt, false)

// Print the options w/o exposing key.
// TODO: Build a stringify interface in Badger options, which is used to print nicely here.
Expand Down