MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / findLeafPage

Method findLeafPage

src/java/simpledb/index/BTreeFile.java:192–227  ·  view source on GitHub ↗

Recursive function which finds and locks the leaf page in the B+ tree corresponding to the left-most page possibly containing the key field f. It locks all internal nodes along the path to the leaf node with READ_ONLY permission, and locks the leaf node with permission perm. If f is null, it finds

(TransactionId tid, Map<PageId, Page> dirtypages, BTreePageId pid, Permissions perm,
                                       Field f)

Source from the content-addressed store, hash-verified

190 *
191 */
192 private BTreeLeafPage findLeafPage(TransactionId tid, Map<PageId, Page> dirtypages, BTreePageId pid, Permissions perm,
193 Field f)
194 throws DbException, TransactionAbortedException {
195 // some code goes here
196 //1. 如果是叶子节点,直接返回
197 if(pid.pgcateg() == BTreePageId.LEAF){
198 return (BTreeLeafPage) getPage(tid,dirtypages,pid,perm);
199 }
200 BTreeInternalPage page = (BTreeInternalPage) getPage(tid,dirtypages,pid,perm);
201 Iterator<BTreeEntry> iterator = page.iterator();
202 //2. 如果filed为空,找到最左边的节点
203 if(f==null){
204 if(iterator.hasNext()){
205 return findLeafPage(tid,dirtypages,iterator.next().getLeftChild(),perm,f);
206 }
207 return null;
208 }
209
210 BTreeEntry next = null;
211 //3. 否则,内部节点查找符合条件的entry,并递归查找
212 while(iterator.hasNext()){
213 next = iterator.next();
214 Field key = next.getKey();
215 //当有重复值的时候 节点分裂有可能一半在左边一半在右边,所以是小于等于
216 if(f.compare(Op.LESS_THAN_OR_EQ,key)){
217 return findLeafPage(tid,dirtypages,next.getLeftChild(),perm,f);
218 }
219 }
220
221 //最后一个entry的右子节点
222 if(next!=null){
223 return findLeafPage(tid,dirtypages,next.getRightChild(),perm,f);
224 }
225
226 return null;
227 }
228
229 /**
230 * Convenience method to find a leaf page when there is no dirtypages HashMap.

Callers 3

insertTupleMethod · 0.95
openMethod · 0.80
openMethod · 0.80

Calls 9

getPageMethod · 0.95
iteratorMethod · 0.95
getLeftChildMethod · 0.95
getKeyMethod · 0.95
getRightChildMethod · 0.95
pgcategMethod · 0.80
hasNextMethod · 0.65
nextMethod · 0.65
compareMethod · 0.65

Tested by

no test coverage detected