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

Method insertTuple

src/java/simpledb/storage/HeapFile.java:127–158  ·  view source on GitHub ↗
(TransactionId tid, Tuple t)

Source from the content-addressed store, hash-verified

125
126 // see DbFile.java for javadocs
127 public List<Page> insertTuple(TransactionId tid, Tuple t)
128 throws DbException, IOException, TransactionAbortedException {
129 // some code goes here
130 if (!getFile().canRead() || !getFile().canWrite()) {
131 throw new IOException();
132 }
133 List<Page> res = new ArrayList<>();
134 for(int i=0;i<numPages();i++){
135 HeapPageId heapPageId = new HeapPageId(getId(),i);
136 HeapPage heapPage = (HeapPage) Database.getBufferPool().getPage(tid,heapPageId,Permissions.READ_ONLY);
137 if(heapPage==null){
138 Database.getBufferPool().unsafeReleasePage(tid,heapPageId);
139 continue;
140 }
141 if(heapPage.getNumEmptySlots()==0){
142 Database.getBufferPool().unsafeReleasePage(tid,heapPageId);
143 continue;
144 }
145 heapPage.insertTuple(t);
146 heapPage.markDirty(true,tid);
147 res.add(heapPage);
148 return res;
149 }
150 //新建一个page
151 HeapPageId heapPageId = new HeapPageId(getId(), numPages());
152 HeapPage heapPage = new HeapPage(heapPageId, HeapPage.createEmptyPageData());
153 heapPage.insertTuple(t);
154 writePage(heapPage);
155 res.add(heapPage);
156 return res;
157 // not necessary for lab1
158 }
159
160 // see DbFile.java for javadocs
161 public ArrayList<Page> deleteTuple(TransactionId tid, Tuple t) throws DbException,

Callers

nothing calls this directly

Calls 11

getFileMethod · 0.95
numPagesMethod · 0.95
getIdMethod · 0.95
getBufferPoolMethod · 0.95
getNumEmptySlotsMethod · 0.95
insertTupleMethod · 0.95
markDirtyMethod · 0.95
createEmptyPageDataMethod · 0.95
writePageMethod · 0.95
unsafeReleasePageMethod · 0.80
getPageMethod · 0.45

Tested by

no test coverage detected