Skip to content

ROBUSTNESS: Write RDS files atomically #317

@HenrikBengtsson

Description

@HenrikBengtsson

Issue

When writing an RDS file, it might fail half way through, resulting in an incomplete, corrupt file. Similarly, if one process attempts to read a file that is currently being written by another process, the read might occur on an incomplete file.

Suggestion

Always write RDS file atomically. This can be achieved by writing to *.rds.tmp and then rename the file to *.rds after saveRDS() completes. This way the target *.rds is guaranteed to be complete.

By writing to *.rds.tmp instead of tempfile() guarantees that we write to the same drive, avoiding cross-drive moves and copies.

Patch

See PR #316 for a patch. I updated writeRDS() to write atomically and I've added wait = 300, which can optionally be set to wait = 0. The latter is used to replace two remaining saveRDS() uses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions