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

Use an atomic rename for the backup file, instead of just opening and writing #5931

Closed
obi1kenobi opened this issue Apr 4, 2016 · 10 comments
Assignees
Milestone

Comments

@obi1kenobi
Copy link
Contributor

I'm running OrientDB 2.1.9 configured with the backup plugin. I noticed that when backing up, the database simply opens its intended backup file and keeps writing data to it until finished. This is bad because it would leave the backup file corrupted in the event of a database crash mid-backup, but I wouldn't be able to notice since the file exists in its expected location.

A suggested solution is to do what other databases do -- write the backup to a separate file, say <intended_backup_filename>.tmp and when done writing the file, perform an atomic rename operation to change the name of the file from the .tmp one to the final filename.

This is a non-breaking change, since externally the behavior will be the same -- the backup file will have the same name and be in the same location. However, we will be guaranteed that any .zip files in the backup directory are valid backups and not corrupted.

@obi1kenobi
Copy link
Contributor Author

Is there a planned milestone for this?

@andrii0lomakin andrii0lomakin added this to the 3.0 milestone Oct 7, 2016
@andrii0lomakin
Copy link
Member

That is enhancement so I put it in 3.0 version

@taburet
Copy link
Contributor

taburet commented Jul 28, 2017

Implemented, closing.

@taburet taburet closed this as completed Jul 28, 2017
@obi1kenobi
Copy link
Contributor Author

The code in the linked diff doesn't actually perform an atomic rename operation -- the ATOMIC_MOVE option isn't set in the Files.move() method: https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#move(java.nio.file.Path,%20java.nio.file.Path,%20java.nio.file.CopyOption...)

@taburet
Copy link
Contributor

taburet commented Jul 30, 2017

@obi1kenobi thank you for the observation, reopening. Usually, if the file system supports atomic renames, regular renames are also atomic. Anyway, for the sake of strictness I will pass ATOMIC_MOVE and then fallback to regular move if the move can't be done atomically. WDYT?

@taburet taburet reopened this Jul 30, 2017
taburet added a commit that referenced this issue Jul 31, 2017
@taburet
Copy link
Contributor

taburet commented Jul 31, 2017

ATOMIC_MOVE is now used to move files, closing.

@taburet taburet closed this as completed Jul 31, 2017
@obi1kenobi
Copy link
Contributor Author

Looks great, thank you! It might also be good to log an error to inform the user that atomic moves are not supported by their system -- I definitely would like to know if that were the case for my database.

@taburet
Copy link
Contributor

taburet commented Jul 31, 2017

@obi1kenobi ok, I will add a warning to the log.

@taburet taburet reopened this Jul 31, 2017
@taburet
Copy link
Contributor

taburet commented Aug 1, 2017

Warning added: 2c5c1e3

@taburet taburet closed this as completed Aug 1, 2017
@obi1kenobi
Copy link
Contributor Author

Looks great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants