On Tue, Sep 20, 2011 at 8:46 AM, Berthier, Emmanuel <
emmanuel.berth...@intel.com> wrote:

>
> I managed the FS mount option and this partition is mount write-back mode
> with barrier=1.
> That's the critical point: referring the documentation, this configuration
> should be safe enough.
> How can I get wrong file size or wrong page nb in the header?
>

I don't know what is going wrong in your particular case.  But problems like
this usually proceed as follows:  The operating system tells the disk
controller "write these sectors and let me know when they are safely on
persistent storage."  The disk controller receives the sectors into its
track cache, and then replies to the OS "all is safely stored" before it
really has written the content to persistent storage.  The operating system
sends some more sectors to be written.  The disk controller writes these
latter sectors first, then a power failure occurs before the initial sectors
are completely written.

That's the usual scenario with spinning media.  I'm less familiar with the
internal workings of flash memory controllers.  But people tell me that they
fail in similar ways.

The bottom line is this:  SQLite uses fsync() as a write barrier.  All
writes that SQLite issues prior to the fsync() must complete prior to any
writes issued after the fsync().  As long as that rule is kept, you won't
get corruption.  Unfortunately, not all combinations of
linux+filesystem+disk/flash-controller keep this rule.

Since version 3.7.0, SQLite has support Write-Ahead Logging (WAL) for
transaction control.  WAL still depends on fsync() as a write barrier.  So
if your OS+hardware does not respect fsync() as a write barrier you can
still get corruption following a power-loss or OS panic.  But, while WAL
does still have some dependence on write barriers, it makes much less use of
write barriers than the older rollback transaction control mechanisms of
3.6.23.  And so your window of vulnerability is much smaller and you are
much less likely to encounter problems.

-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to