Locking Subsystem Learning Notes
0. locking API
__db_lput/__db_lget are txnal lock put/get, often __TLPUT is called instead,
and __TLPUT calls __db_lput internally. __db_lput will downgrade the lock
rathter than simply releasing it if the db supports dirty reads and the lock
is a write lock; in other circumstances it will release the lock.
__LPUT and __ENV_LPUT simply calls __lock_put, thus the lock is simply
released.
1. So far we only use intentional locks in cds mode. This is because we are not using row level locking in tds mode, we only lock pages in tds mode. (what about queue am?)
2. Need to provide row level locking API, like the existing __db_lget/__db_lput for page level locking. Because qam is using record locking now, it uses __db_lget with a DB_LOCK_RECORD flag to lock a record. However __db_lget can't be directly used because it's locking a db-wide recno, so (dbfileuid, recno) is sufficient to be the lock obj, but in the new am we don't have global recno, we will lock (dbfileuid, pgno, in-page-indx).
qam does not lock pages, it always lock (dbfileuid, recno), so it does not
need intentional locking either.
1. So far we only use intentional locks in cds mode. This is because we are not using row level locking in tds mode, we only lock pages in tds mode. (what about queue am?)
2. Need to provide row level locking API, like the existing __db_lget/__db_lput for page level locking. Because qam is using record locking now, it uses __db_lget with a DB_LOCK_RECORD flag to lock a record. However __db_lget can't be directly used because it's locking a db-wide recno, so (dbfileuid, recno) is sufficient to be the lock obj, but in the new am we don't have global recno, we will lock (dbfileuid, pgno, in-page-indx).
qam does not lock pages, it always lock (dbfileuid, recno), so it does not
need intentional locking either.
3. __db_ilock(DB_LOCK_ILOCK) is the lock object structure used inside DB to represent lock
info, all locks used by db internally are managed using this type e.g. the lock list.
We need to add a in-page-index to lock a row.
__db_lock is the struct in the lock region, used to store each lock's info
inside lock subsystem, to manage database locks;
DB_LOCK is used in a lock request used by outside caller to get/put a lock. it
contains offset pointer for us to find the corresponding internal __db_lock.
4.
the $db/lock/Design is obsolete.
Firstly, there are multiple lock table partitions, each of them has __db_lockpart structure,
containing partition specific info, and containing some of
the free lock objects and free locks. So getting a free lock object/lock can
be parallel in multiple partitions.
The main lock region has __db_lockregion structure, containing global info of the lock region; And it
contains the locker free list, lockers are not put into multiple partitions. It also contains the
locker/lock object hash tables, as expected. also it contains the lock table
partition array. Note that all the partitions live in the same region file as
the main lock region.
There are no direct bucket mutex for each bucket in lockobj hash table,
rather, we use lock partition'
Berkeley DB 源代码分析 (5) --- 事务锁模块
最新推荐文章于 2019-04-24 17:56:11 发布
这篇博客详细分析了Berkeley DB的事务锁模块,包括API如__db_lput和__db_lget的内部工作原理,以及锁的管理结构。讨论了在不同模式下如何实现行级和页级锁定,特别提到了qam使用记录锁定的情况。博客还介绍了锁对象结构、锁分区、并发控制和死锁检测等方面的内容,展示了如何提高并发性和避免死锁。
摘要由CSDN通过智能技术生成