2022年Log相关的数据结构 .pdf
《2022年Log相关的数据结构 .pdf》由会员分享,可在线阅读,更多相关《2022年Log相关的数据结构 .pdf(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、一、 Log 相关的数据结构:Db.h /* * Logging. */ #define DB_LOGVERSION 8 /* Current log version. */ #define DB_LOGOLDVER 8 /* Oldest log version supported. */ #define DB_LOGMAGIC 0 x040988 DB_ENV-log_archive() 方法的参数#define DB_ARCH_ABS 0 x001 /* Absolute pathnames. */ #define DB_ARCH_DA TA 0 x002 /* Data files.
2、*/ #define DB_ARCH_LOG 0 x004 /* Log files. */ #define DB_ARCH_REMOVE 0 x008 /* Remove log files. */ DB_ENV-log_put() 方法的参数#define DB_FLUSH 0 x001 /* Flush data to disk (public). */ #define DB_LOG_CHKPNT 0 x002 /* Flush supports a checkpoint */ #define DB_LOG_COMMIT 0 x004 /* Flush supports a commit
3、 */ #define DB_LOG_NOCOPY 0 x008 /* Dont copy data */ #define DB_LOG_NOT_DURABLE 0 x010 /* Do not log; keep in memory */ #define DB_LOG_PERM 0 x020 /* Flag record with REP_PERMANENT */ #define DB_LOG_WRNOSYNC 0 x040 /* Write, dont sync log_put */ DB_LSN 结构日志序号struct _db_lsn u_int32_t file; /* File I
4、D. */ u_int32_t offset; /* File offset. */ ; 日志记录类型#define DB_user_BEGIN 10000 /定义应用程序专用的日志记录类型,它的值不能等于或超过DB_debug_FLAG 的值#define DB_debug_FLAG 0 x80000000 /指定一条日志记录的类型。如果设置这个值, 那么日志记录只是为了调试的目的而记录的。日志游标struct _db_log_cursor DB_ENV *dbenv; /* Enclosing dbenv. */ DB_FH *c_fhp; /* File handle. */ DB_LS
5、N c_lsn; /* Cursor: LSN */ u_int32_t c_len; /* Cursor: record length */ u_int32_t c_prev; /* Cursor: previous records offset */ DBT c_dbt; /* Return DBT. */ 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 21 页 - - - - - - - - - #define DB_LOGC_BUF_SIZE (32 * 102
6、4) u_int8_t *bp; /* Allocated read buffer. */ u_int32_t bp_size; /* Read buffer length in bytes. */ u_int32_t bp_rlen; /* Read buffer valid data length. */ DB_LSN bp_lsn; /* Read buffer first byte LSN. */ u_int32_t bp_maxrec; /* Max record length in the log file. */ /* Methods. */ int (*close) _P(DB
7、_LOGC *, u_int32_t); int (*get) _P(DB_LOGC *, DB_LSN *, DBT *, u_int32_t); #define DB_LOG_DISK 0 x01 /* Log record came from disk. */ #define DB_LOG_LOCKED 0 x02 /* Log region already locked */ #define DB_LOG_SILENT_ERR 0 x04 /* Turn-off error messages. */ u_int32_t flags; ; 日志统计信息的结构struct _db_log_
8、stat u_int32_t st_magic; /* Log file magic number. */ u_int32_t st_version; /* Log file version number. */ int st_mode; /* Log file mode. */ u_int32_t st_lg_bsize; /* Log buffer size. */ u_int32_t st_lg_size; /* Log file size. */ u_int32_t st_w_bytes; /* Bytes to log. */ u_int32_t st_w_mbytes; /* Me
9、gabytes to log. */ u_int32_t st_wc_bytes; /* Bytes to log since checkpoint. */ u_int32_t st_wc_mbytes; /* Megabytes to log since checkpoint. */ u_int32_t st_wcount; /* Total writes to the log. */ u_int32_t st_wcount_fill; /* Overflow writes to the log. */ u_int32_t st_scount; /* Total syncs to the l
10、og. */ u_int32_t st_region_wait; /* Region lock granted after wait. */ u_int32_t st_region_nowait; /* Region lock granted without wait. */ u_int32_t st_cur_file; /* Current log file number. */ u_int32_t st_cur_offset; /* Current log file offset. */ u_int32_t st_disk_file; /* Known on disk log file n
11、umber. */ u_int32_t st_disk_offset; /* Known on disk log file offset. */ u_int32_t st_regsize; /* Region size. */ u_int32_t st_maxcommitperflush; /* Max number of commits in a flush. */ u_int32_t st_mincommitperflush; /* Min number of commits in a flush. */ ; Log.h 名师资料总结 - - -精品资料欢迎下载 - - - - - - -
12、 - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 21 页 - - - - - - - - - 映射日志文件为DB 结构的预处理表typedef struct _db_entry DB *dbp; /* Open dbp for this file id. */ int deleted; /* File was not found during open. */ DB_ENTRY; 文件名和文件id struct _fname SH_TAILQ_ENTRY q; /* File name queue. */ int32_t id; /* L
13、ogging file id. */ DBTYPE s_type; /* Saved DB type. */ roff_t name_off; /* Name offset. */ db_pgno_t meta_pgno; /* Page number of the meta page. */ u_int8_t ufidDB_FILE_ID_LEN; /* Unique file id. */ u_int32_t create_txnid; /* * Txn ID of the DB create, stored so * we can log it at register time. */
14、int is_durable; /* Is this file durable or not. */ ; 日志文件操作类型#define DBREG_CHKPNT 1 /* Checkpoint: file name/id dump. */ #define DBREG_CLOSE 2 /* File close. */ #define DBREG_OPEN 3 /* File open. */ #define DBREG_RCLOSE 4 /* File close after recovery. */ 日志子系统信息struct _db_log; typedef struct _db_log
15、 DB_LOG; struct _hdr; typedef struct _hdr HDR; struct _log; typedef struct _log LOG; struct _log_persist; typedef struct _log_persist LOGP; #define LFPREFIX log. /* Log file name prefix. */ #define LFNAME log.%010d /* Log file name template. */ #define LFNAME_V1 log.%05d /* Log file name template, r
16、ev 1. */ #define LG_MAX_DEFAULT (10 * MEGABYTE) /* 10 MB. */ /日志文件大小的缺省值#define LG_BSIZE_DEFAULT (32 * 1024) /* 32 KB. */ /日志缓冲大小的缺省值#define LG_BASE_REGION_SIZE (60 * 1024) /* 60 KB. */ /日志区大小的缺省值名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 21 页 - - - - - - -
17、 - - DB_LOG 结构struct _db_log /* * These fields need to be protected for multi-threaded support. */ DB_MUTEX *mutexp; /* Mutex for thread protection. */ DB_ENTRY *dbentry; /* Recovery file-id mapping. */ #define DB_GROW_SIZE 64 int32_t dbentry_cnt; /* Entries. Grows by DB_GROW_SIZE. */ /* * These fie
18、lds are always accessed while the region lock is held, so they do * not have to be protected by the thread lock as well. */ u_int32_t lfname; /* Log file name. */ DB_FH *lfhp; /* Log file handle. */ u_int8_t *bufp; /* Region buffer. */ /* These fields are not protected. */ DB_ENV *dbenv; /* Referenc
19、e to error information. */ REGINFO reginfo; /* Region information. */ #define DBLOG_RECOVER 0 x01 /* We are in recovery. */ #define DBLOG_FORCE_OPEN 0 x02 /* Force the DB open even if it appears to be deleted. */ u_int32_t flags; ; 日志记录头struct _hdr u_int32_t prev; /* Previous offset. */ u_int32_t le
20、n; /* Current length. */ u_int8_t chksumDB_MAC_KEY; /* Current checksum. */ u_int8_t ivDB_IV_BYTES; /* IV */ u_int32_t orig_size; /* Original size of log record */ /* ! - size is not written to log, must be last in hdr */ size_t size; /* Size of header to use */ ; 日志记录头包含了前一个记录的lsn 和这个记录的lsn。前者用于反向扫
21、描日志。这样,当前一个记录很大或在前一个文件中时,反向扫描可直接转到它的记录头而不必检查每个中间的页或字节。 由于根据记录的长度。记录头的大小和数据页的使用情况,可以算出下一个记录的 lsn,因此不需要在日志表中保存下一个记录的lsn。在 undo 事务中,需要找到某个事务的前一个日志记录,为了不进行反向扫描日志就可以找到这个记录,在日志管理器中保存名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 21 页 - - - - - - - - - 了该事务的前一个日志记录的ls
22、n。#define HDR_NORMAL_SZ 12 /运行在正常模式下,日志记录头的大小#define HDR_CRYPTO_SZ 12 + DB_MAC_KEY + DB_IV_BYTES /运行在加密模式下,日志记录头的大小(再加上4 个字节的校验和、iv 大小LOGP 结构struct _log_persist u_int32_t magic; /* DB_LOGMAGIC */ u_int32_t version; /* DB_LOGVERSION */ u_int32_t log_size; /* Log file size. */ u_int32_t mode; /* Log f
23、ile mode. */ ; 共享日志区Log 结构其中之一分配再共享内存中,用于描述日志struct _log DB_MUTEX fq_mutex; /* Mutex guarding file name list. */ LOGP persist; /* Persistent information. */ SH_TAILQ_HEAD(_fq1) fq; /* List of file names. */ int32_t fid_max; /* Max fid allocated. */ roff_t free_fid_stack; /* Stack of free file ids. *
24、/ int free_fids; /* Height of free fid stack. */ int free_fids_alloced; /* Number of free fid slots alloced. */ DB_LSN lsn; /* LSN at current file offset. */ / lsn 是将要写的日志文件偏移量,它将返回给用户DB_LSN f_lsn; /* LSN of first byte in the buffer. */ / f_lsn 是缓冲中第一个字节所在的lsn,它将返回给用户,它可能反映的不是缓冲中第一个字节的物理文件位置。size_t
25、b_off; /* Current offset in the buffer. */ u_int32_t w_off; /* Current write offset in the file. */ u_int32_t len; /* Length of the last record. */ int in_flush; /* Log flush in progress. */ roff_t flush_mutex_off; /* Mutex guarding flushing. */ DB_LSN s_lsn; /* LSN of the last sync. */ /s_lsn 是磁盘上最
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Log相关的数据结构 2022 Log 相关 数据结构
限制150内