PostgreSQL Locks中LOCK结构体是什么
发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,本篇内容主要讲解"PostgreSQL Locks中LOCK结构体是什么",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"PostgreSQL Locks中L
千家信息网最后更新 2025年01月20日PostgreSQL Locks中LOCK结构体是什么
本篇内容主要讲解"PostgreSQL Locks中LOCK结构体是什么",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"PostgreSQL Locks中LOCK结构体是什么"吧!
一、LOCK Struct
/* * The LOCKTAG struct is defined with malice aforethought to fit into 16 * bytes with no padding. Note that this would need adjustment if we were * to widen Oid, BlockNumber, or TransactionId to more than 32 bits. * * We include lockmethodid in the locktag so that a single hash table in * shared memory can store locks of different lockmethods. */typedef struct LOCKTAG{ uint32 locktag_field1; /* a 32-bit ID field */ uint32 locktag_field2; /* a 32-bit ID field */ uint32 locktag_field3; /* a 32-bit ID field */ uint16 locktag_field4; /* a 16-bit ID field */ uint8 locktag_type; /* see enum LockTagType */ uint8 locktag_lockmethodid; /* lockmethod indicator */} LOCKTAG;/* * Per-locked-object lock information: * * tag -- uniquely identifies the object being locked * grantMask -- bitmask for all lock types currently granted on this object. * waitMask -- bitmask for all lock types currently awaited on this object. * procLocks -- list of PROCLOCK objects for this lock. * waitProcs -- queue of processes waiting for this lock. * requested -- count of each lock type currently requested on the lock * (includes requests already granted!!). * nRequested -- total requested locks of all types. * granted -- count of each lock type currently granted on the lock. * nGranted -- total granted locks of all types. * * Note: these counts count 1 for each backend. Internally to a backend, * there may be multiple grabs on a particular lock, but this is not reflected * into shared memory. */typedef struct LOCK{ /* hash key */ LOCKTAG tag; /* unique identifier of lockable object */ /* data */ LOCKMASK grantMask; /* bitmask for lock types already granted */ LOCKMASK waitMask; /* bitmask for lock types awaited */ SHM_QUEUE procLocks; /* list of PROCLOCK objects assoc. with lock */ PROC_QUEUE waitProcs; /* list of PGPROC objects waiting on lock */ int requested[MAX_LOCKMODES]; /* counts of requested locks */ int nRequested; /* total of requested[] array */ int granted[MAX_LOCKMODES]; /* counts of granted locks */ int nGranted; /* total of granted[] array */} LOCK;#define LOCK_LOCKMETHOD(lock) ((LOCKMETHODID) (lock).tag.locktag_lockmethodid)---------------------------------------------------------------------------The lock manager's LOCK objects contain:LOCK结构体包括:tag - The key fields that are used for hashing locks in the shared memory lock hash table. The contents of the tag essentially define an individual lockable object. See include/storage/lock.h for details about the supported types of lockable objects. 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 LOCKTAG so that there are no padding bytes.)tag - 该键域用于标记共享内存lock哈希表中的hashing locks.标记tag的内容本质上定义了 一个独立的可锁定对象.关于已支持的可锁定对象类型的详细信息可参考include/storage/lock.h. 之所以定义为一个单独的结构是为了确保能够把归零正确的字节数. 编译器可能插入到结构体中的所有对齐字节数正确被归零是很很重要的,否则的话哈希的计算会是随机的. (当前来看,定义结构体LOCKTAG以避免对齐字节)grantMask - This bitmask indicates what types of locks are currently held on the given lockable object. It is used (against the lock table's conflict table) to determine if a new lock request will conflict with existing lock types held. Conflicts are determined by bitwise AND operations between the grantMask and the conflict table entry for the requested lock type. Bit i of grantMask is 1 if and only if granted[i] > 0.grantMask - 该bitmask表示在给定的可锁定对象上持有了哪些类型的locks. 该字段用于确定新申请的锁是否会与现存的锁存在冲突. 冲突通过grantMask和请求锁类型的冲突表条目的bitwise AND操作实现. 当且仅当granted[i] > 0,grantMask的第i位为1.waitMask - This bitmask shows the types of locks being waited for. Bit i of waitMask is 1 if and only if requested[i] > granted[i].waitMask - 该字段标记了正在等待的锁类型.当且仅当requested[i] > granted[i],waitMask中的第1位为1.procLocks - This is a shared memory queue of all the PROCLOCK structs associated with the lock object. Note that both granted and waiting PROCLOCKs are in this list (indeed, the same PROCLOCK might have some already-granted locks and be waiting for more!).procLocks - 与lock object相关的PROCLOCK结构体在共享内存中的队列. 注意链表中存在granted和waiting PROCLOCKs. (实际上,同一个PROCLOCK可能有已授予的locks但正在等待更多的锁) waitProcs - This is a shared memory queue of all PGPROC structures corresponding to backends that are waiting (sleeping) until another backend releases this lock. The process structure holds the information needed to determine if it should be woken up when the lock is released.waitProcs - 对应等待其他后台进程释放锁的后台进程的PGPROC结构体在共享内存中的队列. 进程结构体保存了用于确定在锁释放时是否需要唤醒的相关信息.nRequested - Keeps a count of how many times this lock has been attempted to be acquired. The count includes attempts by processes which were put to sleep due to conflicts. It also counts the same backend twice if, for example, a backend process first acquires a read and then acquires a write. (But multiple acquisitions of the same lock/lock mode within a backend are not multiply counted here; they are recorded only in the backend's LOCALLOCK structure.)nRequested - 该字段保存了尝试获取该锁的次数.计数包括因为冲突而处于休眠状态的次数. 如果一个进程第一次请求读然后请求写时可能会导致该进程被多次统计. requested - Keeps a count of how many locks of each type have been attempted. Only elements 1 through MAX_LOCKMODES-1 are used as they correspond to the lock type defined constants. Summing the values of requested[] should come out equal to nRequested.requested - 该字段保存了尝试获取多少种锁类型.只有1 -> MAX_LOCKMODES-1被使用,因为这对应了锁类型常量. 计算requested数组的和应等于nRequested. nGranted - Keeps count of how many times this lock has been successfully acquired. This count does not include attempts that are waiting due to conflicts. Otherwise the counting rules are the same as for nRequested.nGranted - 成功获取该锁的次数.该计数不包括因为冲突而等待的次数.因此该计数规则与nRequested一样.granted - Keeps count of how many locks of each type are currently held. Once again only elements 1 through MAX_LOCKMODES-1 are used (0 is not). Also, like requested[], summing the values of granted[] should total to the value of nGranted.granted - 保存每种类型有多少锁.1 -> MAX_LOCKMODES-1是有用的. 与requested类似,granted[]数组的和应等于nGranted.We should always have 0 <= nGranted <= nRequested, and0 <= granted[i] <= requested[i] for each i. When all the request countsgo to zero, the LOCK object is no longer needed and can be freed.nGranted的的范围为[0,nRequested],对于每一个granted[i]范围为[0,requested[i]].如果所有请求变为0,那么LOCK对象不再需要,会通过free释放.
到此,相信大家对"PostgreSQL Locks中LOCK结构体是什么"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
结构
类型
进程
冲突
字段
对象
次数
内存
内容
字节
标记
信息
后台
实际
数组
更多
正在
范围
队列
哈希
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
宽城租房软件开发
俄罗斯网络技术的发展
软件开发免税根据哪个文件
北邮网络安全学院研究生导师官网
360网络安全四大顶级期刊
网络安全工程师缺口大吗
稳定美国服务器
玩游戏服务器连接异常怎么办
云服务器清理缓存
春考计算机网络技术试题
网络技术对于国家的重要性
中职生网络安全试题
福建智能视频分析服务器虚拟主机
dell服务器出厂配置清单
数据库关系表视图
去柬埔寨 搞软件开发
泰兴自动网络技术市场
网络技术及应用复习题
软件开发是兴趣领域吗
延边画图软件开发
网络技术专业考一建
数据库字段属性有哪些
云顶之弈美测服是什么服务器
数据库集群方式怎么区分
哪个进程保证数据库与内存一致性
高级数据库工程师怎么考
rtx腾讯通数据库
沙县五中网络安全
内网服务器全局代理
网络安全专业靠谱吗