238:(locking one entity, then locking one or more additional entities) is used. To illustrate, if two bank customers asked two clerks to obtain their account information so they could transfer some money into other accounts, the two accounts would essentially be locked. Then, if the customers told their clerks that the money was to be transferred into each other's accounts, the clerks would search for the other accounts but find them to be "in use" and wait for them to be returned. Unknowingly, the two clerks are waiting for each other, and neither of them can complete their transaction until the other gives up and returns the account. Various techniques are used to avoid such problems.
25:
143:. Clerk 1 applies and saves a transaction. Clerk 2 applies a different transaction to his saved copy, and saves the result, based on the original record and his changes, overwriting the transaction entered by clerk 1. The record no longer reflects the first transaction, as if it had never taken place.
308:
If lock requests for the same entity are queued, then once a shared lock is granted, any queued shared locks may also be granted. If an exclusive lock is found next on the queue, it must wait until all shared locks have been released. As with exclusive locks, these shared locks should be held for the
291:
queue. This would ensure that any possible waiter would get equal chance to obtain the lock and not be locked out. To further speed up the process, if an entity has gone to sleep waiting for a lock, performance is improved if the entity is notified of the grant, instead of discovering it on some sort
158:
when retrieved for editing or updating. Anyone attempting to retrieve the same record for editing is denied write access because of the lock (although, depending on the implementation, they may be able to view the record without editing it). Once the record is saved or edits are canceled, the lock
304:
can contain multiple entries. Shared locks allow all holders to read the contents of the record knowing that the record cannot be changed until after the lock has been released by all holders. Exclusive locks cannot be obtained when a record is already locked (exclusively or shared) by another
150:
whenever a record is being modified by any user, so that no other user can save data. This prevents records from being overwritten incorrectly, but allows only one record to be processed at a time, locking out other users who need to edit records at the same time.
253:
The application or system should be designed such that any lock is held for the shortest time possible. Data reading, without editing facilities, does not require a lock, and reading locked records is usually permissible.
215:
is achieved if each individual account may be taken by a clerk. This would allow any customer to be serviced without waiting for another customer who is accessing a different account. This is analogous to a
204:, provided that each customer's account is found on a different page than the others. If two customers have accounts on the same page, then only one may be serviced at a time. This is analogous to a
200:
If the clerks can remove one page from the ledger, containing the account of the current customer (plus several other accounts), then multiple customers can be serviced
189:
If the bank clerks (to follow the illustration above) are serving two customers, but their accounts are contained in one ledger, then the entire ledger, or one or more
265:
Exclusive locks are exclusively held by a single entity, usually for the purpose of writing to the record. If the locking schema was represented by a list, the
250:, and no other entity is effectively locked out. The entities that request a lock can be either individual applications (programs) or an entire processor.
154:
To allow several users to edit a database table at the same time and also prevent inconsistencies created by unrestricted access, a single record can be
269:
would contain only one entry. Since this type of lock effectively blocks any other entity that requires the lock from processing, care must be used to:
246:
Record locks need to be managed between the entities requesting the records such that no entity is given too much service via successive
276:
not hold the lock across system or function calls where the entity is no longer running on the processor – this can lead to deadlock;
353:
108:
288:
379:
42:
201:
89:
46:
61:
178:
374:
193:, would need to be made available for editing to the clerks in order for each to complete a transaction, one at a time (
231:
68:
35:
75:
318:
57:
345:
339:
349:
140:
82:
230:
The introduction of granular (subset) locks creates the possibility for a situation called
220:
and is normally the highest degree of locking granularity in a database management system.
139:
for two different transactions. Clerks 1 and 2 both retrieve (i.e., copy) the account's
190:
160:
368:
159:
is released. Records can never be saved so as to overwrite other changes, preserving
279:
ensure that if the entity is unexpectedly exited for any reason, the lock is freed.
194:
147:
136:
212:
24:
287:) can be held in a list that is serviced in a round-robin fashion, or in a
125:
132:
177:
A thorough and authoritative description of locking was written by
171:
124:
is the technique of preventing simultaneous access to data in a
170:
among multiple database users. This is the "I" in the acronym
224:
18:
166:
In database management theory, locking is used to implement
341:
Distributed
Transaction Processing: Concepts and Techniques
197:). While safe, this method can cause unnecessary waiting.
273:
ensure the lock is held for the shortest time possible;
300:
Shared locks differ from exclusive locks in that the
49:. Unsourced material may be challenged and removed.
227:database, a record is typically called a "row".
8:
131:The classic example is demonstrated by two
257:Two main types of locks can be requested:
109:Learn how and when to remove this message
338:Gray, Jim & Reuter, Andreas (1993),
330:
16:Solution for concurrent database access
135:clerks attempting to update the same
7:
47:adding citations to reliable sources
146:A simple way to prevent this is to
128:, to prevent inconsistent results.
292:of system timeout driven wake-up.
14:
283:Non-holders of the lock (a.k.a.
23:
34:needs additional citations for
1:
344:, Morgan Kaufmann, pp.
234:. Deadlock is possible when
396:
380:Transaction processing
309:least time possible.
185:Granularity of locks
43:improve this article
375:Concurrency control
319:Readers–writer lock
236:incremental locking
211:A higher degree of
218:record level lock
119:
118:
111:
93:
387:
359:
358:
335:
114:
107:
103:
100:
94:
92:
58:"Record locking"
51:
27:
19:
395:
394:
390:
389:
388:
386:
385:
384:
365:
364:
363:
362:
356:
337:
336:
332:
327:
315:
298:
263:
261:Exclusive locks
244:
208:in a database.
206:page level lock
191:database tables
187:
115:
104:
98:
95:
52:
50:
40:
28:
17:
12:
11:
5:
393:
391:
383:
382:
377:
367:
366:
361:
360:
354:
329:
328:
326:
323:
322:
321:
314:
311:
297:
294:
281:
280:
277:
274:
262:
259:
243:
240:
186:
183:
161:data integrity
122:Record locking
117:
116:
31:
29:
22:
15:
13:
10:
9:
6:
4:
3:
2:
392:
381:
378:
376:
373:
372:
370:
357:
355:1-55860-190-2
351:
347:
343:
342:
334:
331:
324:
320:
317:
316:
312:
310:
306:
303:
295:
293:
290:
286:
278:
275:
272:
271:
270:
268:
260:
258:
255:
251:
249:
241:
239:
237:
233:
228:
226:
221:
219:
214:
209:
207:
203:
198:
196:
192:
184:
182:
180:
175:
173:
169:
164:
162:
157:
152:
149:
148:lock the file
144:
142:
138:
134:
129:
127:
123:
113:
110:
102:
99:December 2009
91:
88:
84:
81:
77:
74:
70:
67:
63:
60: –
59:
55:
54:Find sources:
48:
44:
38:
37:
32:This article
30:
26:
21:
20:
340:
333:
307:
301:
299:
296:Shared locks
284:
282:
266:
264:
256:
252:
247:
245:
242:Use of locks
235:
229:
222:
217:
210:
205:
202:concurrently
199:
195:file locking
188:
176:
167:
165:
155:
153:
145:
137:bank account
130:
121:
120:
105:
96:
86:
79:
72:
65:
53:
41:Please help
36:verification
33:
302:holder list
267:holder list
213:granularity
369:Categories
325:References
69:newspapers
168:isolation
313:See also
305:entity.
232:deadlock
179:Jim Gray
126:database
346:375–437
285:waiters
83:scholar
352:
248:grants
156:locked
141:record
85:
78:
71:
64:
56:
223:In a
90:JSTOR
76:books
350:ISBN
289:FIFO
172:ACID
133:bank
62:news
225:SQL
45:by
371::
348:,
181:.
174:.
163:.
112:)
106:(
101:)
97:(
87:·
80:·
73:·
66:·
39:.
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.