-
Notifications
You must be signed in to change notification settings - Fork 44
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
fix: support concurrent read/write from same active segment. #45
base: main
Are you sure you want to change the base?
Conversation
Some of the concurrent race conditions that were observed.
I agree that the closed variable data race,part will not happen until Wal.Close is called concurrently without Releasing the reader, but should be protected from a data-race condition. |
\cc @roseduan |
Thanks, I will recheck this later. |
I understand the purpose of this PR:
|
I believe changing to atomic types won't solve the concurrency issues. For the closed field, it may still lead to reading from a closed file, and since currentBlockNumber and currentBlockSize fields need to be updated synchronously, concurrent access would still cause race conditions. |
You're right. But all the descriptors were closed, only when Wal is closed. So most of reader should be closed by the application owner before calling the wal.Close. But then again this leaves the library not dealing with it, which should be avoided. I've updated the PR to cover those cases. |
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.