On 12/07/2010 09:49 PM, Yoni Londner wrote:
> Hi,
>
> Yes, in this scheme the checksum is based on salt values and own frame
> content.a
>
> Note that the current design solve a potential DB corruption bug in
> sqlite. current WAL design is base on the fact that once sqlite writes
> pages successfully to the WAL, they will never get corrupted. but this
> assumption is not true. take for example the following situation:
>
> H 1 1 1 2 2 2 3 3 3 3
>
> We have here 10 pages in 3 transactions. lets say that sqlite stated a
> checkpoint, succesfully checkpointed transaction 1 and 2, and started
> copy transaction 3 to the DB. while copying the first pages of
> transaction 3, pages from transaction 4 are written to the WAL.
> now, since the pages most likely are not aligned to the sector size, the
> OS might read part of last page of transaction 3, and write it along
> with the first page of transaction 4.
> If a power failure occur at this point, then the first pages of
> transactions 3 already copied to the DB, while last page of transaction
> 3 is corrupted, so when recovering, sqlite will not complete copying
> transaction 3 to the DB, and DB we stay corrupted.

In synchronous=full mode, we add extra copies of the last frame of
each transaction (the one with the commit flag set) to beat this.
So the WAL log would look like this:

H 1 1 1a 1b 2 2 2a 2b 3 3 3...

Frame 1b is a copy of 1a, and 2b is a copy of 2a. So although a power 
failure while writing the first frame of transaction 3 can damage
frame 2b, this doesn't matter as it is just a duplicate.

There may be more than one duplicate inserted if the device has very
large sectors.

> while this problem can occur on any device, it is more likely to happen
> on devices which use flash memory (mostly mobile devices), since the
> size of a sector of flash memory tend to be larger than on non flash memory.

It's a real problem and it does come up in practice. You are right
to include a solution in your plan.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to