Berkeley DB 源代码分析 (7) --- 事务和日志 (2)

这篇博客详细介绍了Berkeley DB的日志子系统,包括其架构、主要功能的实现,如日志缓冲区刷新、事务提交、恢复、归档和检查点操作。日志子系统由一个日志缓冲区和多个日志文件组成,记录了数据库事件的详细信息,用于事务恢复和持久性。日志记录包含LSN来标识位置和时间顺序,并通过LSN维护数据页与日志之间的连接。
摘要由CSDN通过智能技术生成
这篇和上篇一样,也是含有一些wiki格式控制字符,看的时候直接忽略这些格式字符。

= Logging subsystem =

== Architecture ==

Log subsystem consists of one log buffer, and several log files, each has a unique file number.  Log buffer and log files contains
log records.  Log records has a loghdr and a data part, hdr contains the admin info about this logrec, and the checksum of log
rec data part(loghdr not checksumed), logrec data part Log records contains full info about an event that just happened(so the
data they contain may vary a lot, some log recs are huge, some are tiny), other parts of the db need to explicitly construct the
required log record and log the event, in order to do recovery. Log recs are appended to the last log file one by one, each log
record has an LSN(log sequence number), when one log file is full (set_log_size, and a log record is not partly stored in multiple
log files), another is created, with incremented index. Logically all log files make up a huge log.

log sequence number consists of two parts---(fileno, infile-offset), both fields are increasing only. LSNs are used to
identify each log record and its exact position, to identify relative time in mvcc mpool algorithm, and to identify those objects
related to the events recorded in the corresponding log record, for example, when a page is created, this event is logged in a log
record with LSN "lsn", then the "lsn" is also written into that page's header, so that we can find out when(relative time) that
page is created, and more info, in the log record; and this lsn will be used to maintain connection between this page and the
logs, when later this page is modified or deleted, we use the "lsn" in its header to identify exactly which page those events
happened to. During normal run of db, log recs are only appended to log files, and they are read out only when we are doing a recovery.
At that time, log recs are accessed using a log cursor,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值