PostgreSQL 源码解读(221)- Locks(PROCLOCK Struct)
发表于:2025-11-06 作者:千家信息网编辑
千家信息网最后更新 2025年11月06日,本节是PostgreSQL Locks中介绍PROCLOCK结构体部分,翻译自README文件.一、PROCLOCK Struct/* * We may have several different
千家信息网最后更新 2025年11月06日PostgreSQL 源码解读(221)- Locks(PROCLOCK Struct)
本节是PostgreSQL Locks中介绍PROCLOCK结构体部分,翻译自README文件.
一、PROCLOCK Struct
/* * We may have several different backends holding or awaiting locks * on the same lockable object. We need to store some per-holder/waiter * information for each such holder (or would-be holder). This is kept in * a PROCLOCK struct. * * PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the * proclock hashtable. A PROCLOCKTAG value uniquely identifies the combination * of a lockable object and a holder/waiter for that object. (We can use * pointers here because the PROCLOCKTAG need only be unique for the lifespan * of the PROCLOCK, and it will never outlive the lock or the proc.) * * Internally to a backend, it is possible for the same lock to be held * for different purposes: the backend tracks transaction locks separately * from session locks. However, this is not reflected in the shared-memory * state: we only track which backend(s) hold the lock. This is OK since a * backend can never block itself. * * The holdMask field shows the already-granted locks represented by this * proclock. Note that there will be a proclock object, possibly with * zero holdMask, for any lock that the process is currently waiting on. * Otherwise, proclock objects whose holdMasks are zero are recycled * as soon as convenient. * * releaseMask is workspace for LockReleaseAll(): it shows the locks due * to be released during the current call. This must only be examined or * set by the backend owning the PROCLOCK. * * Each PROCLOCK object is linked into lists for both the associated LOCK * object and the owning PGPROC object. Note that the PROCLOCK is entered * into these lists as soon as it is created, even if no lock has yet been * granted. A PGPROC that is waiting for a lock to be granted will also be * linked into the lock's waitProcs queue. */typedef struct PROCLOCKTAG{ /* NB: we assume this struct contains no padding! */ LOCK *myLock; /* link to per-lockable-object information */ PGPROC *myProc; /* link to PGPROC of owning backend */} PROCLOCKTAG;typedef struct PROCLOCK{ /* tag */ PROCLOCKTAG tag; /* unique identifier of proclock object */ /* data */ PGPROC *groupLeader; /* proc's lock group leader, or proc itself */ LOCKMASK holdMask; /* bitmask for lock types currently held */ LOCKMASK releaseMask; /* bitmask for lock types to be released */ SHM_QUEUE lockLink; /* list link in LOCK's list of proclocks */ SHM_QUEUE procLink; /* list link in PGPROC's list of proclocks */} PROCLOCK;#define PROCLOCK_LOCKMETHOD(proclock) \ LOCK_LOCKMETHOD(*((proclock).tag.myLock))---------------------------------------------------------------------------The lock manager's PROCLOCK objects contain:tag - The key fields that are used for hashing entries in the shared memory PROCLOCK hash table. This is declared as a separate struct to ensure that we always zero out the correct number of bytes. It is critical that any alignment-padding bytes the compiler might insert in the struct be zeroed out, else the hash computation will be random. (Currently, we are careful to define struct PROCLOCKTAG so that there are no padding bytes.) tag.myLock Pointer to the shared LOCK object this PROCLOCK is for. tag.myProc Pointer to the PGPROC of backend process that owns this PROCLOCK. Note: it's OK to use pointers here because a PROCLOCK never outlives either its lock or its proc. The tag is therefore unique for as long as it needs to be, even though the same tag values might mean something else at other times.tag - 与LOCK结构体中的tag字段类似,用于标识共享内存中的PROCLOCK哈希表中对应的条目. tag.mylock 指向PROCLOCK所表示的共享LOCK对象的指针 tag.myProc 指向持有该PROCLOCK的PGPROC后台进程holdMask - A bitmask for the lock modes successfully acquired by this PROCLOCK. This should be a subset of the LOCK object's grantMask, and also a subset of the PGPROC object's heldLocks mask (if the PGPROC is currently waiting for another lock mode on this lock).holdMask - 该PROCLOCK请求获得的lock模式位掩码. 应为LOCK's grantMask掩码的子集,同时也是PGPROC's heldlocks掩码的子集.releaseMask - A bitmask for the lock modes due to be released during LockReleaseAll. This must be a subset of the holdMask. Note that it is modified without taking the partition LWLock, and therefore it is unsafe for any backend except the one owning the PROCLOCK to examine/change it.releaseMask - 在LockReleaseAll执行过程中即将被释放的lock模式位掩码. 应为holdMask位掩码的子集.注意更新该值时不需要持有分区LWLock,因此除了自身的PROCLOCK外 其他后台进程是不安全的.lockLink - List link for shared memory queue of all the PROCLOCK objects for the same LOCK.lockLink - 共享内存中同一个LOCK的PROCLOCK对象队列链表链接.procLink - List link for shared memory queue of all the PROCLOCK objects for the same backend.procLink - 共享内存中同一个后台进程所有PROCLOCK对象的的链表链接.二、参考资料
README
内存
后台
子集
对象
进程
指向
模式
结构
表链
安全
参考资料
同时
字段
指针
文件
条目
标识
资料
过程
部分
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
电脑网络安全产品
策略组开启数据库在哪里
九赋开票软件服务器连接错误
网络技术基础虚仿实验
软测和网络安全哪个更好
数据库逆匹配
软件网络安全研究报告
广东工业大学网络安全实验报告
win7怎么制作服务器
萤火虫互联网科技
电视台网络安全培训
嘉兴智合软件开发公司
拉卡拉云网络技术有限公司
关于重视网络安全的通知
中关村下载软件开发
苹果服务器无法访问icloud
微软数据库技术支持
网络安全技术黑镜
云服务器技术租赁费用
小冰冰传奇九游数据库
连云港采购管理软件开发平台
不带公式复制数据库
嘉兴云网络技术口碑推荐
服务器一直在关机状态
he健康大使软件开发
网络安全教育征文结尾
荔浦软件开发
提取cad数据库
时代网络安全技术研究院
中国网络安全检测技术公司