Skip to contentSkip to conversation

integrity question

DISCUSSION Toby Dickenson 3 participants 5 messages May 25, 2002 – May 28, 2002

lore
Share & tools
lore
#0 lore raw

I am developing a storage layer for the ZODB object database, which is designed to play to reiserfs strengths.

http://sourceforge.net/projects/dirstorage

I have a question about how much fsyncing is necessary to avoid losing files on power loss, when moving them between directories.

Consider this sequence

1. write to A/B/somefileX and fsync it
2. mkdir A/C
3. rename A/B/somefile to A/C/somefile
4. rmdir A/B
5. power loss

I would like to guarantee that, after journal replay, 'somefile' is in either of those two directories (or both). Am I correct to think that I dont need any other syncs in there?

(A second question; is there any documentation that I could have used to answer the first question myself?)

#1 lore raw
Quoted 16 lines · Toby Dickenson

I am developing a storage layer for the ZODB object database, which is designed to play to reiserfs strengths.

http://sourceforge.net/projects/dirstorage

I have a question about how much fsyncing is necessary to avoid losing files on power loss, when moving them between directories.

Consider this sequence

1. write to A/B/somefileX and fsync it
2. mkdir A/C
3. rename A/B/somefile to A/C/somefile
4. rmdir A/B
5. power loss

Quoted 3 lines

I would like to guarantee that, after journal replay, 'somefile' is in either of those two directories (or both). Am I correct to think that I dont need any other syncs in there?

You are correct, renames are atomic on journalling filesystems. So, no problems with half-written directory entries, if you lose power at the wrong time the journal replay procedure will throw the transaction out and you end up as if you never issued a rename at all.

Quoted 2 lines

(A second question; is there any documentation that I could have used to answer the first question myself?)

I can't point to specific documentation, but this behavior is part of the main ideas behind journalling filesystems. You would get basically the same thing with ext3, XFS, JFS, Solaris UFS with the logging option, etc.

Of course, you could always scan some mailing list archives ;)

reiserfs-list and linux-XFS are quite active and contain very valuable insights.

Jean-Francois Landry

Signature · 4 lines
Any sufficiently complicated C or Fortran program contains an ad hoc
informally-specified bug-ridden slow implementation of half of Common Lisp.
        Greenspun's Tenth Rule
--
#2 lore raw

On Sunday 26 May 2002 6:25 am, Jean-Francois Landry wrote:

thanks for your time,

Quoted 6 lines
Quoted 6 lines

1. write to A/B/somefileX and fsync it
2. mkdir A/C
3. rename A/B/somefile to A/C/somefile
4. rmdir A/B
5. power loss

Quoted 8 lines
Quoted 3 lines

I would like to guarantee that, after journal replay, 'somefile' is in either of those two directories (or both). Am I correct to think that I dont need any other syncs in there?

You are correct, renames are atomic on journalling filesystems. So, no problems with half-written directory entries, if you lose power at the wrong time the journal replay procedure will throw the transaction out and you end up as if you never issued a rename at all.

Atomic rename isnt quite enough in the scenario I described. The filesystem also needs to take care that the step 3 is not committed before step 2, and that step 4 is not committed before step 3.

Quoted 2 lines

I can't point to specific documentation, but this behavior is part of the main ideas behind journalling filesystems.

I would be very happy to find that I am worrying over a problem that does not exist.

#3 lore raw
Quoted 14 lines · Toby Dickenson

On Sunday 26 May 2002 6:25 am, Jean-Francois Landry wrote:

thanks for your time,

Quoted 10 lines
Quoted 9 lines

1. write to A/B/somefileX and fsync it
2. mkdir A/C
3. rename A/B/somefile to A/C/somefile
4. rmdir A/B
5. power loss

I would like to guarantee that, after journal replay, 'somefile' is in either of those two directories (or both). Am I correct to think that I dont need any other syncs in there?

Quoted 8 lines
Quoted 4 lines

You are correct, renames are atomic on journalling filesystems. So, no problems with half-written directory entries, if you lose power at the wrong time the journal replay procedure will throw the transaction out and you end up as if you never issued a rename at all.

Atomic rename isnt quite enough in the scenario I described. The filesystem also needs to take care that the step 3 is not committed before step 2, and that step 4 is not committed before step 3.

AFAIK, all transactions are written to the journal in the order they were issued, so this problem won't arise.

Quoted 4 lines

I would be very happy to find that I am worrying over a problem that does not exist.

I am not aware of a journalling filesystem that does not guarantee the two points you mentionned. You can relax now :)

Jean-Francois Landry

Signature · 3 lines
'Instead of asking why a piece of software is using "1970s technology,"
 start asking why software is ignoring 30 years of accumulated wisdom.'
--
#4 lore raw
Quoted 20 lines · Jean-Francois Landry
Quoted 19 lines · Toby Dickenson

On Sunday 26 May 2002 6:25 am, Jean-Francois Landry wrote:

thanks for your time,

Quoted 14 lines
Quoted 9 lines

1. write to A/B/somefileX and fsync it
2. mkdir A/C
3. rename A/B/somefile to A/C/somefile
4. rmdir A/B
5. power loss

I would like to guarantee that, after journal replay, 'somefile' is in either of those two directories (or both). Am I correct to think that I dont need any other syncs in there?

You are correct, renames are atomic on journalling filesystems. So, no problems with half-written directory entries, if you lose power at the wrong time the journal replay procedure will throw the transaction out and you end up as if you never issued a rename at all.

Quoted 6 lines
Quoted 3 lines

Atomic rename isnt quite enough in the scenario I described. The filesystem also needs to take care that the step 3 is not committed before step 2, and that step 4 is not committed before step 3.

AFAIK, all transactions are written to the journal in the order they were issued, so this problem won't arise.

Correct. Only data blocks can be written out of order, but the fsync protects you from that.

-chris