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 possible incomplete snapshot chunk write #4358
Conversation
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.
Dumb question, why can't we use Files.write
here as well again?
Not dump at all. I just wanted to do smallest changes. I was not sure whether here was a reason to use the SeekableChannel, furthermore not sure whether we have access to the byte array. But probably we have here no direct byte buffer. |
was this now an request ? @npepinpe |
I see what you mean, I guess I'm not 100% sure if we can guarantee it's always a byte array. We probably do, but yeah not sure. That said, it makes me realize there might be an issue with our replication. Say I want to write a chunk of X bytes, but I only write I guess the PR, as is, is already an improvement so 👍 |
bors r+ |
Build succeeded |
@npepinpe regarding the io thing. Our replication marks the snapshot as invalid if an exception was thrown, so should be fine. |
So the only possible case is if it crashed while looping the write? |
Node crash you mean? Yeah maybe. |
@npepinpe thought about this a bit more. I think then the snapshot will not be finished if the node fails, which means it will be not marked as valid so no problem. |
4372: fix(atomix): consume read buffer correctly r=Zelldon a=Zelldon ## Description Fix issue where the read buffer was consumed only half and the rest was thrown away. Refactor `FileChannelJournalSegmentReader#readNext` to improve readability and hopefully maintainability. <!-- Please explain the changes you made here. --> I run also a benchmark with these changes (#4358 was also part of the branch I run a benchmark with) ![metrics](https://user-images.githubusercontent.com/2758593/80199113-45202a00-8621-11ea-9595-e8c65130ec97.png) ## Related issues <!-- Which issues are closed by this PR or are related --> closes #4248 # Co-authored-by: Christopher Zell <zelldon91@googlemail.com>
4372: fix(atomix): consume read buffer correctly r=Zelldon a=Zelldon ## Description Fix issue where the read buffer was consumed only half and the rest was thrown away. Refactor `FileChannelJournalSegmentReader#readNext` to improve readability and hopefully maintainability. <!-- Please explain the changes you made here. --> I run also a benchmark with these changes (#4358 was also part of the branch I run a benchmark with) ![metrics](https://user-images.githubusercontent.com/2758593/80199113-45202a00-8621-11ea-9595-e8c65130ec97.png) ## Related issues <!-- Which issues are closed by this PR or are related --> closes #4248 # Co-authored-by: Christopher Zell <zelldon91@googlemail.com>
Description
As written in #4357 we need to loop on writing otherwise we may end in cases where your snapshot is corrupted because chunks have been written not completely.
Related guide to write to FileChannel http://tutorials.jenkov.com/java-nio/file-channel.html
Related issues
closes #4357
Pull Request Checklist
mvn clean install -DskipTests
locally before committing