Top Description Fields Constructors Methods
org.apache.derby.impl.store.access.btree.index

pack-priv Class B2IRowLocking3

extends Object
implements BTreeLockingPolicy
Class Inheritance
All Implemented Interfaces
org.apache.derby.impl.store.access.btree.BTreeLockingPolicy
Known Direct Subclasses
org.apache.derby.impl.store.access.btree.index.B2IRowLockingRR
Imports
org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.store.access.conglomerate.TransactionManager, org.apache.derby.iapi.store.access.ConglomerateController, org.apache.derby.iapi.store.raw.FetchDescriptor, .LockingPolicy, .RecordHandle, .Transaction, org.apache.derby.iapi.types.DataValueDescriptor, .RowLocation, org.apache.derby.impl.store.access.btree.BTree, .BTreeLockingPolicy, .ControlRow, .LeafControlRow, .OpenBTree, .BTreeRowPosition, .WaitError, org.apache.derby.impl.store.access.heap.HeapController

Implements the jdbc serializable isolation level using row locks.

Holds read and write locks until end of transaction. Obtains previous key locks to protect from phantom reads.

Field Summary

Modifier and TypeField and Description
protected ConglomerateController
base_cc

The container id of the base container for this index.

protected OpenBTree
open_btree

The OpenBtree to use if we have to lock anything in the btree vs. base row locking.

private Transaction
rawtran

The transaction to associate lock requests with.

Constructor Summary

AccessConstructor and Description
pack-priv
B2IRowLocking3(Transaction rawtran, int lock_level, LockingPolicy locking_policy, ConglomerateController base_cc, OpenBTree open_btree)

Constructors for This class:

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

Whether locks were acquired without releasing latch on leaf.
_lockScanRow
(OpenBTree
The open_btree to associate latches with - used if routine has to scan backward.
open_btree
,
BTreeRowPosition
The position of the row to lock.
pos
,
boolean
Whether to request the row lock, should only be requested once per page in the scan.
request_row_lock
,
FetchDescriptor
The fetch descriptor to use to fetch the row location for the lock request.
lock_fetch_desc
,
DataValueDescriptor[]
A scratch area to use to read in rows.
lock_template
,
RowLocation lock_row_loc, boolean
Is this a previous key lock call?
previous_key_lock
,
boolean
Is the scan for update or for read only.
forUpdate
,
int lock_operation)

Lock a row as part of doing the scan.

public boolean
lockNonScanPreviousRow(LeafControlRow
Latched current leaf where "current" key is.
current_leaf
,
int
The slot of row on "current_leaf"
current_slot
,
FetchDescriptor lock_fetch_desc, DataValueDescriptor[]
Empty full template row, to read row into.
lock_template
,
RowLocation lock_row_loc, OpenBTree
The open_btree to associate latches with - used if routine has to scan backward.
open_btree
,
int
For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace]
lock_operation
,
int
For what duration should the lock be held, if INSTANT_DURATION, then the routine will guarantee that lock was acquired while holding the latch, but then immediately release the lock. If COMMIT_DURATION or MANUAL_DURATION then the lock be held when routine returns successfully.
lock_duration
)

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanPreviousRow.

Lock the row previous to the input row.

public boolean
lockNonScanRow(BTree
The conglomerate we are locking.
btree
,
LeafControlRow
If non-null, this leaf is unlatched if the routine has to wait on the lock.
current_leaf
,
LeafControlRow
If non-null, this leaf is unlatched if the routine has to wait on the lock.
aux_leaf
,
DataValueDescriptor[]
In memory, objectified "current" row.
current_row
,
int
For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace]
lock_operation
)

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRow.

Lock the in memory row.

public boolean
lockNonScanRowOnPage(LeafControlRow
The control row of the current leaf to lock.
current_leaf
,
int
The slot position of the row to lock.
current_slot
,
FetchDescriptor lock_fetch_desc, DataValueDescriptor[]
A scratch area to use to read in rows.
lock_template
,
RowLocation lock_row_loc, int
For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace]
lock_operation
)

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRowOnPage.

Lock the row at the given slot.

private boolean
lockPreviousToFirstKey(LeafControlRow current_leaf, LeafControlRow
If non-null, this leaf is unlatched if the routine has to wait on the lock.
aux_leaf
,
int
Whether to lock exclusive or share.
lock_operation
,
int
For what duration should the lock be held, if INSTANT_DURATION, then the routine will guarantee that lock was acquired while holding the latch, but then immediately release the lock. If COMMIT_DURATION or MANUAL_DURATION then the lock be held when routine returns successfully.
lock_duration
)

Lock key previous to first key in btree.

