wal.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. ** 2010 February 1
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. ** This header file defines the interface to the write-ahead logging
  13. ** system. Refer to the comments below and the header comment attached to
  14. ** the implementation of each function in log.c for further details.
  15. */
  16. #ifndef _WAL_H_
  17. #define _WAL_H_
  18. #include "sqliteInt.h"
  19. /* Additional values that can be added to the sync_flags argument of
  20. ** sqlite3WalFrames():
  21. */
  22. #define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */
  23. #define SQLITE_SYNC_MASK 0x13 /* Mask off the SQLITE_SYNC_* values */
  24. #ifdef SQLITE_OMIT_WAL
  25. # define sqlite3WalOpen(x,y,z) 0
  26. # define sqlite3WalLimit(x,y)
  27. # define sqlite3WalClose(w,x,y,z) 0
  28. # define sqlite3WalBeginReadTransaction(y,z) 0
  29. # define sqlite3WalEndReadTransaction(z)
  30. # define sqlite3WalDbsize(y) 0
  31. # define sqlite3WalBeginWriteTransaction(y) 0
  32. # define sqlite3WalEndWriteTransaction(x) 0
  33. # define sqlite3WalUndo(x,y,z) 0
  34. # define sqlite3WalSavepoint(y,z)
  35. # define sqlite3WalSavepointUndo(y,z) 0
  36. # define sqlite3WalFrames(u,v,w,x,y,z) 0
  37. # define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0
  38. # define sqlite3WalCallback(z) 0
  39. # define sqlite3WalExclusiveMode(y,z) 0
  40. # define sqlite3WalHeapMemory(z) 0
  41. # define sqlite3WalFramesize(z) 0
  42. # define sqlite3WalFindFrame(x,y,z) 0
  43. #else
  44. #define WAL_SAVEPOINT_NDATA 4
  45. /* Connection to a write-ahead log (WAL) file.
  46. ** There is one object of this type for each pager.
  47. */
  48. typedef struct Wal Wal;
  49. /* Open and close a connection to a write-ahead log. */
  50. int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *, int, i64, Wal**);
  51. int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *);
  52. /* Set the limiting size of a WAL file. */
  53. void sqlite3WalLimit(Wal*, i64);
  54. /* Used by readers to open (lock) and close (unlock) a snapshot. A
  55. ** snapshot is like a read-transaction. It is the state of the database
  56. ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
  57. ** preserves the current state even if the other threads or processes
  58. ** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the
  59. ** transaction and releases the lock.
  60. */
  61. int sqlite3WalBeginReadTransaction(Wal *pWal, int *);
  62. void sqlite3WalEndReadTransaction(Wal *pWal);
  63. /* Read a page from the write-ahead log, if it is present. */
  64. int sqlite3WalFindFrame(Wal *, Pgno, u32 *);
  65. int sqlite3WalReadFrame(Wal *, u32, int, u8 *);
  66. /* If the WAL is not empty, return the size of the database. */
  67. Pgno sqlite3WalDbsize(Wal *pWal);
  68. /* Obtain or release the WRITER lock. */
  69. int sqlite3WalBeginWriteTransaction(Wal *pWal);
  70. int sqlite3WalEndWriteTransaction(Wal *pWal);
  71. /* Undo any frames written (but not committed) to the log */
  72. int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx);
  73. /* Return an integer that records the current (uncommitted) write
  74. ** position in the WAL */
  75. void sqlite3WalSavepoint(Wal *pWal, u32 *aWalData);
  76. /* Move the write position of the WAL back to iFrame. Called in
  77. ** response to a ROLLBACK TO command. */
  78. int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData);
  79. /* Write a frame or frames to the log. */
  80. int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int);
  81. /* Copy pages from the log to the database file */
  82. int sqlite3WalCheckpoint(
  83. Wal *pWal, /* Write-ahead log connection */
  84. int eMode, /* One of PASSIVE, FULL and RESTART */
  85. int (*xBusy)(void*), /* Function to call when busy */
  86. void *pBusyArg, /* Context argument for xBusyHandler */
  87. int sync_flags, /* Flags to sync db file with (or 0) */
  88. int nBuf, /* Size of buffer nBuf */
  89. u8 *zBuf, /* Temporary buffer to use */
  90. int *pnLog, /* OUT: Number of frames in WAL */
  91. int *pnCkpt /* OUT: Number of backfilled frames in WAL */
  92. );
  93. /* Return the value to pass to a sqlite3_wal_hook callback, the
  94. ** number of frames in the WAL at the point of the last commit since
  95. ** sqlite3WalCallback() was called. If no commits have occurred since
  96. ** the last call, then return 0.
  97. */
  98. int sqlite3WalCallback(Wal *pWal);
  99. /* Tell the wal layer that an EXCLUSIVE lock has been obtained (or released)
  100. ** by the pager layer on the database file.
  101. */
  102. int sqlite3WalExclusiveMode(Wal *pWal, int op);
  103. /* Return true if the argument is non-NULL and the WAL module is using
  104. ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
  105. ** WAL module is using shared-memory, return false.
  106. */
  107. int sqlite3WalHeapMemory(Wal *pWal);
  108. #ifdef SQLITE_ENABLE_ZIPVFS
  109. /* If the WAL file is not empty, return the number of bytes of content
  110. ** stored in each frame (i.e. the db page-size when the WAL was created).
  111. */
  112. int sqlite3WalFramesize(Wal *pWal);
  113. #endif
  114. #endif /* ifndef SQLITE_OMIT_WAL */
  115. #endif /* _WAL_H_ */