blob: c53e41d5eaca29a83921a86cc626241e63b39552 [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
dan6700d022010-04-12 19:05:58 +000022/* Connection to a log file. There is one object of this type for each pager. */
23typedef struct Log Log;
24
25/* Open and close a connection to a log file. */
drhc438efd2010-04-26 00:19:45 +000026int sqlite3WalOpen(sqlite3_vfs*, const char *zDb, Log **ppLog);
27int sqlite3WalClose(Log *pLog, sqlite3_file *pFd, int sync_flags, u8 *zBuf);
dan6700d022010-04-12 19:05:58 +000028
danc5118782010-04-17 17:34:41 +000029/* Used by readers to open (lock) and close (unlock) a snapshot. */
drhc438efd2010-04-26 00:19:45 +000030int sqlite3WalOpenSnapshot(Log *pLog, int *);
31void sqlite3WalCloseSnapshot(Log *pLog);
dan6700d022010-04-12 19:05:58 +000032
33/* Read a page from the log, if it is present. */
drhc438efd2010-04-26 00:19:45 +000034int sqlite3WalRead(Log *pLog, Pgno pgno, int *pInLog, u8 *pOut);
35void sqlite3WalDbsize(Log *pLog, Pgno *pPgno);
dan6700d022010-04-12 19:05:58 +000036
37/* Obtain or release the WRITER lock. */
drhc438efd2010-04-26 00:19:45 +000038int sqlite3WalWriteLock(Log *pLog, int op);
dan6700d022010-04-12 19:05:58 +000039
dan74d6cd82010-04-24 18:44:05 +000040/* Undo any frames written (but not committed) to the log */
drhc438efd2010-04-26 00:19:45 +000041int sqlite3WalUndo(Log *pLog, int (*xUndo)(void *, Pgno), void *pUndoCtx);
dan74d6cd82010-04-24 18:44:05 +000042
dan3306c4a2010-04-23 19:15:00 +000043/* Return true if data has been written but not committed to the log file. */
drhc438efd2010-04-26 00:19:45 +000044int sqlite3WalDirty(Log *pLog);
dan3306c4a2010-04-23 19:15:00 +000045
danc5118782010-04-17 17:34:41 +000046/* Write a frame or frames to the log. */
drhc438efd2010-04-26 00:19:45 +000047int sqlite3WalFrames(Log *pLog, int, PgHdr *, Pgno, int, int);
dan6700d022010-04-12 19:05:58 +000048
49/* Copy pages from the log to the database file */
drhc438efd2010-04-26 00:19:45 +000050int sqlite3WalCheckpoint(
dan6700d022010-04-12 19:05:58 +000051 Log *pLog, /* Log connection */
52 sqlite3_file *pFd, /* File descriptor open on db file */
danc5118782010-04-17 17:34:41 +000053 int sync_flags, /* Flags to sync db file with (or 0) */
dan64d039e2010-04-13 19:27:31 +000054 u8 *zBuf, /* Temporary buffer to use */
55 int (*xBusyHandler)(void *), /* Pointer to busy-handler function */
56 void *pBusyHandlerArg /* Argument to pass to xBusyHandler */
dan6700d022010-04-12 19:05:58 +000057);
58
dan8d22a172010-04-19 18:03:51 +000059/* Return the value to pass to a log callback. Or 0 for no callback. */
drhc438efd2010-04-26 00:19:45 +000060int sqlite3WalCallback(Log *pLog);
dan8d22a172010-04-19 18:03:51 +000061
drhc438efd2010-04-26 00:19:45 +000062#endif /* _WAL_H_ */