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 17 #ifndef _WAL_H_ 18 #define _WAL_H_ 19 20 #include "sqliteInt.h" 21 22 #ifdef SQLITE_OMIT_WAL 23 # define sqlite3WalOpen(x,y,z) 0 24 # define sqlite3WalClose(w,x,y,z) 0 25 # define sqlite3WalBeginReadTransaction(y,z) 0 26 # define sqlite3WalEndReadTransaction(z) 27 # define sqlite3WalRead(v,w,x,y,z) 0 28 # define sqlite3WalDbsize(y,z) 29 # define sqlite3WalBeginWriteTransaction(y) 0 30 # define sqlite3WalEndWriteTransaction(x) 0 31 # define sqlite3WalUndo(x,y,z) 0 32 # define sqlite3WalSavepoint(y,z) 33 # define sqlite3WalSavepointUndo(y,z) 0 34 # define sqlite3WalFrames(u,v,w,x,y,z) 0 35 # define sqlite3WalCheckpoint(u,v,w,x) 0 36 # define sqlite3WalCallback(z) 0 37 # define sqlite3WalExclusiveMode(y,z) 0 38 #else 39 40 #define WAL_SAVEPOINT_NDATA 4 41 42 /* Connection to a write-ahead log (WAL) file. 43 ** There is one object of this type for each pager. 44 */ 45 typedef struct Wal Wal; 46 47 /* Open and close a connection to a write-ahead log. */ 48 int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *zName, Wal**); 49 int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *); 50 51 /* Used by readers to open (lock) and close (unlock) a snapshot. A 52 ** snapshot is like a read-transaction. It is the state of the database 53 ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and 54 ** preserves the current state even if the other threads or processes 55 ** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the 56 ** transaction and releases the lock. 57 */ 58 int sqlite3WalBeginReadTransaction(Wal *pWal, int *); 59 void sqlite3WalEndReadTransaction(Wal *pWal); 60 61 /* Read a page from the write-ahead log, if it is present. */ 62 int sqlite3WalRead(Wal *pWal, Pgno pgno, int *pInWal, int nOut, u8 *pOut); 63 64 /* Return the size of the database as it existed at the beginning 65 ** of the snapshot */ 66 void sqlite3WalDbsize(Wal *pWal, Pgno *pPgno); 67 68 /* Obtain or release the WRITER lock. */ 69 int sqlite3WalBeginWriteTransaction(Wal *pWal); 70 int sqlite3WalEndWriteTransaction(Wal *pWal); 71 72 /* Undo any frames written (but not committed) to the log */ 73 int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx); 74 75 /* Return an integer that records the current (uncommitted) write 76 ** position in the WAL */ 77 void sqlite3WalSavepoint(Wal *pWal, u32 *aWalData); 78 79 /* Move the write position of the WAL back to iFrame. Called in 80 ** response to a ROLLBACK TO command. */ 81 int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData); 82 83 /* Write a frame or frames to the log. */ 84 int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int); 85 86 /* Copy pages from the log to the database file */ 87 int sqlite3WalCheckpoint( 88 Wal *pWal, /* Write-ahead log connection */ 89 int sync_flags, /* Flags to sync db file with (or 0) */ 90 int nBuf, /* Size of buffer nBuf */ 91 u8 *zBuf /* Temporary buffer to use */ 92 ); 93 94 /* Return the value to pass to a sqlite3_wal_hook callback, the 95 ** number of frames in the WAL at the point of the last commit since 96 ** sqlite3WalCallback() was called. If no commits have occurred since 97 ** the last call, then return 0. 98 */ 99 int sqlite3WalCallback(Wal *pWal); 100 101 /* Tell the wal layer that an EXCLUSIVE lock has been obtained (or released) 102 ** by the pager layer on the database file. 103 */ 104 int sqlite3WalExclusiveMode(Wal *pWal, int op); 105 106 #endif /* ifndef SQLITE_OMIT_WAL */ 107 #endif /* _WAL_H_ */ 108