private boolean
lockRowOnPage(LeafControlRow
Latched current leaf where "current" key is.
current_leaf
,
LeafControlRow
If non-null, this leaf is unlatched if the routine has to wait on the lock.
aux_leaf
,
int
Slot of row to lock.
current_slot
,
BTreeRowPosition
The position to lock if the lock is requested while performing a scan, null otherwise.
position
,
FetchDescriptor
Descriptor for fetching just the RowLocation, used for locking.
lock_fetch_desc
,
DataValueDescriptor[] lock_template, RowLocation lock_row_loc, int
Whether lock is for key prev to insert or not.
lock_operation
,
int
For what duration should the lock be held, if INSTANT_DURATION, then the routine will guarantee that lock was acquired while holding the latch, but then immediately release the lock. If COMMIT_DURATION or MANUAL_DURATION then the lock be held when routine returns successfully.
lock_duration
)

Lock a btree row (row is at given slot in page).

public boolean
lockScanCommittedDeletedRow(OpenBTree
The conglomerate we are locking.
open_btree
,
LeafControlRow
The leaf page with the row to lock.
leaf
,
DataValueDescriptor[]
Empty full template row, to read row into.
template
,
FetchDescriptor lock_fetch_desc, int
The slot of row on "current_leaf"
slot_no
)

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanCommittedDeletedRow.

Lock a btree row to determine if it is a committed deleted row.

public boolean

Returns:

Whether locks were acquired without releasing latch on leaf.
lockScanRow
(OpenBTree
The open_btree to associate latches with - used if routine has to scan backward.
open_btree
,
BTreeRowPosition
The position of the row to lock.
pos
,
FetchDescriptor lock_fetch_desc, DataValueDescriptor[]
A scratch area to use to read in rows.
lock_template
,
RowLocation lock_row_loc, boolean
Is this a previous key lock call?
previous_key_lock
,
boolean
Is the scan for update or for read only.
forUpdate
,
int
For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace]
lock_operation
)

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanRow.

Lock a row as part of doing the scan.

private boolean

Returns:

true if previous key found without ever waiting on a latch, false if latch released in order to wait for other latch.
searchLeftAndLockPreviousKey
(LeafControlRow current_leaf, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, OpenBTree open_btree, int lock_operation, int lock_duration)

move left in btree and lock previous key.

public void
unlockScanRecordAfterRead(BTreeRowPosition
Data structure that defines the current position in the scan to be unlocked.
pos
,
boolean
Is the scan for update or for read only.
forUpdate
)

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.unlockScanRecordAfterRead.

Release read lock on a row.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

base_ccback to summary
protected ConglomerateController base_cc

The container id of the base container for this index. Used to build record handles to make lock calls on.

open_btreeback to summary
protected OpenBTree open_btree

The OpenBtree to use if we have to lock anything in the btree vs. base row locking.

rawtranback to summary
private Transaction rawtran

The transaction to associate lock requests with.

Constructor Detail

B2IRowLocking3back to summary
pack-priv B2IRowLocking3(Transaction rawtran, int lock_level, LockingPolicy locking_policy, ConglomerateController base_cc, OpenBTree open_btree)

Constructors for This class:

Method Detail

_lockScanRowback to summary
protected boolean _lockScanRow(OpenBTree open_btree, BTreeRowPosition pos, boolean request_row_lock, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, boolean previous_key_lock, boolean forUpdate, int lock_operation) throws StandardException

Lock a row as part of doing the scan.

Lock the row at the given slot (or the previous row if slot is 0).

If this routine returns true all locks were acquired while maintaining the latch on leaf. If this routine returns false, locks may or may not have been acquired, and the routine should be called again after the client has researched the tree to reget the latch on the appropriate page.

Parameters
open_btree:OpenBTree

The open_btree to associate latches with - used if routine has to scan backward.

pos:BTreeRowPosition

The position of the row to lock.

request_row_lock:boolean

Whether to request the row lock, should only be requested once per page in the scan.

lock_fetch_desc:FetchDescriptor

The fetch descriptor to use to fetch the row location for the lock request.

lock_template:DataValueDescriptor[]

A scratch area to use to read in rows.

previous_key_lock:boolean

Is this a previous key lock call?

forUpdate:boolean

Is the scan for update or for read only.

Returns:boolean

Whether locks were acquired without releasing latch on leaf.

Exceptions
StandardException:
Standard exception policy.
lockNonScanPreviousRowback to summary
public boolean lockNonScanPreviousRow(LeafControlRow current_leaf, int current_slot, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, OpenBTree open_btree, int lock_operation, int lock_duration) throws StandardException

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanPreviousRow.

Lock the row previous to the input row.

See BTreeLockingPolicy.lockNonScanPreviousRow

Parameters
current_leaf:LeafControlRow

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanPreviousRow.

Latched current leaf where "current" key is.

current_slot:int

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanPreviousRow.

The slot of row on "current_leaf"

lock_template:DataValueDescriptor[]

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanPreviousRow.

