|
1 | | -$Header: /cvsroot/pgsql/src/backend/storage/lmgr/README,v 1.4 2000/12/22 00:51:54 tgl Exp $ |
| 1 | +$Header: /cvsroot/pgsql/src/backend/storage/lmgr/README,v 1.5 2001/01/16 06:11:34 tgl Exp $ |
2 | 2 |
|
3 | 3 | There are two fundamental lock structures: the per-lockable-object LOCK |
4 | 4 | struct, and the per-lock-holder HOLDER struct. A LOCK object exists |
@@ -44,51 +44,52 @@ tag - |
44 | 44 | only a single table (see Gray's paper on 2 phase locking if |
45 | 45 | you are puzzled about how multi-level lock tables work). |
46 | 46 |
|
47 | | -mask - |
48 | | - Thisfield indicates what types of locks are currently held on the |
| 47 | +grantMask - |
| 48 | + Thisbitmask indicates what types of locks are currently held on the |
49 | 49 | given lockable object. It is used (against the lock table's conflict |
50 | | - table) to determine ifthe new lock request will conflict with existing |
| 50 | + table) to determine ifa new lock request will conflict with existing |
51 | 51 | lock types held. Conficts are determined by bitwise AND operations |
52 | | - between the mask and the conflict table entry for the given lock type |
53 | | - to be set. The current representation is that each bit (1 through 5) |
54 | | - is set when that lock type (WRITE, READ, WRITE INTENT, READ INTENT, EXTEND) |
55 | | - has been acquired for the lock. |
| 52 | + between the grantMask and the conflict table entry for the requested |
| 53 | + lock type. Bit i of grantMask is 1 if and only if granted[i] > 0. |
| 54 | + |
| 55 | +waitMask - |
| 56 | + This bitmask shows the types of locks being waited for. Bit i of waitMask |
| 57 | + is 1 if and only if requested[i] > granted[i]. |
56 | 58 |
|
57 | 59 | waitProcs - |
58 | 60 | This is a shared memory queue of all process structures corresponding to |
59 | 61 | a backend that is waiting (sleeping) until another backend releases this |
60 | 62 | lock. The process structure holds the information needed to determine |
61 | | - if it should be woken up when this lock is released. If, for example, |
62 | | - we are releasing a read lock and the process is sleeping trying to acquire |
63 | | - a read lock then there is no point in waking it since the lock being |
64 | | - released isn't what caused it to sleep in the first place. There will |
65 | | - be more on this below (when I get to releasing locks and waking sleeping |
66 | | - process routines). |
| 63 | + if it should be woken up when this lock is released. |
67 | 64 |
|
68 | | -nHolding - |
| 65 | +nRequested - |
69 | 66 | Keeps a count of how many times this lock has been attempted to be |
70 | 67 | acquired. The count includes attempts by processes which were put |
71 | 68 | to sleep due to conflicts. It also counts the same backend twice |
72 | 69 | if, for example, a backend process first acquires a read and then |
73 | | - acquires a write. |
| 70 | + acquires a write, or acquires a read lock twice. |
74 | 71 |
|
75 | | -holders - |
| 72 | +requested - |
76 | 73 | Keeps a count of how many locks of each type have been attempted. Only |
77 | | - elements 1 throughMAX_LOCK_TYPES are used as they correspond to the lock |
78 | | - type defined constants (WRITE through EXTEND). Summing the values of |
79 | | -holders should come outequal tonHolding. |
| 74 | + elements 1 throughMAX_LOCKMODES-1 are used as they correspond to the lock |
| 75 | + type defined constants. Summing the values of requested[] should come out |
| 76 | + equal tonRequested. |
80 | 77 |
|
81 | | -nActive - |
82 | | - Keepsacount of how many times this lock has beensuccesfully acquired. |
| 78 | +nGranted - |
| 79 | + Keeps count of how many times this lock has beensuccessfully acquired. |
83 | 80 | This count does not include attempts that are waiting due to conflicts, |
84 | 81 | but can count the same backend twice (e.g. a read then a write -- since |
85 | | - its the same transaction this won't cause a conflict) |
| 82 | + its the same transaction this won't cause a conflict). |
| 83 | + |
| 84 | +granted - |
| 85 | + Keeps count of how many locks of each type are currently held. Once again |
| 86 | + only elements 1 through MAX_LOCKMODES-1 are used (0 is not). Also, like |
| 87 | + requested, summing the values of granted should total to the value |
| 88 | + of nGranted. |
86 | 89 |
|
87 | | -activeHolders - |
88 | | - Keeps a count of how locks of each type are currently held. Once again |
89 | | - only elements 1 through MAX_LOCK_TYPES are used (0 is not). Also, like |
90 | | - holders, summing the values of activeHolders should total to the value |
91 | | - of nActive. |
| 90 | +We should always have 0 <= nGranted <= nRequested, and |
| 91 | +0 <= granted[i] <= requested[i] for each i. If the request counts go to |
| 92 | +zero, the lock object is no longer needed and can be freed. |
92 | 93 |
|
93 | 94 | --------------------------------------------------------------------------- |
94 | 95 |
|
@@ -116,14 +117,12 @@ tag - |
116 | 117 | are always session locks, and we also use session locks for multi- |
117 | 118 | transaction operations like VACUUM. |
118 | 119 |
|
119 | | -holders - |
| 120 | +holding - |
120 | 121 | The number of successfully acquired locks of each type for this holder. |
121 | | - (CAUTION: the semantics are not the same as the LOCK's holder[], which |
122 | | - counts both acquired and pending requests. Probably a different name |
123 | | - should be used...) |
| 122 | + This should be <= the corresponding granted[] value of the lock object! |
124 | 123 |
|
125 | 124 | nHolding - |
126 | | - Sum of theholders[] array. |
| 125 | + Sum of theholding[] array. |
127 | 126 |
|
128 | 127 | queue - |
129 | 128 | List link for shared memory queue of all the HOLDER objects for the |
|