fix: make SequenceCheck.checkTableID logging thread-safe under parallel stream#624
Merged
yamelsenih merged 1 commit intoJul 8, 2026
Conversation
…el stream ## Problem checkTableID processes sequences with a parallel stream (sequenceIds.stream().parallel().forEach(...)), and each worker calls SvrProcess.addLog(...) directly. SvrProcess keeps its log entries in a non-thread-safe list, so concurrent addLog(...) calls can corrupt it (ConcurrentModificationException / lost entries). ## Fix (keeps the parallelism) Buffer the log messages in a thread-safe ConcurrentLinkedQueue inside the parallel lambda, and flush them sequentially (single thread) into SvrProcess.addLog(...) after the stream completes: - Declare ConcurrentLinkedQueue<String> logMessages before the stream. - Replace every in-lambda sp.addLog(...) with logMessages.add(...). - After the stream: if (sp != null) logMessages.forEach(msg -> sp.addLog(0, null, null, msg)). The heavy work (load, validate, saveEx, native sequence creation) still runs in parallel; only the non-thread-safe logging is serialized. Also: createMissingNativeSequence(...) is now called unconditionally (the log is what is deferred), so the native sequence is created regardless of whether a SvrProcess is present. ## Notes - Behavior-preserving; only the timing/threading of log output changes (messages are flushed after processing instead of interleaved). - Touches SequenceCheck.java only.
196515d to
6484c8d
Compare
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.
Problem
checkTableIDprocesses sequences with a parallel stream (sequenceIds.stream().parallel().forEach(...)), and each worker callsSvrProcess.addLog(...)directly.SvrProcesskeeps its log entries in a non-thread-safe list, so concurrentaddLog(...)calls can corrupt it (ConcurrentModificationException/ lost entries).Fix (keeps the parallelism)
Buffer the log messages in a thread-safe
ConcurrentLinkedQueueinside the parallel lambda, and flush them sequentially (single thread) intoSvrProcess.addLog(...)after the stream completes:ConcurrentLinkedQueue<String> logMessagesbefore the stream.sp.addLog(...)withlogMessages.add(...).if (sp != null) logMessages.forEach(msg -> sp.addLog(0, null, null, msg));The heavy work (load, validate,
saveEx, native sequence creation) still runs in parallel; only the non-thread-safe logging is serialized.Also:
createMissingNativeSequence(...)is now called unconditionally (the log is what is deferred), so the native sequence is created regardless of whether aSvrProcessis present.How to test
IsTableID='Y'sequences.ConcurrentModificationException/ missing log lines under parallelism.Notes
SequenceCheck.javaonly.🤖 Generated with Claude Code