DataNucleus - Products
  History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CORE-2462
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Erik Bengtson
Reporter: Erik Bengtson
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
JPOX Core

Update lock for MSSQL (kind of SELECT FOR UPDATE)

Created: 21/Aug/05 05:06 PM   Updated: 22/Aug/05 09:24 PM
Component/s: Datastore Support
Affects Version/s: 1.1.0-beta-3
Fix Version/s: 1.1.0-beta-4

File Attachments: 1. Text File DatabaseAdapter_patch.txt (1 kb)
2. Text File MSSQLServerAdapter_patch.txt (2 kb)
3. Text File QueryStatement_patch.txt (8 kb)
4. Text File RDBMSAdapter_patch.txt (1 kb)
5. Text File RDBMSFetchStatement_patch.txt (4 kb)


Datastore: Microsoft SQL Server


 Description  « Hide
Update (U) locks prevent a common form of deadlock. A typical update pattern consists of a transaction reading a record, acquiring a shared (S) lock on the resource (page or row), and then modifying the row, which requires lock conversion to an exclusive (X) lock. If two transactions acquire shared-mode locks on a resource and then attempt to update data concurrently, one transaction attempts the lock conversion to an exclusive (X) lock. The shared-mode-to-exclusive lock conversion must wait because the exclusive lock for one transaction is not compatible with the shared-mode lock of the other transaction; a lock wait occurs. The second transaction attempts to acquire an exclusive (X) lock for its update. Because both transactions are converting to exclusive (X) locks, and they are each waiting for the other transaction to release its shared-mode lock, a deadlock occurs.

To avoid this potential deadlock problem, update (U) locks are used. Only one transaction can obtain an update (U) lock to a resource at a time. If a transaction modifies a resource, the update (U) lock is converted to an exclusive (X) lock. Otherwise, the lock is converted to a shared-mode lock.

Locking Hints
UPDLOCK

Use update locks instead of shared locks while reading a table, and hold locks until the end of the statement or transaction. UPDLOCK has the advantage of allowing you to read data (without blocking other readers) and update it later with the assurance that the data has not changed since you last read it.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Erik Bengtson - 21/Aug/05 05:08 PM
patch provided by Jörg von Frantzius

Erik Bengtson - 21/Aug/05 05:09 PM
patch provided by Jörg von Frantzius