-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-9399] Change the redirection of System.err to be a custom PrintStream #11096
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
Conversation
|
R: @lukecwik |
kennknowles
left a comment
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.
Thanks for the detailed pull request description. I was able to understand the reason for this and actually able to do a review. Is there a way to test this? (not the deadlock or lack thereof but just the basic functionality)
lukecwik
left a comment
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 need to check for \n for any object that could contain 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.
Would it be an issue for multi-byte wide characters that have been split?
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.
Added a CharsetDecoder that is used for this method
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.
Either use assert !Thread.holdsLock(this) : "BEAM-9399: This thread should never hold this lock"; or checkState(!Thread.holdsLock(this), "BEAM-9399: This thread should never hold this lock"); to guard against this case.
https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#holdsLock%28java.lang.Object%29
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.
Done
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.
It makes a lot more sense to move all the newline handling into publish and for it to check for new lines. If you want to avoid the cost of indexOf/substring call, you could create an internal method that publishWithNewLines that does all the substring/indexOf work and only use publish for the trivial println methods
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 previous code removed trailing newlines when publishing, which makes sense to me since we don't need them in the final log message.
Is there a reason not to do it here? This is a single callsite and avoids making a substring.
The checking for newlines for flushing seems like it needs to be in each function since otherwise we wouldn't be calling publish.
08bfb70 to
abf4d7b
Compare
|
abf4d7b to
fd4beaf
Compare
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 need to use the stateful version of the CharsetDecoder.decode since this method assumes that the byte[] range represents a whole valid String.
In the other methods you would need to finish the decoding if there is a partial decoding in flight.
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.
Thanks for catching. I added a unit test for raw bytes and fixed to keep a buffer of remainders.
d0b54ab to
9651178
Compare
|
retest this please |
|
Run Java PreCommit |
|
Run Spotless PreCommit |
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 have to use the default charset for getBytes since you use the default charset in the CharsetDecoder.
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.
good catch, done.
lukecwik
left a comment
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.
Please address my comment about using the default charset during testing and also address the spotless error described below:
14:06:02 > The following files had format violations:
14:06:02 runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/logging/JulHandlerPrintStreamAdapterFactory.java
14:06:02 @@ -144,7 +144,7 @@
14:06:02 ··············flush·=·true;
14:06:02 ············}
14:06:02 ············//·Keep·the·unread·bytes.
14:06:02 -············assert(incoming.remaining()·<=·carryOverByteArray.length);
14:06:02 +············assert·(incoming.remaining()·<=·carryOverByteArray.length);
14:06:02 ············while·(incoming.hasRemaining())·{
14:06:02 ··············carryOverByteArray[carryOverBytes++]·=·incoming.get();
14:06:02 ············}
14:06:02 Run 'gradlew spotlessApply' to fix these violations.
…Stream instead of a custom output stream wrapped by standard PrintStream.
9651178 to
072ddc0
Compare
|
I pushed fixes for both changes you requested but it isn't letting me close your changes requested . For the future, should push commits and only squash them once reviewing is complete? Thanks! |
|
retest this please |
lukecwik
left a comment
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.
Conditionally on tests being green.
|
retest this please |
You shouldn't squash commits because it makes it harder for the reviewer to see the diff between versions. Also it messes up parts of the comments/suggestion history. Once you get an LGTM, you can either squash and fix-up your commit history then or allow the reviewer to squash and merge your commits. |
lukecwik
left a comment
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.
Please fix:
08:19:51 /home/jenkins/jenkins-slave/workspace/beam_PreCommit_Java_Commit/src/runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/logging/JulHandlerPrintStreamAdapterFactoryTest.java:122: error: cannot find symbol
08:19:51 byte[] bytes = msg.getBytes(Charset.defaultCharset());
08:19:51 ^
08:19:51 symbol: variable Charset
08:19:51 location: class JulHandlerPrintStreamAdapterFactoryTest
08:19:51 /home/jenkins/jenkins-slave/workspace/beam_PreCommit_Java_Commit/src/runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/logging/JulHandlerPrintStreamAdapterFactoryTest.java:129: error: cannot find symbol
08:19:51 byte[] newlineMsgBytes = newlineMsg.getBytes(Charset.defaultCharset());
08:19:51 ^
08:19:51 symbol: variable Charset
|
Fixed. Sorry for that, I ran tests but must have been on the wrong branch. |
|
retest this please |
|
retest this please |
|
https://builds.apache.org/job/beam_PreCommit_Java_Commit/10616/ passed, merging. |
This replaces the current implementation of a custom output stream wrapped by standard PrintStream, removing a possible deadlock between the PrintStream and handler. The
deadlock can occur if something beneath the handler lock attempts to use System.err, reversing
the normal locking order.
By using PrintStream we can use a StringBuffer instead of a ByteBuffer, which also avoids extra encoding and decoding between byte arrays and Strings.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
R: @username).[BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replaceBEAM-XXXwith the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
Post-Commit Tests Status (on master branch)
Pre-Commit Tests Status (on master branch)
See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.