pager-invariants.txt 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. *** Throughout this document, a page is deemed to have been synced
  2. automatically as soon as it is written when PRAGMA synchronous=OFF.
  3. Otherwise, the page is not synced until the xSync method of the VFS
  4. is called successfully on the file containing the page.
  5. *** Definition: A page of the database file is said to be "overwriteable" if
  6. one or more of the following are true about the page:
  7. (a) The original content of the page as it was at the beginning of
  8. the transaction has been written into the rollback journal and
  9. synced.
  10. (b) The page was a freelist leaf page at the start of the transaction.
  11. (c) The page number is greater than the largest page that existed in
  12. the database file at the start of the transaction.
  13. (1) A page of the database file is never overwritten unless one of the
  14. following are true:
  15. (a) The page and all other pages on the same sector are overwriteable.
  16. (b) The atomic page write optimization is enabled, and the entire
  17. transaction other than the update of the transaction sequence
  18. number consists of a single page change.
  19. (2) The content of a page written into the rollback journal exactly matches
  20. both the content in the database when the rollback journal was written
  21. and the content in the database at the beginning of the current
  22. transaction.
  23. (3) Writes to the database file are an integer multiple of the page size
  24. in length and are aligned to a page boundary.
  25. (4) Reads from the database file are either aligned on a page boundary and
  26. an integer multiple of the page size in length or are taken from the
  27. first 100 bytes of the database file.
  28. (5) All writes to the database file are synced prior to the rollback journal
  29. being deleted, truncated, or zeroed.
  30. (6) If a master journal file is used, then all writes to the database file
  31. are synced prior to the master journal being deleted.
  32. *** Definition: Two databases (or the same database at two points it time)
  33. are said to be "logically equivalent" if they give the same answer to
  34. all queries. Note in particular the content of freelist leaf
  35. pages can be changed arbitarily without effecting the logical equivalence
  36. of the database.
  37. (7) At any time, if any subset, including the empty set and the total set,
  38. of the unsynced changes to a rollback journal are removed and the
  39. journal is rolled back, the resulting database file will be logical
  40. equivalent to the database file at the beginning of the transaction.
  41. (8) When a transaction is rolled back, the xTruncate method of the VFS
  42. is called to restore the database file to the same size it was at
  43. the beginning of the transaction. (In some VFSes, the xTruncate
  44. method is a no-op, but that does not change the fact the SQLite will
  45. invoke it.)
  46. (9) Whenever the database file is modified, at least one bit in the range
  47. of bytes from 24 through 39 inclusive will be changed prior to releasing
  48. the EXCLUSIVE lock.
  49. (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
  50. than one billion transactions.
  51. (11) A database file is well-formed at the beginning and at the conclusion
  52. of every transaction.
  53. (12) An EXCLUSIVE lock must be held on the database file before making
  54. any changes to the database file.
  55. (13) A SHARED lock must be held on the database file before reading any
  56. content out of the database file.