Skip to content
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

Add a with_truncate_on_close to DmaStreamWriterBuilder #612

Closed
wants to merge 1 commit into from

Conversation

tontinton
Copy link
Contributor

@tontinton tontinton commented Oct 13, 2023

What does this PR do?

Adds a with_truncate_on_close to DmaStreamWriterBuilder, to remove any padding that might have been added by glommio.

Motivation

I wanted to get the file size of a file by reading its metadata using file_size(), instead of saving it to another file for example, and it was important to me to calculate how many items I have written to the file by a simple calculation instead of parsing it.

Any padding added would have ruined the calculation.

Useful to remove any padding that might have been added by glommio.
@vlovich
Copy link
Contributor

vlovich commented Oct 13, 2023

I'd love to see a unit test that shows the motivating example. I don't understand the impact this flag has because close consumes the DmaStreamWriterState. And if the flag is true, then we avoid the logic in must_truncate to force a truncation, but truncation should only have any effect if and only if flushed pos > aligned pos (i.e. must_truncate would be returning true anyway).

@tontinton
Copy link
Contributor Author

tontinton commented Oct 14, 2023

There's a check though in must_truncate:

        if let FileStatus::Closed = self.file_status {
            return false;
        }

Which is true when you call close on the file.

I can maybe write a test later, currently a bit busy.

@vlovich
Copy link
Contributor

vlovich commented Oct 14, 2023

I see. If that's the case, I would posit that there's a higher level logical bug where that state is being set prematurely and truncation isn't getting applied correctly (assuming this is happening in a very simple happy path).

@tontinton
Copy link
Contributor Author

Closing as fixed in #611

@tontinton tontinton closed this Oct 21, 2023
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