1*0Sstevel@tonic-gate /*- 2*0Sstevel@tonic-gate * See the file LICENSE for redistribution information. 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * Copyright (c) 1996, 1997, 1998 5*0Sstevel@tonic-gate * Sleepycat Software. All rights reserved. 6*0Sstevel@tonic-gate * 7*0Sstevel@tonic-gate * @(#)log.h 10.30 (Sleepycat) 10/11/98 8*0Sstevel@tonic-gate */ 9*0Sstevel@tonic-gate 10*0Sstevel@tonic-gate #ifndef _LOG_H_ 11*0Sstevel@tonic-gate #define _LOG_H_ 12*0Sstevel@tonic-gate 13*0Sstevel@tonic-gate struct __fname; typedef struct __fname FNAME; 14*0Sstevel@tonic-gate struct __hdr; typedef struct __hdr HDR; 15*0Sstevel@tonic-gate struct __log; typedef struct __log LOG; 16*0Sstevel@tonic-gate struct __log_persist; typedef struct __log_persist LOGP; 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate #ifndef MAXLFNAME 19*0Sstevel@tonic-gate #define LFPREFIX "log." /* Log file name prefix. */ 20*0Sstevel@tonic-gate #define LFNAME "log.%010d" /* Log file name template. */ 21*0Sstevel@tonic-gate #define LFNAME_V1 "log.%05d" /* Log file name template, rev 1. */ 22*0Sstevel@tonic-gate #define MAXLFNAME 2000000000 /* Maximum log file name. */ 23*0Sstevel@tonic-gate #endif 24*0Sstevel@tonic-gate /* Default log name. */ 25*0Sstevel@tonic-gate #define DB_DEFAULT_LOG_FILE "__db_log.share" 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #define DEFAULT_MAX (10 * MEGABYTE) /* 10 Mb. */ 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* Macros to lock/unlock the region and threads. */ 30*0Sstevel@tonic-gate #define LOCK_LOGTHREAD(dblp) \ 31*0Sstevel@tonic-gate if (F_ISSET(dblp, DB_AM_THREAD)) \ 32*0Sstevel@tonic-gate (void)__db_mutex_lock((dblp)->mutexp, -1) 33*0Sstevel@tonic-gate #define UNLOCK_LOGTHREAD(dblp) \ 34*0Sstevel@tonic-gate if (F_ISSET(dblp, DB_AM_THREAD)) \ 35*0Sstevel@tonic-gate (void)__db_mutex_unlock((dblp)->mutexp, -1); 36*0Sstevel@tonic-gate #define LOCK_LOGREGION(dblp) \ 37*0Sstevel@tonic-gate (void)__db_mutex_lock(&((RLAYOUT *)(dblp)->lp)->lock, \ 38*0Sstevel@tonic-gate (dblp)->reginfo.fd) 39*0Sstevel@tonic-gate #define UNLOCK_LOGREGION(dblp) \ 40*0Sstevel@tonic-gate (void)__db_mutex_unlock(&((RLAYOUT *)(dblp)->lp)->lock, \ 41*0Sstevel@tonic-gate (dblp)->reginfo.fd) 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate /* Check for region catastrophic shutdown. */ 44*0Sstevel@tonic-gate #define LOG_PANIC_CHECK(dblp) { \ 45*0Sstevel@tonic-gate if ((dblp)->lp->rlayout.panic) \ 46*0Sstevel@tonic-gate return (DB_RUNRECOVERY); \ 47*0Sstevel@tonic-gate } 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate /* 50*0Sstevel@tonic-gate * The per-process table that maps log file-id's to DB structures. 51*0Sstevel@tonic-gate */ 52*0Sstevel@tonic-gate typedef struct __db_entry { 53*0Sstevel@tonic-gate DB *dbp; /* Associated DB structure. */ 54*0Sstevel@tonic-gate char *name; /* File name. */ 55*0Sstevel@tonic-gate u_int32_t refcount; /* Reference counted. */ 56*0Sstevel@tonic-gate int deleted; /* File was not found during open. */ 57*0Sstevel@tonic-gate } DB_ENTRY; 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate /* 60*0Sstevel@tonic-gate * DB_LOG 61*0Sstevel@tonic-gate * Per-process log structure. 62*0Sstevel@tonic-gate */ 63*0Sstevel@tonic-gate struct __db_log { 64*0Sstevel@tonic-gate /* These fields need to be protected for multi-threaded support. */ 65*0Sstevel@tonic-gate db_mutex_t *mutexp; /* Mutex for thread protection. */ 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate DB_ENTRY *dbentry; /* Recovery file-id mapping. */ 68*0Sstevel@tonic-gate #define DB_GROW_SIZE 64 69*0Sstevel@tonic-gate u_int32_t dbentry_cnt; /* Entries. Grows by DB_GROW_SIZE. */ 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate /* 72*0Sstevel@tonic-gate * These fields are always accessed while the region lock is held, so they do 73*0Sstevel@tonic-gate * not have to be protected by the thread lock as well OR, they are only used 74*0Sstevel@tonic-gate * when threads are not being used, i.e. most cursor operations are disallowed 75*0Sstevel@tonic-gate * on threaded logs. 76*0Sstevel@tonic-gate */ 77*0Sstevel@tonic-gate u_int32_t lfname; /* Log file "name". */ 78*0Sstevel@tonic-gate int lfd; /* Log file descriptor. */ 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate DB_LSN c_lsn; /* Cursor: current LSN. */ 81*0Sstevel@tonic-gate DBT c_dbt; /* Cursor: return DBT structure. */ 82*0Sstevel@tonic-gate int c_fd; /* Cursor: file descriptor. */ 83*0Sstevel@tonic-gate u_int32_t c_off; /* Cursor: previous record offset. */ 84*0Sstevel@tonic-gate u_int32_t c_len; /* Cursor: current record length. */ 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate /* These fields are not protected. */ 87*0Sstevel@tonic-gate LOG *lp; /* Address of the shared LOG. */ 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate DB_ENV *dbenv; /* Reference to error information. */ 90*0Sstevel@tonic-gate REGINFO reginfo; /* Region information. */ 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate void *addr; /* Address of shalloc() region. */ 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate char *dir; /* Directory argument. */ 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate /* 97*0Sstevel@tonic-gate * These fields are used by XA; since XA forbids threaded execution, these 98*0Sstevel@tonic-gate * do not have to be protected. 99*0Sstevel@tonic-gate */ 100*0Sstevel@tonic-gate void *xa_info; /* Committed transaction list that 101*0Sstevel@tonic-gate * has to be carried between calls 102*0Sstevel@tonic-gate * to xa_recover. */ 103*0Sstevel@tonic-gate DB_LSN xa_lsn; /* Position of an XA recovery scan. */ 104*0Sstevel@tonic-gate DB_LSN xa_first; /* LSN to which we need to roll back 105*0Sstevel@tonic-gate for this XA recovery scan. */ 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate /* 108*0Sstevel@tonic-gate * !!! 109*0Sstevel@tonic-gate * Currently used to hold: 110*0Sstevel@tonic-gate * DB_AM_THREAD (a DB flag) 111*0Sstevel@tonic-gate * DBC_RECOVER (a DBC flag) 112*0Sstevel@tonic-gate * If they are ever the same bits, we're in serious trouble. 113*0Sstevel@tonic-gate */ 114*0Sstevel@tonic-gate #if DB_AM_THREAD == DBC_RECOVER 115*0Sstevel@tonic-gate DB_AM_THREAD, DBC_RECOVER, FLAG MISMATCH 116*0Sstevel@tonic-gate #endif 117*0Sstevel@tonic-gate u_int32_t flags; 118*0Sstevel@tonic-gate }; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate /* 121*0Sstevel@tonic-gate * HDR -- 122*0Sstevel@tonic-gate * Log record header. 123*0Sstevel@tonic-gate */ 124*0Sstevel@tonic-gate struct __hdr { 125*0Sstevel@tonic-gate u_int32_t prev; /* Previous offset. */ 126*0Sstevel@tonic-gate u_int32_t cksum; /* Current checksum. */ 127*0Sstevel@tonic-gate u_int32_t len; /* Current length. */ 128*0Sstevel@tonic-gate }; 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate struct __log_persist { 131*0Sstevel@tonic-gate u_int32_t magic; /* DB_LOGMAGIC */ 132*0Sstevel@tonic-gate u_int32_t version; /* DB_LOGVERSION */ 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate u_int32_t lg_max; /* Maximum file size. */ 135*0Sstevel@tonic-gate int mode; /* Log file mode. */ 136*0Sstevel@tonic-gate }; 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate /* 139*0Sstevel@tonic-gate * LOG -- 140*0Sstevel@tonic-gate * Shared log region. One of these is allocated in shared memory, 141*0Sstevel@tonic-gate * and describes the log. 142*0Sstevel@tonic-gate */ 143*0Sstevel@tonic-gate struct __log { 144*0Sstevel@tonic-gate RLAYOUT rlayout; /* General region information. */ 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate LOGP persist; /* Persistent information. */ 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate SH_TAILQ_HEAD(__fq) fq; /* List of file names. */ 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate /* 151*0Sstevel@tonic-gate * The lsn LSN is the file offset that we're about to write and which 152*0Sstevel@tonic-gate * we will return to the user. 153*0Sstevel@tonic-gate */ 154*0Sstevel@tonic-gate DB_LSN lsn; /* LSN at current file offset. */ 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate /* 157*0Sstevel@tonic-gate * The s_lsn LSN is the last LSN that we know is on disk, not just 158*0Sstevel@tonic-gate * written, but synced. 159*0Sstevel@tonic-gate */ 160*0Sstevel@tonic-gate DB_LSN s_lsn; /* LSN of the last sync. */ 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate u_int32_t len; /* Length of the last record. */ 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate u_int32_t w_off; /* Current write offset in the file. */ 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate DB_LSN chkpt_lsn; /* LSN of the last checkpoint. */ 167*0Sstevel@tonic-gate time_t chkpt; /* Time of the last checkpoint. */ 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate DB_LOG_STAT stat; /* Log statistics. */ 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate /* 172*0Sstevel@tonic-gate * The f_lsn LSN is the LSN (returned to the user) that "owns" the 173*0Sstevel@tonic-gate * first byte of the buffer. If the record associated with the LSN 174*0Sstevel@tonic-gate * spans buffers, it may not reflect the physical file location of 175*0Sstevel@tonic-gate * the first byte of the buffer. 176*0Sstevel@tonic-gate */ 177*0Sstevel@tonic-gate DB_LSN f_lsn; /* LSN of first byte in the buffer. */ 178*0Sstevel@tonic-gate size_t b_off; /* Current offset in the buffer. */ 179*0Sstevel@tonic-gate u_int8_t buf[4 * 1024]; /* Log buffer. */ 180*0Sstevel@tonic-gate }; 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate /* 183*0Sstevel@tonic-gate * FNAME -- 184*0Sstevel@tonic-gate * File name and id. 185*0Sstevel@tonic-gate */ 186*0Sstevel@tonic-gate struct __fname { 187*0Sstevel@tonic-gate SH_TAILQ_ENTRY q; /* File name queue. */ 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate u_int16_t ref; /* Reference count. */ 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate u_int32_t id; /* Logging file id. */ 192*0Sstevel@tonic-gate DBTYPE s_type; /* Saved DB type. */ 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate size_t name_off; /* Name offset. */ 195*0Sstevel@tonic-gate u_int8_t ufid[DB_FILE_ID_LEN]; /* Unique file id. */ 196*0Sstevel@tonic-gate }; 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate /* File open/close register log record opcodes. */ 199*0Sstevel@tonic-gate #define LOG_CHECKPOINT 1 /* Checkpoint: file name/id dump. */ 200*0Sstevel@tonic-gate #define LOG_CLOSE 2 /* File close. */ 201*0Sstevel@tonic-gate #define LOG_OPEN 3 /* File open. */ 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate #include "log_auto.h" 204*0Sstevel@tonic-gate #include "log_ext.h" 205*0Sstevel@tonic-gate #endif /* _LOG_H_ */ 206