-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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{} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
y/logger.go
Outdated
type defaultLog struct { | ||
*log.Logger | ||
} | ||
|
||
var defaultLogger = &defaultLog{Logger: log.New(os.Stderr, "badger ", log.LstdFlags)} | ||
|
||
func DefaultLogger() *defaultLog { |
There was a problem hiding this comment.
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
)
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. |
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. |
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. |
This PR can be merged after #1249 is merged. |
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. |
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. |
This reverts commit 0b81618.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 7 files reviewed, 10 unresolved discussions (waiting on @ashish-goswami, @gabru-md, @jarifibrahim, and @manishrjain)
Thanks for the PR @gabru-md 🎉 |
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