fix: support concurrent read/write from same active segment. #45
+48
−45
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.
Currently, wal.Read supports concurrent reads without data races only when using the exact chunk position, as it assumes that WAL is actively being written.
wal/wal.go
Line 426 in 9f1a618
However, if parallel/concurrent log replay is needed, the active segment modifies certain fields in the segment struct during writes. These same fields are also accessed by reader instances, leading to potential data races:
To enable safe concurrent reads while the WAL is being written, this PR updates these fields to use atomic operations:
By making these changes, the WAL will support parallel log replay from different readers without data races, ensuring consistency and thread safety.
Changes in this PR
• Replaced uint32 and bool fields with their atomic counterparts.
• Ensured all accesses to these fields use atomic operations.