久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

PostgreSQL Locks中LOCK結構體是什么

149次閱讀
沒有評論

共計 6562 個字符,預計需要花費 17 分鐘才能閱讀完成。

本篇內容主要講解“PostgreSQL Locks 中 LOCK 結構體是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓丸趣 TV 小編來帶大家學習“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, and
0  = granted[i]  = requested[i] for each i. When all the request counts
go 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 結構體是什么”有了更深的了解,不妨來實際操作一番吧!這里是丸趣 TV 網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-26發表,共計6562字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 洛扎县| 云安县| 曲松县| 迁西县| 安图县| 壤塘县| 宝清县| 民乐县| 吉木乃县| 青川县| 杂多县| 九龙县| 侯马市| 温泉县| 虞城县| 盱眙县| 筠连县| 双流县| 湖北省| 苍梧县| 筠连县| 尉犁县| 修水县| 龙州县| 荔波县| 金塔县| 台州市| 新丰县| 隆尧县| 台东市| 阿勒泰市| 旬邑县| 望江县| 重庆市| 溧阳市| 芜湖市| 唐海县| 秦皇岛市| 堆龙德庆县| 芜湖市| 汶上县|