blob: bf40c3bd9f358cff6357f198ec53388c19068080 [file] [log] [blame]
dan6700d022010-04-12 19:05:58 +00001/*
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
drhc438efd2010-04-26 00:19:45 +000017#ifndef _WAL_H_
18#define _WAL_H_
dan6700d022010-04-12 19:05:58 +000019
20#include "sqliteInt.h"
21
dan5cf53532010-05-01 16:40:20 +000022#ifdef SQLITE_OMIT_WAL
23# define sqlite3WalOpen(x,y,z) 0
24# define sqlite3WalClose(w,x,y,z) 0
25# define sqlite3WalOpenSnapshot(y,z) 0
26# define sqlite3WalCloseSnapshot(z)
danb6e099a2010-05-04 14:47:39 +000027# define sqlite3WalRead(v,w,x,y,z) 0
dan5cf53532010-05-01 16:40:20 +000028# define sqlite3WalDbsize(y,z)
29# define sqlite3WalWriteLock(y,z) 0
30# define sqlite3WalUndo(x,y,z) 0
dan71d89912010-05-24 13:57:42 +000031# define sqlite3WalSavepoint(y,z)
dan5cf53532010-05-01 16:40:20 +000032# define sqlite3WalSavepointUndo(y,z) 0
33# define sqlite3WalFrames(u,v,w,x,y,z) 0
34# define sqlite3WalCheckpoint(u,v,w,x,y,z) 0
35# define sqlite3WalCallback(z) 0
36#else
37
dan71d89912010-05-24 13:57:42 +000038#define WAL_SAVEPOINT_NDATA 3
39
drh833bf962010-04-28 14:42:19 +000040/* Connection to a write-ahead log (WAL) file.
41** There is one object of this type for each pager.
42*/
drh7ed91f22010-04-29 22:34:07 +000043typedef struct Wal Wal;
dan6700d022010-04-12 19:05:58 +000044
drh833bf962010-04-28 14:42:19 +000045/* Open and close a connection to a write-ahead log. */
drhd9e5c4f2010-05-12 18:01:39 +000046int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *zName, Wal**);
47int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *);
dan6700d022010-04-12 19:05:58 +000048
drh833bf962010-04-28 14:42:19 +000049/* Used by readers to open (lock) and close (unlock) a snapshot. A
50** snapshot is like a read-transaction. It is the state of the database
51** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
52** preserves the current state even if the other threads or processes
53** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the
54** transaction and releases the lock.
55*/
drh7ed91f22010-04-29 22:34:07 +000056int sqlite3WalOpenSnapshot(Wal *pWal, int *);
57void sqlite3WalCloseSnapshot(Wal *pWal);
dan6700d022010-04-12 19:05:58 +000058
drh833bf962010-04-28 14:42:19 +000059/* Read a page from the write-ahead log, if it is present. */
danb6e099a2010-05-04 14:47:39 +000060int sqlite3WalRead(Wal *pWal, Pgno pgno, int *pInWal, int nOut, u8 *pOut);
drh833bf962010-04-28 14:42:19 +000061
62/* Return the size of the database as it existed at the beginning
63** of the snapshot */
drh7ed91f22010-04-29 22:34:07 +000064void sqlite3WalDbsize(Wal *pWal, Pgno *pPgno);
dan6700d022010-04-12 19:05:58 +000065
66/* Obtain or release the WRITER lock. */
drh7ed91f22010-04-29 22:34:07 +000067int sqlite3WalWriteLock(Wal *pWal, int op);
dan6700d022010-04-12 19:05:58 +000068
dan74d6cd82010-04-24 18:44:05 +000069/* Undo any frames written (but not committed) to the log */
drh7ed91f22010-04-29 22:34:07 +000070int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx);
dan74d6cd82010-04-24 18:44:05 +000071
drh833bf962010-04-28 14:42:19 +000072/* Return an integer that records the current (uncommitted) write
73** position in the WAL */
dan71d89912010-05-24 13:57:42 +000074void sqlite3WalSavepoint(Wal *pWal, u32 *aWalData);
drh833bf962010-04-28 14:42:19 +000075
76/* Move the write position of the WAL back to iFrame. Called in
77** response to a ROLLBACK TO command. */
dan71d89912010-05-24 13:57:42 +000078int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData);
dan4cd78b42010-04-26 16:57:10 +000079
danc5118782010-04-17 17:34:41 +000080/* Write a frame or frames to the log. */
drh7ed91f22010-04-29 22:34:07 +000081int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int);
dan6700d022010-04-12 19:05:58 +000082
83/* Copy pages from the log to the database file */
drhc438efd2010-04-26 00:19:45 +000084int sqlite3WalCheckpoint(
drh7ed91f22010-04-29 22:34:07 +000085 Wal *pWal, /* Write-ahead log connection */
danc5118782010-04-17 17:34:41 +000086 int sync_flags, /* Flags to sync db file with (or 0) */
danb6e099a2010-05-04 14:47:39 +000087 int nBuf, /* Size of buffer nBuf */
dan64d039e2010-04-13 19:27:31 +000088 u8 *zBuf, /* Temporary buffer to use */
89 int (*xBusyHandler)(void *), /* Pointer to busy-handler function */
90 void *pBusyHandlerArg /* Argument to pass to xBusyHandler */
dan6700d022010-04-12 19:05:58 +000091);
92
drh833bf962010-04-28 14:42:19 +000093/* 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*/
drh7ed91f22010-04-29 22:34:07 +000098int sqlite3WalCallback(Wal *pWal);
dan8d22a172010-04-19 18:03:51 +000099
dan55437592010-05-11 12:19:26 +0000100/* Tell the wal layer that an EXCLUSIVE lock has been obtained (or released)
101** by the pager layer on the database file.
102*/
103int sqlite3WalExclusiveMode(Wal *pWal, int op);
104
dan5cf53532010-05-01 16:40:20 +0000105#endif /* ifndef SQLITE_OMIT_WAL */
drhc438efd2010-04-26 00:19:45 +0000106#endif /* _WAL_H_ */