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 3 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
9 changes: 7 additions & 2 deletions 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 Expand Up @@ -319,7 +324,7 @@ func Open(opt Options) (db *DB, err error) {
replayCloser := y.NewCloser(1)
go db.doWrites(replayCloser)

if err = db.vlog.open(db, vptr, db.replayFunction()); err != nil {
if err = db.vlog.open(db, vptr, db.replayFunction(), opt.EventLogging); err != nil {
return db, y.Wrapf(err, "During db.vlog.open")
}
replayCloser.SignalAndWait() // Wait for replay to be applied first.
Expand Down
31 changes: 31 additions & 0 deletions event_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2019 Dgraph Labs, Inc. and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package badger

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

var (
noEventLog trace.EventLog = nilEventLog{}
)

type nilEventLog struct{}

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
7 changes: 5 additions & 2 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,15 @@ func (vlog *valueLog) replayLog(lf *logFile, offset uint32, replayFn logEntry) e
return nil
}

func (vlog *valueLog) open(db *DB, ptr valuePointer, replayFn logEntry) error {
func (vlog *valueLog) open(db *DB, ptr valuePointer, replayFn logEntry, eventLogging bool) error {
jarifibrahim marked this conversation as resolved.
Show resolved Hide resolved
opt := db.opt
vlog.opt = opt
vlog.dirPath = opt.ValueDir
vlog.db = db
vlog.elog = trace.NewEventLog("Badger", "Valuelog")
vlog.elog = noEventLog
if eventLogging {
vlog.elog = trace.NewEventLog("Badger", "Valuelog")
}
vlog.garbageCh = make(chan struct{}, 1) // Only allow one GC at a time.
vlog.lfDiscardStats = &lfDiscardStats{m: make(map[uint32]int64)}
if err := vlog.populateFilesMap(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func TestValueGC4(t *testing.T) {
err = kv.vlog.Close()
require.NoError(t, err)

err = kv.vlog.open(kv, valuePointer{Fid: 2}, kv.replayFunction())
err = kv.vlog.open(kv, valuePointer{Fid: 2}, kv.replayFunction(), true)
require.NoError(t, err)

for i := 0; i < 8; i++ {
Expand Down Expand Up @@ -628,7 +628,7 @@ func TestPartialAppendToValueLog(t *testing.T) {
// Replay value log from beginning, badger head is past k2.
require.NoError(t, kv.vlog.Close())
require.NoError(t,
kv.vlog.open(kv, valuePointer{Fid: 0}, kv.replayFunction()))
kv.vlog.open(kv, valuePointer{Fid: 0}, kv.replayFunction(), true))
require.NoError(t, kv.Close())
}

Expand Down