Zero length files - an alternative approach?
Just a thought on the ongoing discussion of dataloss with ext4 vs ext3.
Taking the common scenario:
Read oldfile
create newfile file
write newfile data
close newfile
rename newfile to oldfile
When using this scenario, the application writer wants to ensure that either the old or new content are present. With delayed allocation, this can lead to zero length files. Most of the suggestions on how to address this have involved syncing the data either before the rename or making the rename sync the data.
What about, instead of 'bringing forward' the allocation and flushing of the data, would it be possible to instead delay the rename until after the blocks for newfile have been allocated and the data buffers flushed? This would keep the performance benefits of delayed allocation etc and also satisfy the applications developers' apparent dislike of using fsync(). It would give better performance that syncing the data at rename time (either using fsync() or automatically) and satisfy the requirements that either the old or new content is present.
I am not a filesystem developer, so do not know how feasible this would be.
Quoted 15 lines · Graham Murray
Just a thought on the ongoing discussion of dataloss with ext4 vs ext3.
Taking the common scenario:
Read oldfile
create newfile file
write newfile data
close newfile
rename newfile to oldfileWhen using this scenario, the application writer wants to ensure that either the old or new content are present. With delayed allocation, this can lead to zero length files. Most of the suggestions on how to address this have involved syncing the data either before the rename or making the rename sync the data.
Quoted 8 lines
What about, instead of 'bringing forward' the allocation and flushing of the data, would it be possible to instead delay the rename until after the blocks for newfile have been allocated and the data buffers flushed? This would keep the performance benefits of delayed allocation etc and also satisfy the applications developers' apparent dislike of using
fsync(). It would give better performance that syncing the data at rename time (either usingfsync()or automatically) and satisfy the requirements that either the old or new content is present.
Consider this scenario:
1. Create/write/close newfile
2. Rename newfile to oldfile
3. Open/read oldfile. This must return the new contents.
4. System crash and reboot before delayed allocation/flush complete
5. Open/read oldfile. Old contents now returned.
This rollback isn't obviously, to me at least, without problems of its own.
Signature · 2 lines
Måns Rullgård [email protected]
Quoted 12 lines · On 29.03.2009 13:22 Måns Rullgård wrote:
Consider this scenario:
1. Create/write/close newfile
2. Rename newfile to oldfile
3. Open/read oldfile. This must return the new contents.
4. System crash and reboot before delayed allocation/flush complete
5. Open/read oldfile. Old contents now returned.This rollback isn't obviously, to me at least, without problems of its own.
Having the old data in 5) is far better than having no data in 5).
Quoted 9 lines · Andreas T.Auer
Quoted 8 lines · On 29.03.2009 13:22 Måns Rullgård wrote:
Consider this scenario:
1. Create/write/close newfile
2. Rename newfile to oldfile
3. Open/read oldfile. This must return the new contents.
4. System crash and reboot before delayed allocation/flush complete
5. Open/read oldfile. Old contents now returned.
Quoted 4 lines
Quoted 3 lines
This rollback isn't obviously, to me at least, without problems of its own.
Having the old data in 5) is far better than having no data in 5).
Of course having old data is better than no data. However, fsync() and similar approaches make a rollback to old data after new data has been visible impossible or far less likely than the suggested one. I'm not saying it's necessarily a problem, only that it is a difference that should be taken into account.
Signature · 6 lines
Måns Rullgård [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · M?ns Rullg?rd
Quoted 9 lines · Andreas T.Auer
Quoted 8 lines · On 29.03.2009 13:22 M?ns Rullg?rd wrote:
Consider this scenario:
1. Create/write/close newfile
2. Rename newfile to oldfile
3. Open/read oldfile. This must return the new contents.
4. System crash and reboot before delayed allocation/flush complete
5. Open/read oldfile. Old contents now returned.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
This rollback isn't obviously, to me at least, without problems of its own.
Having the old data in 5) is far better than having no data in 5).
Of course having old data is better than no data. However,
fsync()and similar approaches make a rollback to old data after new data has been visible impossible or far less likely than the suggested one.
Untrue. Unless you fsync after rename, you can get olddata.
fsync() is easy. But some people _want_ to have either newdata _or_ olddata, but don't care which one, and would prefer to avoid fsync. That's where replace() should help...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 24 lines · Graham Murray
Just a thought on the ongoing discussion of dataloss with ext4 vs ext3.
Taking the common scenario:
Read oldfile
create newfile file
write newfile data
close newfile
rename newfile to oldfileWhen using this scenario, the application writer wants to ensure that either the old or new content are present. With delayed allocation, this can lead to zero length files. Most of the suggestions on how to address this have involved syncing the data either before the rename or making the rename sync the data.
What about, instead of 'bringing forward' the allocation and flushing of the data, would it be possible to instead delay the rename until after the blocks for newfile have been allocated and the data buffers flushed? This would keep the performance benefits of delayed allocation etc and also satisfy the applications developers' apparent dislike of using
fsync(). It would give better performance that syncing the data at rename time (either usingfsync()or automatically) and satisfy the requirements that either the old or new content is present.
Quoted 3 lines
I am not a filesystem developer, so do not know how feasible this would be.
This has been suggested, I believe. In filesystem terms, it means inserting a barrier before the rename operation, meaning that any write operations needed to carry out the rename must not take place until all write operations from the previous calls have completed.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 3 lines · Pavel Machek
fsync()is easy. But some people _want_ to have either newdata _or_ olddata, but don't care which one, and would prefer to avoid fsync. That's wherereplace()should help...
Most people, I wager, care more about their code being portable than they do about leaping through a Linux-specific hoop. They're not going to use replace; not ever; that's what link/unlink is for.
If you think it's reasonable to modify every instance in applications where a sudden crash would cause data loss, why not make a mount-time flag that does all of that in FS; and for the other 99% of users, it doesn't, but runs faster?
Quoted 26 lines · Måns Rullgård
Quoted 15 lines · Graham Murray
Just a thought on the ongoing discussion of dataloss with ext4 vs ext3.
Taking the common scenario:
Read oldfile
create newfile file
write newfile data
close newfile
rename newfile to oldfileWhen using this scenario, the application writer wants to ensure that either the old or new content are present. With delayed allocation, this can lead to zero length files. Most of the suggestions on how to address this have involved syncing the data either before the rename or making the rename sync the data.
Quoted 8 lines
What about, instead of 'bringing forward' the allocation and flushing of the data, would it be possible to instead delay the rename until after the blocks for newfile have been allocated and the data buffers flushed? This would keep the performance benefits of delayed allocation etc and also satisfy the applications developers' apparent dislike of using
fsync(). It would give better performance that syncing the data at rename time (either usingfsync()or automatically) and satisfy the requirements that either the old or new content is present.
Quoted 4 lines
Consider this scenario:
1. Create/write/close newfile
2. Rename newfile to oldfile
2a. create oldfile again
2b. fsync oldfile
Quoted 4 lines
3. Open/read oldfile. This must return the new contents.
4. System crash and reboot before delayed allocation/flush complete
5. Open/read oldfile. Old contents now returned.
What happens to the new generation of oldfile? We could insert dependency tracking so that we know the fsync of oldfile is supposed to also fsync the rename'd new file. But then picture a loop of operations doing renames and creating files in the place of the old one...that dependency tracking gets ugly in a hurry.
Databases know how to do all of this, but filesystems don't implement most of the database transactional features.
-chris
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 14 lines · Chris Mason
Quoted 5 lines
Consider this scenario:
1. Create/write/close newfile
2. Rename newfile to oldfile2a. create oldfile again
2b. fsync oldfileQuoted 4 lines
3. Open/read oldfile. This must return the new contents.
4. System crash and reboot before delayed allocation/flush complete
5. Open/read oldfile. Old contents now returned.
Quoted 5 lines
What happens to the new generation of oldfile? We could insert dependency tracking so that we know the fsync of oldfile is supposed to also fsync the rename'd new file. But then picture a loop of operations doing renames and creating files in the place of the old one...that dependency tracking gets ugly in a hurry.
If there are any calls to link(2) to create hard links to oldfile or newfile intermingled in this sequence, life also gets very entertaining.
Quoted 2 lines
Databases know how to do all of this, but filesystems don't implement most of the database transactional features.
Yep, we'd have to implement a rollback log to get this right, which would also impact performance. My guess is that just aggressively forcing out the data write before the rename() is going to cost less in performance, and is certainly much easier to implement.
- Ted