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

changes eventLog with Logger #1203

Merged
merged 10 commits into from
Apr 13, 2020

Conversation

gabru-md
Copy link
Contributor

@gabru-md gabru-md commented Jan 21, 2020

Provides a fix for #1193

@jarifibrahim, please review and let me know If it is correct. If it isn't then please mention what needs to be done so that I can try to do that as well.

Thanks for the issue


This change is Reviewable

Copy link
Contributor

@jarifibrahim jarifibrahim left a comment

Choose a reason for hiding this comment

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

Hey @gabru-md, thank you so much for the PR. It looks great 🎉

I have added some minor comments. Please address those and we should be able to merge this PR.
Thank you once again for your contribution :)

db.go Outdated
@@ -68,7 +67,7 @@ type DB struct {
valueDirGuard *directoryLockGuard

closers closers
elog trace.EventLog
logger Logger
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this. The options struct has the logger. Look at db.opt.Logger.

db.go Outdated
elog = trace.NewEventLog("Badger", "DB")
logger := NilLogger
if opt.Logging {
logger = defaultLogger
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the 3 lines above. The y.NoEventLog was added because eventLog would take up too much of CPU/memory. Now we don't need it.

db.go Outdated
@@ -284,7 +283,7 @@ func Open(opt Options) (db *DB, err error) {
writeCh: make(chan *request, kvWriteChCapacity),
opt: opt,
manifest: manifestFile,
elog: elog,
logger: logger,
Copy link
Contributor

Choose a reason for hiding this comment

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

This would go away once you remove logger from the DB struct :)

levels.go Outdated
@@ -37,7 +37,7 @@ import (

type levelsController struct {
nextFileID uint64 // Atomic
elog trace.EventLog
logger Logger
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this logger. The levelsController contains DB struct which contains the logger.

You can do levelsController.kv.opt.Logger where ever you need this.

levels.go Outdated
@@ -77,7 +77,7 @@ func newLevelsController(db *DB, mf *Manifest) (*levelsController, error) {
y.AssertTrue(db.opt.NumLevelZeroTablesStall > db.opt.NumLevelZeroTables)
s := &levelsController{
kv: db,
elog: db.elog,
logger: db.logger,
Copy link
Contributor

Choose a reason for hiding this comment

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

This would also go away once you change the levelsController struct.

logger.go Outdated
@@ -83,3 +83,15 @@ func (l *defaultLog) Infof(f string, v ...interface{}) {
func (l *defaultLog) Debugf(f string, v ...interface{}) {
l.Printf("DEBUG: "+f, v...)
}

var NilLogger Logger = nilLogger{}
Copy link
Contributor

Choose a reason for hiding this comment

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

The nilLogger is of no use to use once you remove the opt.Logging options. You can remove everything related to nilLogger.

options.go Outdated
@@ -48,7 +48,7 @@ type Options struct {
Truncate bool
Logger Logger
Compression options.CompressionType
EventLogging bool
Logging bool
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also not necessary. The user can set the logger via the opt.Logger option.

value.go Outdated
@@ -827,7 +827,7 @@ type lfDiscardStats struct {

type valueLog struct {
dirPath string
elog trace.EventLog
logger Logger
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use valueLog.db.opt.Logger . We don't need this logger.

@jarifibrahim
Copy link
Contributor

I just realized that the logger in badger doesn't support leveled logging. We might have to change the default logger. The Travis build failed because we're logging too much information.

y/watermark.go Outdated
}

// Init initializes a WaterMark struct. MUST be called before using it.
func (w *WaterMark) Init(closer *Closer, eventLogging bool) {
func (w *WaterMark) Init(closer *Closer, opt badger.Options) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

instead of passing a boolean value I am passing the Options object so that logger can be initialized for the Watermark struct as well.
@jarifibrahim, please see if this is the correct way to do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this may cause the circular import error. I'm not clear about how would I do it otherwise. will creating the logger as a different module be a better approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can move the logger inside the y package. The y package contains a bunch of utility types.

@gabru-md gabru-md requested a review from jarifibrahim January 25, 2020 15:34
y/logger.go Outdated
type defaultLog struct {
*log.Logger
}

var defaultLogger = &defaultLog{Logger: log.New(os.Stderr, "badger ", log.LstdFlags)}

func DefaultLogger() *defaultLog {

Choose a reason for hiding this comment

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

exported func DefaultLogger returns unexported type *github.com/dgraph-io/badger/v2/y.defaultLog, which can be annoying to use (from golint)

@stale
Copy link

stale bot commented Feb 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status/stale The issue hasn't had activity for a while and it's marked for closing. label Feb 26, 2020
@stale
Copy link

stale bot commented Mar 4, 2020

This issue was marked as stale and no activity has occurred since then, therefore it will now be closed. Please, reopen if the issue is still relevant.

@stale stale bot closed this Mar 4, 2020
@jarifibrahim
Copy link
Contributor

jarifibrahim commented Mar 5, 2020

This is a useful PR but we cannot merge it until we figure out a way to add leveled logging. Without leveled logging this PR would generate too much log.

@jarifibrahim jarifibrahim reopened this Mar 5, 2020
@stale stale bot removed the status/stale The issue hasn't had activity for a while and it's marked for closing. label Mar 5, 2020
@CLAassistant
Copy link

CLA assistant check
All committers have signed the CLA.

@jarifibrahim
Copy link
Contributor

This PR can be merged after #1249 is merged.

@stale
Copy link

stale bot commented Apr 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status/stale The issue hasn't had activity for a while and it's marked for closing. label Apr 5, 2020
@stale
Copy link

stale bot commented Apr 12, 2020

This issue was marked as stale and no activity has occurred since then, therefore it will now be closed. Please, reopen if the issue is still relevant.

@stale stale bot closed this Apr 12, 2020
@jarifibrahim jarifibrahim reopened this Apr 13, 2020
@stale stale bot removed the status/stale The issue hasn't had activity for a while and it's marked for closing. label Apr 13, 2020
Copy link
Contributor

@jarifibrahim jarifibrahim left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 0 of 7 files reviewed, 10 unresolved discussions (waiting on @ashish-goswami, @gabru-md, @jarifibrahim, and @manishrjain)

@jarifibrahim jarifibrahim merged commit 09dd2e1 into dgraph-io:master Apr 13, 2020
@jarifibrahim
Copy link
Contributor

Thanks for the PR @gabru-md 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants