📄 b2irowlocking3.java
字号:
} return(ret_status); } /** * Lock a control row page for reclaiming deleted rows. * <p> * 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. * * @return true if lock was granted nowait, else false and not lock was * granted. * * @exception StandardException Standard exception policy. **/ public boolean lockScanForReclaimSpace( LeafControlRow current_leaf) throws StandardException { // The scan page lock is implemented as a row lock on the reserved // row id on the page (RecordHandle.RECORD_ID_PROTECTION_HANDLE). RecordHandle scan_lock_rh = current_leaf.getPage().makeRecordHandle( RecordHandle.RECORD_ID_PROTECTION_HANDLE); // First try to get the lock NOWAIT, while latch is held. return( _lockScan(scan_lock_rh, true /* update */, false /* NOWAIT */)); } /** * Lock a btree row to determine if it is a committed deleted row. * <p> * @see BTreeLockingPolicy#lockScanCommittedDeletedRow * * @exception StandardException Standard exception policy. **/ public boolean lockScanCommittedDeletedRow( OpenBTree open_btree, LeafControlRow leaf, DataValueDescriptor[] template, FetchDescriptor lock_fetch_desc, int slot_no) throws StandardException { if (SanityManager.DEBUG) { SanityManager.ASSERT(leaf != null); if (slot_no <= 0 || slot_no >= leaf.getPage().recordCount()) { SanityManager.THROWASSERT( "slot_no = " + slot_no + "; leaf.getPage().recordCount() = " + leaf.getPage().recordCount()); } SanityManager.ASSERT(template != null, "template is null"); } RowLocation row_loc = (RowLocation) template[((B2I) open_btree.getConglomerate()).rowLocationColumn]; // Fetch the row location to lock. leaf.getPage().fetchFromSlot( (RecordHandle) null, slot_no, template, lock_fetch_desc, true); // Request the lock NOWAIT, return status return( base_cc.lockRow(row_loc, ConglomerateController.LOCK_UPD, false /* NOWAIT */, TransactionManager.LOCK_COMMIT_DURATION)); } /** * Lock a row as part of doing the scan. * <p> * 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. * <p> * 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. * * @return Whether locks were acquired without releasing latch on leaf. * * @param open_btree The open_btree to associate latches with - * used if routine has to scan backward. * @param btree the conglomerate info. * @param pos The position of the row to lock. * @param request_scan_lock Whether to request the page scan lock, should * only be requested once per page in the scan. * @param lock_template A scratch area to use to read in rows. * @param previous_key_lock Is this a previous key lock call? * @param forUpdate Is the scan for update or for read only. * * @exception StandardException Standard exception policy. **/ 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 { return( _lockScanRow( open_btree, btree, pos, true, // request the row lock (always true for iso 3 ) request_scan_lock, lock_fetch_desc, lock_template, lock_row_loc, previous_key_lock, forUpdate, lock_operation)); } /** * Release read lock on a row. * * For serializable, there is no work to do. * * **/ public void unlockScanRecordAfterRead( BTreeRowPosition pos, boolean forUpdate) throws StandardException { return; } /** * 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. * <p> * See BTree.unlockScan() for more info. * **/ public void unlockScan( long page_number) { // This is first row in table, lock the special key that // represents the key previous to the first key of the table. try { RecordHandle scan_lock_rh = open_btree.makeRecordHandle( page_number, RecordHandle.RECORD_ID_PROTECTION_HANDLE); scan_locking_policy.unlockRecordAfterRead( rawtran, open_btree.getContainerHandle(), scan_lock_rh, false, true); } catch (StandardException se) { if (SanityManager.DEBUG) SanityManager.THROWASSERT("error from make RecordHandle."); } } /************************************************************************** * Abstract Protected lockNonScan*() locking methods of BTree: * * lockNonScanPreviousRow - lock the row previous to the current * lockNonScanRow - lock the input row ************************************************************************** */ /** * Lock the row previous to the input row. * <p> * See BTree.lockPreviousRow() for more info. * * @exception StandardException Standard exception policy. **/ 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 { boolean ret_status; if (SanityManager.DEBUG) { SanityManager.ASSERT(btree instanceof B2I); } if (current_slot > 1) { // Easy case, just lock the key previous to the current one. // Lock (current_slot - 1) ret_status = lockRowOnPage( btree, current_leaf, (LeafControlRow) null, current_slot - 1, false, lock_fetch_desc, lock_template, lock_row_loc, lock_operation, lock_duration); } else { // Should only be called while pointing at a valid location, 0 // is not a valid key slot - it is the control row. if (SanityManager.DEBUG) SanityManager.ASSERT(current_slot == 1); if (current_leaf.isLeftmostLeaf()) { // This is first row in table, lock the special key that // represents the key previous to the first key of the table. ret_status = lockPreviousToFirstKey( current_leaf, (LeafControlRow) null, lock_operation, lock_duration); } else { // The previous key is on a previous page, search left // through the pages to find the key to latch. // RESOLVE RLL (mikem) - do I need to do the // RECORD_ID_PROTECTION_HANDLE lock. // First guarantee that record id's will not move off this // current page while searching for previous key, by getting // the RECORD_ID_PROTECTION_HANDLE lock on the current page. // Since we have a latch on the cur // RESOLVE RLL (mikem) - NO RECORD_ID PROTECTION IN EFFECT. // caller must research, get new locks if this routine // releases latches. ret_status = this.searchLeftAndLockPreviousKey( (B2I) btree, current_leaf, current_slot, lock_fetch_desc, lock_template, lock_row_loc, open_btree, lock_operation, lock_duration); } } return(ret_status); } /** * Lock the in memory row. * <p> * See BTree.lockRow() for more info. * * @exception StandardException Standard exception policy. **/ public boolean lockNonScanRow( BTree btree, LeafControlRow current_leaf, LeafControlRow aux_leaf, DataValueDescriptor[] current_row, int lock_operation) throws StandardException { if (SanityManager.DEBUG) { SanityManager.ASSERT(btree instanceof B2I); } B2I b2i = (B2I) btree; // First try to get the lock NOWAIT, while latch is held. boolean ret_status = base_cc.lockRow( (RowLocation) current_row[b2i.rowLocationColumn], lock_operation, false /* NOWAIT */, TransactionManager.LOCK_COMMIT_DURATION); if (!ret_status) { // Could not get the lock NOWAIT, release latch and wait for lock. if (current_leaf != null) { current_leaf.release(); current_leaf = null; } if (aux_leaf != null) { aux_leaf.release(); aux_leaf = null; } base_cc.lockRow( (RowLocation) current_row[b2i.rowLocationColumn], lock_operation, true /* WAIT */, TransactionManager.LOCK_COMMIT_DURATION); } return(ret_status); } 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 { return( lockRowOnPage( btree, current_leaf, null, current_slot, false, lock_fetch_desc, lock_template, lock_row_loc, lock_operation, TransactionManager.LOCK_COMMIT_DURATION)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -