org.apache.derby.impl.store.access.btree.index
Class B2IRowLocking3

java.lang.Object
  extended byorg.apache.derby.impl.store.access.btree.index.B2IRowLocking3
All Implemented Interfaces:
BTreeLockingPolicy
Direct Known Subclasses:
B2IRowLockingRR

class B2IRowLocking3
extends java.lang.Object
implements BTreeLockingPolicy


Field Summary
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.
private  Transaction rawtran
          The transaction to associate lock requests with.
private  LockingPolicy scan_locking_policy
          The locking policy to use to get and release the scan locks.
 
Constructor Summary
(package private) B2IRowLocking3(Transaction rawtran, int lock_level, LockingPolicy locking_policy, ConglomerateController base_cc, OpenBTree open_btree)
          Constructors for This class:
 
Method Summary
private  boolean _lockScan(RecordHandle rh, boolean forUpdate, boolean wait)
          Private methods of This class:
protected  boolean _lockScanRow(OpenBTree open_btree, BTree btree, BTreeRowPosition pos, boolean request_row_lock, boolean request_scan_lock, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, boolean previous_key_lock, boolean forUpdate, int lock_operation)
          Lock a row as part of doing the scan.
 boolean lockNonScanPreviousRow(BTree btree, 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)
          Lock the row previous to the input row.
 boolean lockNonScanRow(BTree btree, LeafControlRow current_leaf, LeafControlRow aux_leaf, DataValueDescriptor[] current_row, int lock_operation)
          Lock the in memory row.
 boolean lockNonScanRowOnPage(BTree btree, LeafControlRow current_leaf, int current_slot, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, int lock_operation)
          Lock the row at the given slot.
private  boolean lockPreviousToFirstKey(LeafControlRow current_leaf, LeafControlRow aux_leaf, int lock_operation, int lock_duration)
          Lock key previous to first key in btree.
private  boolean lockRowOnPage(BTree btree, LeafControlRow current_leaf, LeafControlRow aux_leaf, int current_slot, boolean check_changed_rowloc, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, int lock_operation, int lock_duration)
          Lock a btree row (row is at given slot in page).
 boolean lockScan(LeafControlRow current_leaf, ControlRow aux_control_row, boolean forUpdate, int lock_operation)
          Lock a control row page for scan.
 boolean lockScanCommittedDeletedRow(OpenBTree open_btree, LeafControlRow leaf, DataValueDescriptor[] template, FetchDescriptor lock_fetch_desc, int slot_no)
          Lock a btree row to determine if it is a committed deleted row.
 boolean lockScanForReclaimSpace(LeafControlRow current_leaf)
          Lock a control row page for reclaiming deleted rows.
 boolean lockScanRow(OpenBTree open_btree, BTree btree, BTreeRowPosition pos, boolean request_scan_lock, FetchDescriptor lock_fetch_desc, DataValueDescriptor[] lock_template, RowLocation lock_row_loc, boolean previous_key_lock, boolean forUpdate, int lock_operation)
          Lock a row as part of doing the scan.
private  boolean searchLeftAndLockPreviousKey(B2I b2i, 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)
           
 void unlockScan(long page_number)
          Release the lock gotten by calling lockScan.
 void unlockScanRecordAfterRead(BTreeRowPosition pos, boolean forUpdate)
          Release read lock on a row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base_cc

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_btree

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


scan_locking_policy

private LockingPolicy scan_locking_policy
The locking policy to use to get and release the scan locks. We could cache this somewhere better.


rawtran

private Transaction rawtran
The transaction to associate lock requests with.

Constructor Detail

B2IRowLocking3

B2IRowLocking3(Transaction rawtran,
               int lock_level,
               LockingPolicy locking_policy,
               ConglomerateController base_cc,
               OpenBTree open_btree)
Constructors for This class:

Method Detail

_lockScan

private boolean _lockScan(RecordHandle rh,
                          boolean forUpdate,
                          boolean wait)
                   throws StandardException
