Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(162)

Issue 7524046: log: fix data race on log.Target (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 1 month ago by dave
Modified:
11 years, 1 month ago
Reviewers:
mp+153978
Visibility:
Public.

Description

log: fix data race on log.Target Many of our test cases set the value of log.Target, then reset it during the test/suite teardown. This has always been racy, but we've worked around it. We're now at the point that it can't be hidden anymore. In this case it is the mgo connection retry logic inside the state tests, but it will always be something. This proposal makes the setting and getting of log.Target() (actually, log.target.logger) thread safe, and introduces a new nilLogger to make the logic inside each of the logging methods. There is probably also a race on log.Debug, so a similar proposal will be needed as a followup. Also, as witnessed by the duplication of logic that sets and resets the log.Target, try to push as much of the log target slight of hand into testing.LoggingSuite. https://code.launchpad.net/~dave-cheney/juju-core/108-fix-data-race-in-logging-tests/+merge/153978 (do not edit description out of merge proposal)

Patch Set 1 #

Patch Set 2 : log: fix data race on log.Target #

Total comments: 3

Patch Set 3 : log: fix data race on log.Target #

Patch Set 4 : log: fix data race on log.Target #

Total comments: 11

Patch Set 5 : log: fix data race on log.Target #

Total comments: 2

Patch Set 6 : log: fix data race on log.Target #

Patch Set 7 : log: fix data race on log.Target #

Unified diffs Side-by-side diffs Delta from patch set Stats (+90 lines, -84 lines) Patch
A [revision details] View 1 2 3 4 5 6 1 chunk +2 lines, -0 lines 0 comments Download
M charm/dir_test.go View 1 2 3 4 1 chunk +1 line, -3 lines 0 comments Download
M charm/repo_test.go View 1 2 3 4 1 chunk +1 line, -3 lines 0 comments Download
M cmd/builddb/main.go View 1 2 3 4 2 chunks +4 lines, -3 lines 0 comments Download
M cmd/charmd/main.go View 1 2 3 4 1 chunk +1 line, -1 line 0 comments Download
M cmd/charmload/main.go View 1 2 3 4 1 chunk +1 line, -1 line 0 comments Download
M cmd/logging.go View 1 2 3 4 2 chunks +1 line, -2 lines 0 comments Download
M cmd/logging_test.go View 1 2 3 4 3 chunks +6 lines, -14 lines 0 comments Download
M cmd/supercommand_test.go View 1 2 3 4 1 chunk +3 lines, -2 lines 0 comments Download
M log/log.go View 1 2 3 4 2 chunks +41 lines, -24 lines 0 comments Download
M log/log_test.go View 1 2 3 4 2 chunks +10 lines, -10 lines 0 comments Download
M state/megawatcher.go View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M store/store_test.go View 1 2 3 4 5 1 chunk +1 line, -1 line 0 comments Download
M testing/log.go View 1 2 3 4 1 chunk +7 lines, -7 lines 0 comments Download
M worker/uniter/context_test.go View 1 2 3 4 1 chunk +1 line, -5 lines 0 comments Download
M worker/uniter/jujuc/juju-log_test.go View 1 2 3 4 1 chunk +8 lines, -6 lines 0 comments Download
M worker/uniter/uniter_test.go View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 11
dave_cheney.net
Please take a look.
11 years, 1 month ago (2013-03-19 01:59:51 UTC) #1
dave_cheney.net
Please take a look. https://codereview.appspot.com/7524046/diff/3001/charm/dir_test.go File charm/dir_test.go (right): https://codereview.appspot.com/7524046/diff/3001/charm/dir_test.go#newcode120 charm/dir_test.go:120: func (s *DirSuite) TestBundleToWithNonExecutableHooks(c *C) ...
11 years, 1 month ago (2013-03-19 04:56:58 UTC) #2
jameinel
LGTM
11 years, 1 month ago (2013-03-19 08:18:15 UTC) #3
dimitern
LGTM https://codereview.appspot.com/7524046/diff/3002/cmd/logging_test.go File cmd/logging_test.go (right): https://codereview.appspot.com/7524046/diff/3002/cmd/logging_test.go#newcode43 cmd/logging_test.go:43: {"", true, true, []interface{}{NotNil}}, var nothing []interface = ...
11 years, 1 month ago (2013-03-19 10:19:41 UTC) #4
rog
LGTM with nilLogger gone and some other suggestions below. https://codereview.appspot.com/7524046/diff/3002/log/log.go File log/log.go (right): https://codereview.appspot.com/7524046/diff/3002/log/log.go#newcode13 log/log.go:13: ...
11 years, 1 month ago (2013-03-19 15:54:58 UTC) #5
dave_cheney.net
Please take a look. https://codereview.appspot.com/7524046/diff/3002/cmd/logging_test.go File cmd/logging_test.go (right): https://codereview.appspot.com/7524046/diff/3002/cmd/logging_test.go#newcode43 cmd/logging_test.go:43: {"", true, true, []interface{}{NotNil}}, Reverted ...
11 years, 1 month ago (2013-03-20 06:13:40 UTC) #6
fwereade
LGTM; I'm fine fixing just the race that this CL targets.
11 years, 1 month ago (2013-03-20 13:04:17 UTC) #7
rog
https://codereview.appspot.com/7524046/diff/15002/log/log.go File log/log.go (right): https://codereview.appspot.com/7524046/diff/15002/log/log.go#newcode47 log/log.go:47: return logf("ERROR: "+format, a...) better to avoid the string ...
11 years, 1 month ago (2013-03-20 13:17:38 UTC) #8
rog
LGTM modulo the below, BTW. On 2013/03/20 13:17:38, rog wrote: > https://codereview.appspot.com/7524046/diff/15002/log/log.go > File log/log.go ...
11 years, 1 month ago (2013-03-20 13:18:08 UTC) #9
thumper
LGTM I'm not bothered by the concatenation of the prefix prior to the logf call.
11 years, 1 month ago (2013-03-20 22:45:37 UTC) #10
dave_cheney.net
11 years, 1 month ago (2013-03-21 00:27:34 UTC) #11
*** Submitted:

log: fix data race on log.Target

Many of our test cases set the value of log.Target, then reset it during the
test/suite teardown. This has always been racy, but we've worked around it.
We're now at the point that it can't be hidden anymore. In this case it is the
mgo connection retry logic inside the state tests, but it will always be
something.

This proposal makes the setting and getting of log.Target() (actually,
log.target.logger) thread safe, and introduces a new nilLogger to make the logic
inside each of the logging methods.

There is probably also a race on log.Debug, so a similar proposal will be needed
as a followup.

Also, as witnessed by the duplication of logic that sets and resets the
log.Target, try to push as much of the log target slight of hand into
testing.LoggingSuite.

R=jameinel, dimitern, rog, fwereade, thumper
CC=
https://codereview.appspot.com/7524046

https://codereview.appspot.com/7524046/diff/15002/log/log.go
File log/log.go (right):

https://codereview.appspot.com/7524046/diff/15002/log/log.go#newcode47
log/log.go:47: return logf("ERROR: "+format, a...)
On 2013/03/20 13:17:38, rog wrote:
> better to avoid the string concatenation completely by passing the prefix as a
> separate argument, i think. (when the logging is disabled, of course) No need
to
> add more overhead than necessary.

There was string concatenation before this CL, and there is string concatenation
now. I am not focusing on the overhead of this allocation, I believe, in the
scope of Juju network usage, it is below the noise threshold.

If we find ourselves logging at such a rate that the logger itself is a
bottleneck, well, we have two problems.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b