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

support concurrent-safe WriteSyncer #359

Closed
wants to merge 1 commit into from
Closed

Conversation

flisky
Copy link
Contributor

@flisky flisky commented Mar 9, 2017

Follows up #106

@mention-bot
Copy link

@flisky, thanks for your PR! By analyzing the history of the files in this pull request, we identified @akshayjshah and @suyash to be potential reviewers.

@flisky flisky closed this Mar 9, 2017
@flisky flisky reopened this Mar 9, 2017
@flisky
Copy link
Contributor Author

flisky commented Mar 9, 2017

Travis errors with "Update failed for go.uber.org/atomic: Cannot detect VCS"

Trigger again.

@flisky flisky closed this Mar 9, 2017
@flisky flisky reopened this Mar 9, 2017
@flisky
Copy link
Contributor Author

flisky commented Mar 9, 2017

The CI should pass. Please take a review.

@suyash
Copy link
Contributor

suyash commented Mar 9, 2017

Any chance you could provide a sample program demonstrating usage for this feature?

@flisky
Copy link
Contributor Author

flisky commented Mar 9, 2017

Actually, I need the lock to do an application-level log rotate, but zap doesn't expose the underlying lockedWriteSyncer, and zap will lock the sink in anyway even if the writesyncer already does.

@akshayjshah
Copy link
Contributor

@flisky I'm sorry, I'm still confused. Can you explain your use case in more detail?

If you're trying to provide your own WriteSyncer that's already locked and handles log rotation, this change isn't necessary. Pass your implementation to zap.New - this library doesn't do anything by default unless you use the config struct.

@flisky
Copy link
Contributor Author

flisky commented Mar 9, 2017

Pass your implementation to zap.New - this library doesn't do anything by default unless you use the config struct.

It calls the writeSyncer with a zapcore.Lock in my understanding. And zapcore.Lock forcely adds a lock.

#106 said -

In future, we may want to expose a way of setting a WriteSyncer that
already supports concurrent calls

And this is a way trying to advise Lock - if the ws is concurrent safe, use it; if not, wrap ws with our default implementation. But now, the logic is - if the ws is our default concurrent safe instance, use it; if not, wrap it to our default concurrent safe instance.

Is my understanding correct? Thanks!

@akshayjshah
Copy link
Contributor

akshayjshah commented Mar 9, 2017

Oh dear, you're right - I was so sure that we'd already removed that. Let's fix this properly and just remove the automatic lock in NewCore.

The zapcore package shouldn't be supplying default behaviors - it should assume that the programmer knows what she's doing. This is a holdover from a much, much earlier version of this package.

func TestLockedWriteSyncerInterface(t *testing.T) {
buf := &bytes.Buffer{}
ws := AddSync(buf)
var lws WriteSyncer = &lockedWriteSyncer{ws: ws}
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be even better if the test uses a concrete type separately implemented from the internal lockedWriteSyncer since, as I understand it, the entire point of this PR is to support external implementations (and avoid double-locking them).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, half part. It also makes sure the internal lockedWriteSyncer is okay.
A separately implementation would be almost same as our default one, so I don't think it necessary.
Would some rewords help? Any thoughts?

@flisky
Copy link
Contributor Author

flisky commented Mar 10, 2017

Could you give me a final okay to get rid of zapcore.Lock, @akshayjshah & @jcorbin ? Because it's an incompatible change.

If so, would we keep the Lock implementation and just not call it ourselves, or remove it clearly? I'm glad to send another PR:)

@akshayjshah
Copy link
Contributor

We shouldn't get rid of zapcore.Lock, but we should get rid of the automatic use of it in zapcore.NewCore.

@seifer
Copy link

seifer commented Mar 10, 2017

Hi, what about this PR? It's a very useful. When will it be merged?

@flisky
Copy link
Contributor Author

flisky commented Mar 13, 2017

#369 as you wish, @akshayjshah.

@flisky flisky closed this Mar 13, 2017
@akshayjshah
Copy link
Contributor

@seifer This PR won't be merged, but @flisky was kind enough to open a smaller PR that accomplishes the same thing.

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.

6 participants