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

Method checkSubTree

src/java/simpledb/index/BTreeChecker.java:82–131  ·  view source on GitHub ↗
(BTreeFile bt, TransactionId tid, Map<PageId, Page> dirtypages,
                                       BTreePageId pageId, Field lowerBound, Field upperBound,
                                       BTreePageId parentId, boolean checkOccupancy, int depth)

Source from the content-addressed store, hash-verified

80 }
81
82 static SubtreeSummary checkSubTree(BTreeFile bt, TransactionId tid, Map<PageId, Page> dirtypages,
83 BTreePageId pageId, Field lowerBound, Field upperBound,
84 BTreePageId parentId, boolean checkOccupancy, int depth) throws
85 TransactionAbortedException, DbException {
86 BTreePage page = (BTreePage )bt.getPage(tid, dirtypages, pageId, Permissions.READ_ONLY);
87 assert(page.getParentId().equals(parentId));
88
89 if (page.getId().pgcateg() == BTreePageId.LEAF) {
90 BTreeLeafPage bpage = (BTreeLeafPage) page;
91 bpage.checkRep(bt.keyField(), lowerBound, upperBound, checkOccupancy, depth);
92 return new SubtreeSummary(bpage, depth);
93 } else if (page.getId().pgcateg() == BTreePageId.INTERNAL) {
94
95 BTreeInternalPage ipage = (BTreeInternalPage) page;
96 ipage.checkRep(lowerBound, upperBound, checkOccupancy, depth);
97
98 SubtreeSummary acc = null;
99 BTreeEntry prev = null;
100 Iterator<BTreeEntry> it = ipage.iterator();
101
102 prev = it.next();
103 { // init acc and prev.
104 acc = checkSubTree(bt, tid, dirtypages, prev.getLeftChild(), lowerBound, prev.getKey(), ipage.getId(),
105 checkOccupancy, depth + 1);
106 lowerBound = prev.getKey();
107 }
108
109 assert(acc != null);
110 BTreeEntry curr = prev; // for one entry case.
111 while (it.hasNext()) {
112 curr = it.next();
113 SubtreeSummary currentSubTreeResult =
114 checkSubTree(bt, tid, dirtypages, curr.getLeftChild(), lowerBound, curr.getKey(), ipage.getId(),
115 checkOccupancy, depth + 1);
116 acc = SubtreeSummary.checkAndMerge(acc, currentSubTreeResult);
117
118 // need to move stuff for next iter:
119 lowerBound = curr.getKey();
120 }
121
122 SubtreeSummary lastRight = checkSubTree(bt, tid, dirtypages, curr.getRightChild(), lowerBound, upperBound,
123 ipage.getId(), checkOccupancy, depth + 1);
124 acc = SubtreeSummary.checkAndMerge(acc, lastRight);
125
126 return acc;
127 } else {
128 assert(false); // no other page types allowed inside the tree.
129 return null;
130 }
131 }
132}

Callers 1

checkRepMethod · 0.95

Calls 15

getParentIdMethod · 0.95
getIdMethod · 0.95
checkRepMethod · 0.95
checkRepMethod · 0.95
iteratorMethod · 0.95
getLeftChildMethod · 0.95
getKeyMethod · 0.95
checkAndMergeMethod · 0.95
getRightChildMethod · 0.95
pgcategMethod · 0.80
keyFieldMethod · 0.80
equalsMethod · 0.65

Tested by

no test coverage detected