views:

47

answers:

2

There's a following statement in SQLite FAQ:

A transaction normally requires two complete rotations of the disk platter, which on a 7200RPM disk drive limits you to about 60 transactions per second.

As I know there's a cache on the harddisk and there might be also an extra cache in the disk driver that abstract the operation that is perceived by the software from the actual operation against the disk platter.

Then why and how exactly are transactions so strictly bound to disk platter rotation?

+1  A: 

Because it ensures data integrity by making sure the data is actually written on to the disk rather than held in memory. Thus if the power goes off or something, the database is not corrupted.

This video http://www.youtube.com/watch?v=f428dSRkTs4 talks about reasons why (e.g. because SQLite is actually used in a lot of embedded devices where the power might well suddenly go off.)

Kinopiko
Why is there a guarantee that the disk controller will actuall perform the write?
sharptooth
Sorry but I don't know all the details of how it works.
Kinopiko
But that's the key problem. If the disk controller can delay the actual write for unknown period there's no point in bounding to rotation - the program can skip whatever number of rotations, yet no write to the platter will occur.
sharptooth
@Nick D: I guess this explains a lot and should go as an answer, not comment.
sharptooth
Disk manufacturers aren't entirely stupid, and do not delay writes needlessly. See for more details http://serverfault.com/questions/15404/sata-disks-that-handle-write-caching-properly
MSalters
+1  A: 

From Atomic Commit In SQLite

2.0 Hardware Assumptions

SQLite assumes that the operating system will buffer writes and that a write request will return before data has actually been stored in the mass storage device. SQLite further assumes that write operations will be reordered by the operating system. For this reason, SQLite does a "flush" or "fsync" operation at key points. SQLite assumes that the flush or fsync will not return until all pending write operations for the file that is being flushed have completed. We are told that the flush and fsync primitives are broken on some versions of Windows and Linux. This is unfortunate. It opens SQLite up to the possibility of database corruption following a power loss in the middle of a commit. However, there is nothing that SQLite can do to test for or remedy the situation. SQLite assumes that the operating system that it is running on works as advertised. If that is not quite the case, well then hopefully you will not lose power too often.

Nick D