Method to encapsulate the process of deleting an entry (specifically the key and right child) from a parent node. If the parent becomes empty (no keys remaining), that indicates that it was the root node and should be replaced by its one remaining child. Otherwise, if it gets below minimum occupan
(TransactionId tid, Map<PageId, Page> dirtypages, BTreePage leftPage, BTreeInternalPage parent, BTreeEntry parentEntry)
| 1009 | * @throws TransactionAbortedException |
| 1010 | */ |
| 1011 | private void deleteParentEntry(TransactionId tid, Map<PageId, Page> dirtypages, |
| 1012 | BTreePage leftPage, BTreeInternalPage parent, BTreeEntry parentEntry) |
| 1013 | throws DbException, IOException, TransactionAbortedException { |
| 1014 | |
| 1015 | // delete the entry in the parent. If |
| 1016 | // the parent is below minimum occupancy, get some tuples from its siblings |
| 1017 | // or merge with one of the siblings |
| 1018 | parent.deleteKeyAndRightChild(parentEntry); |
| 1019 | int maxEmptySlots = parent.getMaxEntries() - parent.getMaxEntries()/2; // ceiling |
| 1020 | if(parent.getNumEmptySlots() == parent.getMaxEntries()) { |
| 1021 | // This was the last entry in the parent. |
| 1022 | // In this case, the parent (root node) should be deleted, and the merged |
| 1023 | // page will become the new root |
| 1024 | BTreePageId rootPtrId = parent.getParentId(); |
| 1025 | if(rootPtrId.pgcateg() != BTreePageId.ROOT_PTR) { |
| 1026 | throw new DbException("attempting to delete a non-root node"); |
| 1027 | } |
| 1028 | BTreeRootPtrPage rootPtr = (BTreeRootPtrPage) getPage(tid, dirtypages, rootPtrId, Permissions.READ_WRITE); |
| 1029 | leftPage.setParentId(rootPtrId); |
| 1030 | rootPtr.setRootId(leftPage.getId()); |
| 1031 | |
| 1032 | // release the parent page for reuse |
| 1033 | setEmptyPage(tid, dirtypages, parent.getId().getPageNumber()); |
| 1034 | } |
| 1035 | else if(parent.getNumEmptySlots() > maxEmptySlots) { |
| 1036 | handleMinOccupancyPage(tid, dirtypages, parent); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | /** |
| 1041 | * Delete a tuple from this BTreeFile. |
no test coverage detected