Skip to content

fix: make SequenceCheck.checkTableID logging thread-safe under parallel stream#624

Merged
yamelsenih merged 1 commit into
solop-develop:developfrom
EdwinBetanc0urt:bugfix/sequencecheck-parallel-addlog-threadsafe
Jul 8, 2026
Merged

fix: make SequenceCheck.checkTableID logging thread-safe under parallel stream#624
yamelsenih merged 1 commit into
solop-develop:developfrom
EdwinBetanc0urt:bugfix/sequencecheck-parallel-addlog-threadsafe

Conversation

@EdwinBetanc0urt

Copy link
Copy Markdown
Member

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.

How to test

  1. Run the Sequence Check process on a database with many IsTableID='Y' sequences.
  2. Before: intermittent ConcurrentModificationException / missing log lines under parallelism.
  3. After: all messages appear in the process result, flushed after processing; no concurrency errors.

Notes

  • Behavior-preserving; only the timing/threading of log output changes (messages are flushed after processing instead of interleaved).
  • Touches SequenceCheck.java only.

🤖 Generated with Claude Code

…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.
@EdwinBetanc0urt EdwinBetanc0urt force-pushed the bugfix/sequencecheck-parallel-addlog-threadsafe branch from 196515d to 6484c8d Compare July 8, 2026 21:30
@yamelsenih yamelsenih merged commit 03ec3b0 into solop-develop:develop Jul 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants