GH-49433: [C++] Buffer ARROW_LOG output to prevent thread interleaving#49663
Open
Shockp wants to merge 1 commit intoapache:mainfrom
Open
GH-49433: [C++] Buffer ARROW_LOG output to prevent thread interleaving#49663Shockp wants to merge 1 commit intoapache:mainfrom
Shockp wants to merge 1 commit intoapache:mainfrom
Conversation
…leaving When using the ARROW_LOG macros from multiple threads, messages were getting mingled together in stderr because the operator<< was writing directly to the global stream piece-by-piece. This commit introduces an internal std::ostringstream buffer to CerrLog so that messages are accumulated locally and flushed atomically upon destruction.
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
When using the C++
ARROW_LOGmacros from multiple threads, messages often get mingled together instderrbecause theoperator<<writes directly to the global stream piece-by-piece, which is not thread-safe.What changes are included in this PR?
This PR introduces an internal
std::ostringstreambuffer to the fallbackCerrLogclass.Instead of writing to
std::cerrimmediately on every<<operation, the messages are accumulated locally within theCerrLoginstance. The completed string is then flushed atomically tostd::cerrupon the object's destruction.Are these changes tested?
Yes. I built the C++ project locally and ran the test suite (
ctest) to ensure no existing logging behavior or IPC functionality was broken.Are there any user-facing changes?
No API changes. Users will simply notice that multi-threaded
ARROW_LOGconsole output is now cleanly separated per line instead of interleaved.Closes #49433