Small. Fast. Reliable.
Choose any three.
*** 17,22 ****
--- 17,23 ----
  in the middle of a commit.  We had intended to modify
  three pages of the database file, but only one page
  was fully written and another page was partially written.
+ So the database is in an inconsistent state.
  (The writes are shown in red.)  The rollback journal
  still exists as a separate file on disk.
  
***************
*** 51,59 ****
  
  If the process is unable to get an exclusive lock, it backs
  off.  It releases its shared lock and returns SQLITE_BUSY.
  
! _To Be Continue...._
  
  
  {clear}
  ----
--- 52,107 ----
  
  If the process is unable to get an exclusive lock, it backs
  off.  It releases its shared lock and returns SQLITE_BUSY.
+ Presumably it will try again to get its shared lock after
+ a delay of a few milliseconds, and by that point some other
+ process will have already completed the recovery.
  
! {clear}
! 
! ----
! {rightimage: rollback-3.gif}
! *Step 3*
! 
! After we have an exclusive lock on the database, the original
! content of all database pages that were to be changed by the
! transaction that failed are read from the rollback journal
! and written into the database file.  This restores the database
! file to the same content it held prior to the start of the
! transaction.
! 
! We have not shown it here, but a sync operation must be performed
! in order to force the database out to the disk surface prior
! to the next step.
! 
! {clear}
! 
! ----
! {rightimage: rollback-4.gif}
! *Step 4*
  
+ Once the database file is restored to its original content prior
+ to the start of the transaction, the rollback journal can be
+ deleted.  The failed transaction has been completely rolled back
+ so the journal is no longer needed.
  
  {clear}
+ 
+ ----
+ {rightimage: rollback-5.gif}
+ *Step 5*
+ 
+ Finally, the lock on the file can drop back from exclusive to
+ shared and the database connection can continue as normal.
+ 
+ SQLite performs all of the above steps automatically
+ and transparently
+ on the first attempt to read a database that has suffered
+ a failed transaction.
+ The programming that is calling SQLite never knows that anything
+ unusual has taken place.  From the point of view of the SQLite
+ client, it is as if the database had never been corrupted by
+ a power failure or OS crash in the first place.
+ 
+ {clear}
+ 
  ----