-
Notifications
You must be signed in to change notification settings - Fork 5.7k
fix(agent): Correctly truncate the disk buffer #16697
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(agent): Correctly truncate the disk buffer #16697
Conversation
Thanks so much for the pull request! |
This fix appears to work in the tests I have run, but I am not confident that it actually always works. |
it might be a good idea to consider different approaches to dealing with the fact that the
|
models/buffer_disk.go
Outdated
offset := 0 | ||
for batchSize > 0 && readIndex < endIndex { | ||
for ; batchSize > 0 && readIndex < endIndex; readIndex, offset = readIndex+1, offset+1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see because we are adding this before the rest of the code and you do it at the end... In this case it would be good to keep the readIndex
as is and use the following
for offset := 0; batchSize > 0 && readIndex < endIndex; offset++ {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if we were going to attempt to complete this PR? it seems like a pretty major issue with the disk buffer
!signed-cla |
@nagaflokhu sorry for this being so slow! We do appreciate your effort on this! For moving forward with the PR, we need to check why the tests are failing now. If the tests were wrong initially, we need an explanation on why they were wrong and a fix to correct the test. Otherwise, if the tests are correct, we need to fix the code to get the tests to pass. |
@srebhan I've now fixed the tests that were failing and added an assertion for regression purposes. I just ran the additional assertion on the code from the latest master branch commit, and it shows that the previous implementation was not working: accepting a transaction and ending it did not change the amount of entries in the buffer. the other assertion in the test I modified was passing because the mask had a length of 2. |
e20a5d5
to
6e8b3b7
Compare
@nagaflokhu I took the liberty to push some commits to your branch including a unit-test and some missing pieces for fixing the issue. What do you think? |
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
very nice! fwiw, I wonder if an alternative disk buffer design might not be simpler than having to manage a mask, but it looks to me like we're not going down that route, so let's move forward I guess. |
An alternative WAL implementation will not happen anytime soon so let's fix this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nagaflokhu for pushing this forward!
@mstrandboge and @skartikey approved this but as I'm involved in the code, please review both! Furthermore, review but do not merge yet until we get some confirmations it fixes the issue(s). |
The proposed fix looks solid and appears to resolve the issue with the buffer not shrinking properly. It correctly maintains the mask, handles the empty buffer case more consistently, and adjusts offsets after truncation as expected. While reading through the code, I considered checking whether the condition The fix aligns well with what this test validates. Great work on this! |
Thanks @skartikey for the thorough review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this great work!
Co-authored-by: Sven Rebhan <srebhan@influxdata.com> (cherry picked from commit 5329835)
Summary
The disk buffer grows and never shrinks, as documented here.
Checklist
Related issues
resolves #16314
resolves #16500
resolves #16615
resolves #16696