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 options to createWriter() to deal with atomic writes. #51

Merged
merged 4 commits into from
Jun 10, 2019

Conversation

mkruisselbrink
Copy link
Contributor

This attempts to solve #37 by making it explicit that changes made to files
might not be reflected on disk until flush() or close() is called on the
writer.

This also introduces a "atomic" mode for FileSystemWriter where any changes
are written to a temporary file, and only on flush or close is that file
moved on top of the destination file. This should address #48.

Still to be decided if we actually want to implement the non-atomic mode at
first, as the semantics there aren't very clear. I.e. we might want to start with only
having an atomic mode.

index.bs Outdated
This is typically implemented by writing data to a temporary file, and only replacing the file
represented by |fileHandle| with the temporary file when the writer is closed.

If |truncate| is `true` or not specified, the temporary file starts out empty, otherwise the
Copy link
Collaborator

@oyiptong oyiptong May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a flag, how about an enum?

fopen provides the following options closest to what we want to achieve:

  • w for truncate mode
  • r+ for read/write, with the cursor at the beginning of the file

I like the idea of update to be the opposite of truncate.

If we want to contrast with fopen so there's no confusion, we can use slightly different enums:

enum FileSystemWriterMode {"truncate", "update"};

dictionary FileSystemCreateWriterOptions {
  FileSystemWriterMode mode = "truncate";
  boolean atomic = true;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with victor's suggested names for now.

Copy link
Collaborator

@pwnall pwnall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileSystemCreateWriterOptions is a great idea! Let's get that in.

I'd prefer that we discuss flush() separately.

index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
This attempts to solve #37 by making it explicit that changes made to files
might not be reflected on disk until flush() or close() is called on the
writer.

This also introduces a "atomic" mode for FileSystemWriter where any changes
are written to a temporary file, and only on flush or close is that file
moved on top of the destination file. This should address #48.
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.

None yet

3 participants