Private methods of This class:

Throws:
StandardException

lockPreviousToFirstKey

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 - If non-null, this leaf is unlatched if the routine has to wait on the lock.
lock_duration - 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.
Throws:
StandardException - Standard exception policy.

lockRowOnPage

private boolean lockRowOnPage(BTree btree,
                              LeafControlRow current_leaf,
                              LeafControlRow aux_leaf,
                              int current_slot,
                              boolean check_changed_rowloc,
                              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:
btree - The conglomerate we are locking.
current_leaf - Latched current leaf where "current" key is.
aux_leaf - If non-null, this leaf is unlatched if the routine has to wait on the lock.
current_slot - Slot of row to lock.
lock_fetch_desc - Descriptor for fetching just the RowLocation, used for locking.
check_changed_rowloc - whether to check for the changed rowloc or not.
lock_duration - 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.
Throws:
StandardException - Standard exception policy.

searchLeftAndLockPreviousKey

private boolean searchLeftAndLockPreviousKey(B2I b2i,
                                             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
Throws:
StandardException

_lockScanRow

protected boolean _lockScanRow(OpenBTree open_btree,
                               BTree btree,
                               BTreeRowPosition pos,
                               boolean request_row_lock,
                               boolean request_scan_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). Get the scan lock on the page if "request_scan_lock" is true.

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. (p> As a sided effect stores the value of the record handle of the current scan lock.

Parameters:
open_btree - The open_btree to associate latches with - used if routine has to scan backward.
btree - the conglomerate info.
request_row_lock - Whether to request the row lock, should only be requested once per page in the scan.
request_scan_lock - Whether to request the page scan lock, should only be requested once per page in the scan.
previous_key_lock - Is this a previous key lock call?
forUpdate - Is the scan for update or for read only.
Returns:
Whether locks were acquired without releasing latch on leaf.
Throws:
StandardException - Standard exception policy.

lockScan

public boolean lockScan(LeafControlRow current_leaf,
                        ControlRow aux_control_row,
                        boolean forUpdate,
                        int lock_operation)
                 throws StandardException
Lock a control row page for scan.

Scanners get shared lock on the page while positioned on a row within the page, splitter/purgers/mergers get exclusive lock on the page. See BTree.lockScan() for more info.

Specified by:
lockScan in interface BTreeLockingPolicy
Parameters:
current_leaf - The lock is associated with this page in the btree. This control row is unlatched if the routine has to wait on the lock.
aux_control_row - If non-null, this control row is unlatched if the routine has to wait on the lock.
forUpdate - Whether to wait for lock.
Throws:
StandardException - Standard exception policy.

lockScanForReclaimSpace

public boolean lockScanForReclaimSpace(LeafControlRow current_leaf)
                                throws StandardException
Lock a control row page for reclaiming deleted rows.

When reclaiming deleted rows during split need to get an exclusive scan lock on the page, which will mean there are no other scans positioned on the page. If there are other scans positioned, just give up on reclaiming space now.

Specified by:
lockScanForReclaimSpace in interface BTreeLockingPolicy
Returns:
true if lock was granted nowait, else false and not lock was granted.
Throws:
StandardException - Standard exception policy.

lockScanCommittedDeletedRow

public boolean lockScanCommittedDeletedRow(OpenBTree open_btree,
                                           LeafControlRow leaf,
                                           DataValueDescriptor[] template,
                                           FetchDescriptor lock_fetch_desc,
                                           int slot_no)
                                    throws StandardException
Lock a btree row to determine if it is a committed deleted row.

Specified by:
lockScanCommittedDeletedRow in interface BTreeLockingPolicy
Parameters:
open_btree - The conglomerate we are locking.
leaf - The leaf page with the row to lock.
template - Empty full template row, to read row into.
slot_no - The slot of row on "current_leaf"
Throws:
StandardException - Standard exception policy.
See Also:
BTreeLockingPolicy.lockScanCommittedDeletedRow(org.apache.derby.impl.store.access.btree.OpenBTree, org.apache.derby.impl.store.access.btree.LeafControlRow, org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.store.raw.FetchDescriptor, int)

lockScanRow

public boolean lockScanRow(OpenBTree open_btree,
                           BTree btree,
                           BTreeRowPosition pos,
                           boolean request_scan_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). Get the scan lock on the page if "request_scan_lock" is true.

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. (p> As a sided effect stores the value of the record handle of the current scan lock.

Specified by:
lockScanRow in interface BTreeLockingPolicy
Parameters:
open_btree - The open_btree to associate latches with - used if routine has to scan backward.
btree - the conglomerate info.
request_scan_lock - Whether to request the page scan lock, should only be requested once per page in the scan.
previous_key_lock - Is this a previous key lock call?
forUpdate - Is the scan for update or for read only.
Returns:
Whether locks were acquired without releasing latch on leaf.
Throws:
StandardException - Standard exception policy.

unlockScanRecordAfterRead

public void unlockScanRecordAfterRead(BTreeRowPosition pos,
                                      boolean forUpdate)
                               throws StandardException
Release read lock on a row. For serializable, there is no work to do.

Specified by:
unlockScanRecordAfterRead in interface BTreeLockingPolicy
Parameters:
pos - Data structure that defines the current position in the scan to be unlocked.
forUpdate - Is the scan for update or for read only.
Throws:
StandardException - Standard exception policy.

unlockScan

public void unlockScan(long page_number)
Release the lock gotten by calling lockScan. This call can only be made to release read scan locks, write scan locks must be held until end of transaction.

See BTree.unlockScan() for more info.

Specified by:
unlockScan in interface BTreeLockingPolicy
Parameters:
page_number - page number of page that lockScan was called on.

lockNonScanPreviousRow

public boolean lockNonScanPreviousRow(BTree btree,
                                      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
Lock the row previous to the input row.

See BTree.lockPreviousRow() for more info.

Specified by:
lockNonScanPreviousRow in interface BTreeLockingPolicy
Parameters:
btree - The conglomerate we are locking.
current_leaf - Latched current leaf where "current" key is.
current_slot - The slot of row on "current_leaf"
open_btree - The open_btree to associate latches with - used if routine has to scan backward.
lock_duration - 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.
Throws:
StandardException - Standard exception policy.

lockNonScanRow

public boolean lockNonScanRow(BTree btree,
                              LeafControlRow current_leaf,
                              LeafControlRow aux_leaf,
                              DataValueDescriptor[] current_row,
                              int lock_operation)
                       throws StandardException
Lock the in memory row.

See BTree.lockRow() for more info.

Specified by:
lockNonScanRow in interface BTreeLockingPolicy
Parameters:
btree - The conglomerate we are locking.
current_leaf - If non-null, this leaf is unlatched if the routine has to wait on the lock.
aux_leaf - If non-null, this leaf is unlatched if the routine has to wait on the lock.
current_row - In memory, objectified "current" row.
Throws:
StandardException - Standard exception policy.

lockNonScanRowOnPage

public boolean lockNonScanRowOnPage(BTree btree,
                                    LeafControlRow current_leaf,
                                    int current_slot,
                                    FetchDescriptor lock_fetch_desc,
                                    DataValueDescriptor[] lock_template,
                                    RowLocation lock_row_loc,
                                    int lock_operation)
                             throws StandardException
Description copied from interface: BTreeLockingPolicy
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.

Specified by:
lockNonScanRowOnPage in interface BTreeLockingPolicy
Parameters:
btree - the conglomerate info.
current_leaf - The control row of the current leaf to lock.
current_slot - The slot position of the row to lock.
Returns:
Whether locks were acquired without releasing latch on leaf.
Throws:
StandardException - Standard exception policy.


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.