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

Add EventLogging option #1035

Merged
merged 6 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,18 @@ func Open(opt Options) (db *DB, err error) {
}
}()

elog := noEventLog
if opt.EventLogging {
elog = trace.NewEventLog("Badger", "DB")
}

db = &DB{
imm: make([]*skl.Skiplist, 0, opt.NumMemtables),
flushChan: make(chan flushTask, opt.NumMemtables),
writeCh: make(chan *request, kvWriteChCapacity),
opt: opt,
manifest: manifestFile,
elog: trace.NewEventLog("Badger", "DB"),
elog: elog,
dirLockGuard: dirLockGuard,
valueDirGuard: valueDirLockGuard,
orc: newOracle(opt),
Expand Down
15 changes: 15 additions & 0 deletions nil_event_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package badger
mjgarton marked this conversation as resolved.
Show resolved Hide resolved

import "golang.org/x/net/trace"

var (
noEventLog trace.EventLog = nilEventLog{}
)

type nilEventLog struct{}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the need for this struct to be a part of the repo, and why is it the default?


func (nel nilEventLog) Printf(format string, a ...interface{}) {}

func (nel nilEventLog) Errorf(format string, a ...interface{}) {}

func (nel nilEventLog) Finish() {}
12 changes: 12 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Options struct {
ReadOnly bool
Truncate bool
Logger Logger
EventLogging bool

// Fine tuning options.

Expand Down Expand Up @@ -114,6 +115,7 @@ func DefaultOptions(path string) Options {
ValueThreshold: 32,
Truncate: false,
Logger: defaultLogger,
EventLogging: true,
LogRotatesToFlush: 2,
}
}
Expand Down Expand Up @@ -237,6 +239,16 @@ func (opt Options) WithLogger(val Logger) Options {
return opt
}

// WithEventLogging returns a new Options value with EventLogging set to the given value.
//
// EventLogging provides a way to enable or disable trace.EventLog logging.
//
// The default value of EventLogging is true.
func (opt Options) WithEventLogging(enabled bool) Options {
opt.EventLogging = enabled
return opt
}

// WithMaxTableSize returns a new Options value with MaxTableSize set to the given value.
//
// MaxTableSize sets the maximum size in bytes for each LSM table or file.
Expand Down