Empty full template row, to read row into.

open_btree:OpenBTree

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanPreviousRow.

The open_btree to associate latches with - used if routine has to scan backward.

lock_operation:int

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanPreviousRow.

For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace]

lock_duration:int

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanPreviousRow.

For what duration should the lock be held, if INSTANT_DURATION, then the routine will guarantee that lock was acquired while holding the latch, but then immediately release the lock. If COMMIT_DURATION or MANUAL_DURATION then the lock be held when routine returns successfully.

Exceptions
StandardException:
Standard exception policy.
lockNonScanRowback to summary
public boolean lockNonScanRow(BTree btree, LeafControlRow current_leaf, LeafControlRow aux_leaf, DataValueDescriptor[] current_row, int lock_operation) throws StandardException

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRow.

Lock the in memory row.

See BTree.lockRow() for more info.

Parameters
btree:BTree

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRow.

The conglomerate we are locking.

current_leaf:LeafControlRow

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRow.

If non-null, this leaf is unlatched if the routine has to wait on the lock.

aux_leaf:LeafControlRow

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRow.

If non-null, this leaf is unlatched if the routine has to wait on the lock.

current_row:DataValueDescriptor[]

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRow.

In memory, objectified "current" row.

lock_operation:int

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRow.

For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace]

Exceptions
StandardException:
Standard exception policy.
lockNonScanRowOnPageback to summary
public boolean lockNonScanRowOnPage(LeafControlRow current_leaf, int current_slot, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, int lock_operation) throws StandardException

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRowOnPage.

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockNonScanRowOnPage.

Lock the row at the given slot.

If this routine returns true all locks were acquired while maintaining the latch on leaf. If this routine returns false, locks may or may not have been acquired, and the routine should be called again after the client has researched the tree to reget the latch on the appropriate page.

Parameters
current_leaf:LeafControlRow

The control row of the current leaf to lock.

current_slot:int

The slot position of the row to lock.

lock_template:DataValueDescriptor[]

A scratch area to use to read in rows.

lock_operation:int

For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace]

Returns:boolean

Whether locks were acquired without releasing latch on leaf.

Exceptions
StandardException:
Standard exception policy.
lockPreviousToFirstKeyback to summary
private boolean lockPreviousToFirstKey(LeafControlRow current_leaf, LeafControlRow aux_leaf, int lock_operation, int lock_duration) throws StandardException

Lock key previous to first key in btree.

In the previous key locking protocol repeatable read and phantom protection is guaranteed by locking a range of keys in the btree. The range is defined by the key previous to the first key you look at and all subsequent keys you look at. The first key in the index is a special case, as there are no keys previous to it. In that case a special key is declared the "previous key" to the first key in the btree and is locked instead.

In this implementation that first key is defined to be in the base container, page ContainerHandle.FIRST_PAGE_NUMBER, record id PREVIOUS_KEY_HANDLE.

Note that the previous key is the same for all indexes on a given conglomerate. It seemed better for all locks on a base table to have the same containerid, rather than having some locks generated from a btree have a containerid from base table and some having a containerid from the btree. If this turns out to be a problem we could either have 2 different containerid's, be more creative with the record id, or even add more to the lock key.

Parameters
aux_leaf:LeafControlRow

If non-null, this leaf is unlatched if the routine has to wait on the lock.

lock_operation:int

Whether to lock exclusive or share.

lock_duration:int

For what duration should the lock be held, if INSTANT_DURATION, then the routine will guarantee that lock was acquired while holding the latch, but then immediately release the lock. If COMMIT_DURATION or MANUAL_DURATION then the lock be held when routine returns successfully.

Exceptions
StandardException:
Standard exception policy.
lockRowOnPageback to summary
private boolean lockRowOnPage(LeafControlRow current_leaf, LeafControlRow aux_leaf, int current_slot, BTreeRowPosition position, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, int lock_operation, int lock_duration) throws StandardException

Lock a btree row (row is at given slot in page).

Lock the row at the given slot in the page. Meant to be used if caller only has the slot on the page to be locked, and has not read the row yet. This routine fetches the row location field from the page, and then locks that rowlocation in the base container.

Lock a btree row, enforcing the standard lock/latch protocol. On return the row is locked. Return status indicates if the lock was waited for, which will mean a latch was dropped while waiting. In general a false status means that the caller will either have to research the tree unless some protocol has been implemented that insures that the row will not have moved while the latch was dropped.

This routine request a row lock NOWAIT on the in-memory row "current_row.". If the lock is granted the routine will return true. If the lock cannot be granted NOWAIT, then the routine will release the latch on "current_leaf" and "aux_leaf" (if aux_leaf is non-null), and then it will request a WAIT lock on the row.

Parameters
current_leaf:LeafControlRow

Latched current leaf where "current" key is.

