Answer the question
In order to leave comments, you need to log in
Is there some mechanism similar to db transactions, only for the file system?
Good tribute.
On the site, the user has the ability to create albums and upload photos to them. Photos can be uploaded in batches, after which they are yf cthdtht resized and saved. The photo is stored on the hard drive, plus a corresponding entry is made in the database.
Working with the database is done using ActiveRecords (Yii). The class describes the behavior: after saving the record to the database, the files are saved. I noticed that there are cases when the file is not written to disk.
I need to roll back all changes in case of a write error of at least one file. With base it is clear - transactions in the help. But what about files?
The only thing that comes to mind: in case of an error, manually delete all files that have already been saved. But somehow that's wrong.
Tell me, can there be some kind of mechanism similar to database transactions, only for the file system? Now ext4 is used, but it is possible to change to something more suitable.
Answer the question
In order to leave comments, you need to log in
everything is done through the database. create a separate table of tasks, for example, tasks for deleting files from a disk. and do like this
1. you need to save the file blabla.jpg
1a. enter in the table of tasks "delete blabla.jpg with a timeout for example 1 hour"
1b. create a file blabla.jpg
2. open a transaction
3. make an entry in the main table, where in one of the fields you save the associated file blabla.jpg (not the file itself, of course, but its name)
4. delete the entry made in paragraph 1a
5a. if there are no errors, close transaction
5b. if there are errors, roll back the transaction. The
second part of the scheme is a script that bypasses the job table and executes jobs from it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question