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

Datasets use atomic write when persisting to disk #307

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

mikesmit
Copy link
Collaborator

@mikesmit mikesmit commented Nov 8, 2024

Partially fixes PolicyEngine/policyengine-api#1954

Prior to this change dataset.download() would use a normal file write to persist downloaded data to disk.

This meant another process or thread could check for the file and attempt to read it before the full content was written.

This change uses a temporary file + a rename to update the file atomically.

If a process is already reading a file that the new verion overwrites, the previous file node is unlinked rather than being overwritten so the read will work as expected.

This will allow us to back out optimistically pre-loading dataset data before it is needed (and causing 404 errors when running tests on machines without the appropriate permissions to download UK data)

Thanks for contributing! Please remove any top-level sections that do not apply to your changes.

  • make format && make documentation has been run.

New variable

  • Label field added
  • Documentation field added
  • Unit field added
  • Default value field added if relevant
  • Variable name follows conventions
  • Unit test(s) added
  • Integration test(s) added if relevant
  • Issues this PR fixes linked

What's changed

See description in the commit above

Bug fix

  • Regression test added
  • Regression test passing

What this fixes and how it's fixed

See description in commit above

Partially fixes: #1954

Prior to this change dataset.download() would use a normal file write to
persist downloaded data to disk.

This meant another process or thread could check for the file and
attempt to read it before the full content was written.

This change uses a temporary file + a rename to update the file
atomically.

If a process is already reading a file that the new verion overwrites,
the previous file node is unlinked rather than being overwritten so the
read will work as expected.

This will allow us to back out optimistically pre-loading dataset data
before it is needed (and causing 404 errors when running tests on
machines without the appropriate permissions to download UK data)
Copy link
Contributor

@nikhilwoodruff nikhilwoodruff left a comment

Choose a reason for hiding this comment

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

I think we can merge- still useful, and doesn't seem like it can hurt.

changelog_entry.yaml Outdated Show resolved Hide resolved
@MaxGhenis MaxGhenis merged commit 6f3f426 into master Nov 11, 2024
3 checks passed
@MaxGhenis MaxGhenis deleted the 1954_add_atomic_write_for_datasets branch November 11, 2024 14:20
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.

make debug-test fails with 404 error
3 participants