Lock types
When you are using pessimistic and optimistic locking, shared (S), upgradeable (U) and exclusive (X) locks are used to maintain consistency. Understanding locking and its behavior is important when you have pessimistic locking enabled. With optimistic locking, the locks are not held. Different types of locks are compatible with others in various ways. Locks must be handled in the correct order to avoid deadlock scenarios.
Shared, upgradeable, and exclusive locks
When an application calls any method of the map programming interface, WebSphere® eXtreme Scale automatically attempts to acquire a lock for the map entry that is being accessed.In Java applications, locks are also acquired when the applications uses the find methods on an index, or does a query.
Lock mode (Java / .NET) | Java method equivalent | .NET method equivalent |
---|---|---|
SHARED / Shared | get and getAll methods on the ObjectMap interface, index methods, and queries | Get(), GetAndLock(Key,LockMode.Shared), GetAndLockAll(KeyList, LockMode.Shared),GetAll methods |
UPGRADABLE /Upgradable | getForUpdate(), getAllForUpdate() | GetAndLock(Key, LockMode.Updgradable), GetAndLockAll(KeyList, LockMode.Upgradable) |
EXCLUSIVE / Exclusive | getNextKey(), commit(), put, putAll,
remove, removeAll, insert, update, and touch methods, global invalidate and
global invalidateAll methods. (No locks are acquired for the local
invalidate and invalidateAll methods because none of the
BackingMap entries are invalidated by local invalidate method calls.) Note: The upsert and upsertAll methods
replace the ObjectMap
put and putAll methods. Use the upsert
method to tell the BackingMap and loader that an entry in the data grid must place the key and value
into the grid. The BackingMap and loader either inserts or an updates to place the value into the
data grid and loader. If you run the upsert API within your applications, then
the loader gets an UPSERT LogElement type, which allows loaders to do database merge or
upsert calls instead of using insert or update.
|
Commit(), Add, AddAll, Put, PutAll, Remove, RemoveAll,
Replace, ReplaceAll, Touch, TouchAll, Invalidate, InvalidateAll Note: The Put and
PutAll methods are equivalent to the Java upsert and
upsertAll methods.
|
The following table is a lock mode compatibility matrix that summarizes the described lock modes, which you can use to determine which lock modes are compatible with each other. To read this matrix, the row in the matrix indicates a lock mode that is already granted. The column indicates the lock mode that is requested by another transaction. If Yes is displayed in the column, then the lock mode that is requested by the other transaction is granted because it is compatible with the lock mode that is already granted. No indicates that the lock mode is not compatible and the other transaction must wait for the first transaction to release the lock that it owns.
Lock | Lock type S (shared) | Lock type U (upgradeable) | Lock type X (exclusive) | Strength |
---|---|---|---|---|
S (shared) | Yes | Yes | No | weakest |
U (upgradeable) | Yes | No | No | normal |
X (exclusive) | No | No | No | strongest |