1N/A/*-
1N/A * See the file LICENSE for redistribution information.
1N/A *
1N/A * Copyright (c) 1996, 1997, 1998
1N/A * Sleepycat Software. All rights reserved.
1N/A *
1N/A * @(#)log.h 10.30 (Sleepycat) 10/11/98
1N/A */
1N/A
1N/A#ifndef _LOG_H_
1N/A#define _LOG_H_
1N/A
1N/Astruct __fname; typedef struct __fname FNAME;
1N/Astruct __hdr; typedef struct __hdr HDR;
1N/Astruct __log; typedef struct __log LOG;
1N/Astruct __log_persist; typedef struct __log_persist LOGP;
1N/A
1N/A#ifndef MAXLFNAME
1N/A#define LFPREFIX "log." /* Log file name prefix. */
1N/A#define LFNAME "log.%010d" /* Log file name template. */
1N/A#define LFNAME_V1 "log.%05d" /* Log file name template, rev 1. */
1N/A#define MAXLFNAME 2000000000 /* Maximum log file name. */
1N/A#endif
1N/A /* Default log name. */
1N/A#define DB_DEFAULT_LOG_FILE "__db_log.share"
1N/A
1N/A#define DEFAULT_MAX (10 * MEGABYTE) /* 10 Mb. */
1N/A
1N/A/* Macros to lock/unlock the region and threads. */
1N/A#define LOCK_LOGTHREAD(dblp) \
1N/A if (F_ISSET(dblp, DB_AM_THREAD)) \
1N/A (void)__db_mutex_lock((dblp)->mutexp, -1)
1N/A#define UNLOCK_LOGTHREAD(dblp) \
1N/A if (F_ISSET(dblp, DB_AM_THREAD)) \
1N/A (void)__db_mutex_unlock((dblp)->mutexp, -1);
1N/A#define LOCK_LOGREGION(dblp) \
1N/A (void)__db_mutex_lock(&((RLAYOUT *)(dblp)->lp)->lock, \
1N/A (dblp)->reginfo.fd)
1N/A#define UNLOCK_LOGREGION(dblp) \
1N/A (void)__db_mutex_unlock(&((RLAYOUT *)(dblp)->lp)->lock, \
1N/A (dblp)->reginfo.fd)
1N/A
1N/A/* Check for region catastrophic shutdown. */
1N/A#define LOG_PANIC_CHECK(dblp) { \
1N/A if ((dblp)->lp->rlayout.panic) \
1N/A return (DB_RUNRECOVERY); \
1N/A}
1N/A
1N/A/*
1N/A * The per-process table that maps log file-id's to DB structures.
1N/A */
1N/Atypedef struct __db_entry {
1N/A DB *dbp; /* Associated DB structure. */
1N/A char *name; /* File name. */
1N/A u_int32_t refcount; /* Reference counted. */
1N/A int deleted; /* File was not found during open. */
1N/A} DB_ENTRY;
1N/A
1N/A/*
1N/A * DB_LOG
1N/A * Per-process log structure.
1N/A */
1N/Astruct __db_log {
1N/A/* These fields need to be protected for multi-threaded support. */
1N/A db_mutex_t *mutexp; /* Mutex for thread protection. */
1N/A
1N/A DB_ENTRY *dbentry; /* Recovery file-id mapping. */
1N/A#define DB_GROW_SIZE 64
1N/A u_int32_t dbentry_cnt; /* Entries. Grows by DB_GROW_SIZE. */
1N/A
1N/A/*
1N/A * These fields are always accessed while the region lock is held, so they do
1N/A * not have to be protected by the thread lock as well OR, they are only used
1N/A * when threads are not being used, i.e. most cursor operations are disallowed
1N/A * on threaded logs.
1N/A */
1N/A u_int32_t lfname; /* Log file "name". */
1N/A int lfd; /* Log file descriptor. */
1N/A
1N/A DB_LSN c_lsn; /* Cursor: current LSN. */
1N/A DBT c_dbt; /* Cursor: return DBT structure. */
1N/A int c_fd; /* Cursor: file descriptor. */
1N/A u_int32_t c_off; /* Cursor: previous record offset. */
1N/A u_int32_t c_len; /* Cursor: current record length. */
1N/A
1N/A/* These fields are not protected. */
1N/A LOG *lp; /* Address of the shared LOG. */
1N/A
1N/A DB_ENV *dbenv; /* Reference to error information. */
1N/A REGINFO reginfo; /* Region information. */
1N/A
1N/A void *addr; /* Address of shalloc() region. */
1N/A
1N/A char *dir; /* Directory argument. */
1N/A
1N/A/*
1N/A * These fields are used by XA; since XA forbids threaded execution, these
1N/A * do not have to be protected.
1N/A */
1N/A void *xa_info; /* Committed transaction list that
1N/A * has to be carried between calls
1N/A * to xa_recover. */
1N/A DB_LSN xa_lsn; /* Position of an XA recovery scan. */
1N/A DB_LSN xa_first; /* LSN to which we need to roll back
1N/A for this XA recovery scan. */
1N/A
1N/A /*
1N/A * !!!
1N/A * Currently used to hold:
1N/A * DB_AM_THREAD (a DB flag)
1N/A * DBC_RECOVER (a DBC flag)
1N/A * If they are ever the same bits, we're in serious trouble.
1N/A */
1N/A#if DB_AM_THREAD == DBC_RECOVER
1N/A DB_AM_THREAD, DBC_RECOVER, FLAG MISMATCH
1N/A#endif
1N/A u_int32_t flags;
1N/A};
1N/A
1N/A/*
1N/A * HDR --
1N/A * Log record header.
1N/A */
1N/Astruct __hdr {
1N/A u_int32_t prev; /* Previous offset. */
1N/A u_int32_t cksum; /* Current checksum. */
1N/A u_int32_t len; /* Current length. */
1N/A};
1N/A
1N/Astruct __log_persist {
1N/A u_int32_t magic; /* DB_LOGMAGIC */
1N/A u_int32_t version; /* DB_LOGVERSION */
1N/A
1N/A u_int32_t lg_max; /* Maximum file size. */
1N/A int mode; /* Log file mode. */
1N/A};
1N/A
1N/A/*
1N/A * LOG --
1N/A * Shared log region. One of these is allocated in shared memory,
1N/A * and describes the log.
1N/A */
1N/Astruct __log {
1N/A RLAYOUT rlayout; /* General region information. */
1N/A
1N/A LOGP persist; /* Persistent information. */
1N/A
1N/A SH_TAILQ_HEAD(__fq) fq; /* List of file names. */
1N/A
1N/A /*
1N/A * The lsn LSN is the file offset that we're about to write and which
1N/A * we will return to the user.
1N/A */
1N/A DB_LSN lsn; /* LSN at current file offset. */
1N/A
1N/A /*
1N/A * The s_lsn LSN is the last LSN that we know is on disk, not just
1N/A * written, but synced.
1N/A */
1N/A DB_LSN s_lsn; /* LSN of the last sync. */
1N/A
1N/A u_int32_t len; /* Length of the last record. */
1N/A
1N/A u_int32_t w_off; /* Current write offset in the file. */
1N/A
1N/A DB_LSN chkpt_lsn; /* LSN of the last checkpoint. */
1N/A time_t chkpt; /* Time of the last checkpoint. */
1N/A
1N/A DB_LOG_STAT stat; /* Log statistics. */
1N/A
1N/A /*
1N/A * The f_lsn LSN is the LSN (returned to the user) that "owns" the
1N/A * first byte of the buffer. If the record associated with the LSN
1N/A * spans buffers, it may not reflect the physical file location of
1N/A * the first byte of the buffer.
1N/A */
1N/A DB_LSN f_lsn; /* LSN of first byte in the buffer. */
1N/A size_t b_off; /* Current offset in the buffer. */
1N/A u_int8_t buf[4 * 1024]; /* Log buffer. */
1N/A};
1N/A
1N/A/*
1N/A * FNAME --
1N/A * File name and id.
1N/A */
1N/Astruct __fname {
1N/A SH_TAILQ_ENTRY q; /* File name queue. */
1N/A
1N/A u_int16_t ref; /* Reference count. */
1N/A
1N/A u_int32_t id; /* Logging file id. */
1N/A DBTYPE s_type; /* Saved DB type. */
1N/A
1N/A size_t name_off; /* Name offset. */
1N/A u_int8_t ufid[DB_FILE_ID_LEN]; /* Unique file id. */
1N/A};
1N/A
1N/A/* File open/close register log record opcodes. */
1N/A#define LOG_CHECKPOINT 1 /* Checkpoint: file name/id dump. */
1N/A#define LOG_CLOSE 2 /* File close. */
1N/A#define LOG_OPEN 3 /* File open. */
1N/A
1N/A#include "log_auto.h"
1N/A#include "log_ext.h"
1N/A#endif /* _LOG_H_ */