001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.btree.index.B2IRowLocking1
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.access.btree.index;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025:
026: import org.apache.derby.iapi.error.StandardException;
027:
028: import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
029:
030: import org.apache.derby.iapi.store.access.ConglomerateController;
031: import org.apache.derby.iapi.types.RowLocation;
032: import org.apache.derby.iapi.store.access.TransactionController;
033:
034: import org.apache.derby.iapi.store.raw.FetchDescriptor;
035: import org.apache.derby.iapi.store.raw.LockingPolicy;
036: import org.apache.derby.iapi.store.raw.Page;
037: import org.apache.derby.iapi.store.raw.RecordHandle;
038: import org.apache.derby.iapi.store.raw.Transaction;
039:
040: import org.apache.derby.iapi.types.DataValueDescriptor;
041:
042: import org.apache.derby.impl.store.access.btree.BTree;
043: import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;
044: import org.apache.derby.impl.store.access.btree.BTreeRowPosition;
045: import org.apache.derby.impl.store.access.btree.ControlRow;
046: import org.apache.derby.impl.store.access.btree.LeafControlRow;
047: import org.apache.derby.impl.store.access.btree.OpenBTree;
048: import org.apache.derby.impl.store.access.btree.WaitError;
049:
050: /**
051:
052: The btree locking policy which implements read uncommitted isolation level.
053:
054: It inherits all functionality from B2IRowLocking2 except that it does not
055: get any read row locks (and thus does not release them). Note that table
056: level and table level intent locking remains the same as B2IRowLocking2 as
057: this is currently the way we prevent concurrent ddl from happening while a
058: read uncommitted scanner is operating in the btree.
059:
060: **/
061:
062: class B2IRowLocking1 extends B2IRowLocking2 implements
063: BTreeLockingPolicy {
064: /**************************************************************************
065: * Fields of the class
066: **************************************************************************
067: */
068:
069: /**************************************************************************
070: * Constructors for This class:
071: **************************************************************************
072: */
073: B2IRowLocking1(Transaction rawtran, int lock_level,
074: LockingPolicy locking_policy,
075: ConglomerateController base_cc, OpenBTree open_btree) {
076: super (rawtran, lock_level, locking_policy, base_cc, open_btree);
077: }
078:
079: /**************************************************************************
080: * Public Methods of This class:
081: **************************************************************************
082: */
083:
084: /**************************************************************************
085: * Abstract Protected lockScan*() locking methods of BTree:
086: * lockScan - lock the scan page
087: * (inherit from B2IRowLocking2, we still
088: * get page control locks).
089: * lockScanForReclaimSpace - lock page for reclaiming deleted rows.
090: * (inherit from B2IRowLocking2, should never
091: * be called while in read uncommitted).
092: * lockScanRow - lock row and possibly the scan page, only
093: * if row is forUpdate and not a previous key
094: * lock.
095: * unlockScan - unlock the scan page
096: * (inherit from B2IRowLocking2, should never
097: * be called while in read uncommitted).
098: * unlockScanRecordAfterRead- unlock the scan record if we locked it in
099: * lockScanRow.
100: *
101: **************************************************************************
102: */
103:
104: /**
105: * Lock a row as part of doing the scan.
106: * <p>
107: * Lock the row at the given slot (or the previous row if slot is 0).
108: * Get the scan lock on the page if "request_scan_lock" is true.
109: * <p>
110: * If this routine returns true all locks were acquired while maintaining
111: * the latch on leaf. If this routine returns false, locks may or may
112: * not have been acquired, and the routine should be called again after
113: * the client has researched the tree to reget the latch on the
114: * appropriate page.
115: * (p>
116: * As a side effect stores the value of the record handle of the current
117: * scan lock.
118: *
119: * @return Whether locks were acquired without releasing latch on leaf.
120: *
121: * @param open_btree The open_btree to associate latches with -
122: * used if routine has to scan backward.
123: * @param btree the conglomerate info.
124: * @param pos The position of the row to lock.
125: * @param request_scan_lock Whether to request the page scan lock, should
126: * only be requested once per page in the scan.
127: * @param lock_template A scratch area to use to read in rows.
128: * @param previous_key_lock Is this a previous key lock call?
129: * @param forUpdate Is the scan for update or for read only.
130: *
131: * @exception StandardException Standard exception policy.
132: **/
133: public boolean lockScanRow(OpenBTree open_btree, BTree btree,
134: BTreeRowPosition pos, boolean request_scan_lock,
135: FetchDescriptor lock_fetch_desc,
136: DataValueDescriptor[] lock_template,
137: RowLocation lock_row_loc, boolean previous_key_lock,
138: boolean forUpdate, int lock_operation)
139: throws StandardException {
140: // request the scan lock if necessary.
141: // only get the row lock if it is not a previous key lock and iff
142: // it is an update lock.
143: return (_lockScanRow(open_btree,
144: btree,
145: pos,
146: (forUpdate && !previous_key_lock), // only get update row lock
147: request_scan_lock, lock_fetch_desc, lock_template,
148: lock_row_loc, previous_key_lock, forUpdate,
149: lock_operation));
150: }
151:
152: /**
153: * Release read lock on a row.
154: *
155: * Because this is read uncommitted no S row locks will have been requested,
156: * thus none need be released. The only locks that need to be released
157: * are U locks requested if the scan was opened for update.
158: *
159: * @param pos The position of the row to unlock.
160: * @param forUpdate Is the scan for update or for read only.
161: *
162: **/
163: public void unlockScanRecordAfterRead(BTreeRowPosition pos,
164: boolean forUpdate) throws StandardException {
165: if (forUpdate) {
166: super .unlockScanRecordAfterRead(pos, forUpdate);
167: }
168: }
169:
170: /**************************************************************************
171: * Abstract Protected lockNonScan*() locking methods of BTree:
172: *
173: * lockNonScanPreviousRow - lock the row previous to the current
174: * (inherit from B2IRowLocking2, we still
175: * get page control locks) - only called
176: * by insert.
177: * lockNonScanRow - lock the input row
178: * (inherit from B2IRowLocking2, we still
179: * get page control locks) - only called
180: * by insert.
181: **************************************************************************
182: */
183:
184: }
|