aux_leaf:LeafControlRow

If non-null, this leaf is unlatched if the routine has to wait on the lock.

current_slot:int

Slot of row to lock.

position:BTreeRowPosition

The position to lock if the lock is requested while performing a scan, null otherwise.

lock_fetch_desc:FetchDescriptor

Descriptor for fetching just the RowLocation, used for locking.

lock_operation:int

Whether lock is for key prev to insert or not.

lock_duration:int

For what duration should the lock be held, if INSTANT_DURATION, then the routine will guarantee that lock was acquired while holding the latch, but then immediately release the lock. If COMMIT_DURATION or MANUAL_DURATION then the lock be held when routine returns successfully.

Exceptions
StandardException:
Standard exception policy.
lockScanCommittedDeletedRowback to summary
public boolean lockScanCommittedDeletedRow(OpenBTree open_btree, LeafControlRow leaf, DataValueDescriptor[] template, FetchDescriptor lock_fetch_desc, int slot_no) throws StandardException

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanCommittedDeletedRow.

Lock a btree row to determine if it is a committed deleted row.

Parameters
open_btree:OpenBTree

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanCommittedDeletedRow.

The conglomerate we are locking.

leaf:LeafControlRow

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanCommittedDeletedRow.

The leaf page with the row to lock.

template:DataValueDescriptor[]

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanCommittedDeletedRow.

Empty full template row, to read row into.

slot_no:int

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanCommittedDeletedRow.

The slot of row on "current_leaf"

Exceptions
StandardException:
Standard exception policy.
See Also
BTreeLockingPolicy#lockScanCommittedDeletedRow
lockScanRowback to summary
public boolean lockScanRow(OpenBTree open_btree, BTreeRowPosition pos, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, boolean previous_key_lock, boolean forUpdate, int lock_operation) throws StandardException

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanRow.

Lock a row as part of doing the scan.

Lock the row at the given slot (or the previous row if slot is 0).

If this routine returns true all locks were acquired while maintaining the latch on leaf. If this routine returns false, locks may or may not have been acquired, and the routine should be called again after the client has researched the tree to reget the latch on the appropriate page.

Parameters
open_btree:OpenBTree

The open_btree to associate latches with - used if routine has to scan backward.

pos:BTreeRowPosition

The position of the row to lock.

lock_template:DataValueDescriptor[]

A scratch area to use to read in rows.

previous_key_lock:boolean

Is this a previous key lock call?

forUpdate:boolean

Is the scan for update or for read only.

lock_operation:int

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.lockScanRow.

For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace]

Returns:boolean

Whether locks were acquired without releasing latch on leaf.

Exceptions
StandardException:
Standard exception policy.
searchLeftAndLockPreviousKeyback to summary
private boolean searchLeftAndLockPreviousKey(LeafControlRow current_leaf, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, OpenBTree open_btree, int lock_operation, int lock_duration) throws StandardException

move left in btree and lock previous key.

Enter routine with "current_leaf" latched. This routine implements the left travel ladder locking protocol to search the leaf pages from right to left for the previous key to 1st key on current_leaf. There are 2 cases: 1) the previous page has keys, in which case the last key on that page is locked, other wise search continues on the next page to the left. 2) there are no keys on the current page and there is no page to the left. In this case the special "leftmost key" lock is gotten by calling lockPreviousToFirstKey(). Left laddar locking is used if all latches can be obtained immediately with NOWAIT. This means that current latch is held while asking for left latch NOWAIT, and if left latch is granted then subsequently current latch can be released. If this protocol is followed and all latches are granted then caller is guaranteed that the correct previous key has been locked and current_page latch remains. The NOWAIT protocol is used to avoid latch/latch deadlocks. The overall protocol is that one never holds a latch while waiting on another unless the direction of travel is down and to the right.

If along the search a latch has to be waited on then latches are released and a wait is performed, and "false" status is returned to caller. In this case the routine can no longer be sure of it's current position and may have to retry the whole operation.

Returns:boolean

true if previous key found without ever waiting on a latch, false if latch released in order to wait for other latch.

Exceptions
StandardException:
Standard exception policy.
unlockScanRecordAfterReadback to summary
public void unlockScanRecordAfterRead(BTreeRowPosition pos, boolean forUpdate) throws StandardException

Implements org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.unlockScanRecordAfterRead.

Release read lock on a row. For serializable, there is no work to do.

Parameters
pos:BTreeRowPosition

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.unlockScanRecordAfterRead.

Data structure that defines the current position in the scan to be unlocked.

forUpdate:boolean

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.unlockScanRecordAfterRead.

Is the scan for update or for read only.

Exceptions
StandardException:

Doc from org.apache.derby.impl.store.access.btree.BTreeLockingPolicy.unlockScanRecordAfterRead.

Standard exception policy.