📄 t_recovery.java
字号:
try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); Page p; p = c.getPage(pnum[0]); if (p.recordCount() == 0) // it has no overflow rows in it { p.unlatch(); throw T_Fail.testFailMsg("first page failed to get any overflow records"); } p.unlatch(); p = c.getPage(pnum[1]); if (p.recordCount() == 0) // it has no overflow rows in it { p.unlatch(); throw T_Fail.testFailMsg("second page failed to get any overflow records"); } p.unlatch(); p = c.getPage(pnum[numpages-1]); if (p.recordCount() == 0) // it has no overflow rows in it { p.unlatch(); throw T_Fail.testFailMsg("last page failed to get any overflow records"); } p.unlatch(); // all other pages have one huge row at the beginning p = c.getFirstPage(); if (p.getPageNumber() != pnum[2]) throw T_Fail.testFailMsg("first page expected to be page " + pnum[2] + ", got " + p.getPageNumber() + " instead"); long pageNum = p.getPageNumber(); t_util.t_checkStringLengthFetch(p, 0, 1500); p.unlatch(); int i = 3; while((p = c.getNextPage(pageNum)) != null) { pageNum = p.getPageNumber(); if (pageNum != pnum[i]) throw T_Fail.testFailMsg("expect page " + pnum[i] + " get page " + pageNum); t_util.t_checkStringLengthFetch(p, 0, 1500); p.unlatch(); i++; } if (i != numpages-1) throw T_Fail.testFailMsg("expect last head page to be " + (numpages-2) + " got " + i + " page instead"); } finally { t_util.t_commit(t); t.close(); } PASS("R010"); } /* * test 11 - allocate a lot of pages so that we need > 1 allocation pages */ protected void S011() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); int iterations = 10000; try { long cid = t_util.t_addContainer(t, 0, 4096); t_util.t_commit(t); T_RawStoreRow row = new T_RawStoreRow(REC_001); ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); // allocate iterations pages, this ought to bring the number of pages // over what 1 allocation page can handle Page p = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); t_util.t_insert(p, row); p.unlatch(); long pnum = ContainerHandle.FIRST_PAGE_NUMBER; long lastPageNum = ContainerHandle.INVALID_PAGE_NUMBER; for (int i = 1; i <= iterations; i++) { p = t_util.t_addPage(c); if (p.getPageNumber() != pnum+1) REPORT("S011: skipping " + (pnum+1) + " going to " + p.getPageNumber()); pnum = p.getPageNumber(); t_util.t_insert(p, row); if (i == iterations) { lastPageNum = p.getPageNumber(); REPORT("S011: Last page number is " + lastPageNum); } p.unlatch(); } t_util.t_commit(t); // now scan the pages c = t_util.t_openContainer(t, 0, cid, true); p = c.getFirstPage(); if (p == null || p.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER) throw T_Fail.testFailMsg("first page not where it is expected"); p.unlatch(); p = t_util.t_getLastPage(c); if (p == null || p.getPageNumber() != lastPageNum) throw T_Fail.testFailMsg("last page not where it is expected"); p.unlatch(); register(key(11, 1), cid); register(key(11, 2), lastPageNum); register(key(11, 3), iterations); REPORT("setup S011, container id = " + cid); } finally { t_util.t_commit(t); t.close(); } } protected void R011() throws T_Fail, StandardException { long cid = find(key(11,1)); if (cid < 0) { REPORT("R011 not run"); return; } else REPORT("R011 container id = " + cid); long expectedLastPageNum = find(key(11,2)); int iterations = (int)find(key(11,3)); Transaction t = t_util.t_startTransaction(); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, false); Page p = c.getFirstPage(); if (p == null || p.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER) throw T_Fail.testFailMsg("first page not where it is expected"); p.unlatch(); long pageNum = ContainerHandle.FIRST_PAGE_NUMBER; long pnum = pageNum; int pcount = 1; while((p = c.getNextPage(pageNum)) != null) { t_util.t_checkFetchFirst(p, REC_001); pageNum = p.getPageNumber(); if (pageNum != pnum+1) REPORT("R011: skipping " + (pnum+1) + " going to " + pageNum); pnum = pageNum; pcount++; p.unlatch(); } if (pcount != (iterations+1)) { throw T_Fail.testFailMsg( "expect to see " + (iterations+1) + " pages, got: " + pcount + " last page number is " + pageNum); } p = t_util.t_getLastPage(c); if (p.getPageNumber() != expectedLastPageNum) { throw T_Fail.testFailMsg( "expect last page num to be " + expectedLastPageNum + " , instead got " + p.getPageNumber()); } REPORT("Last page pagenumber is " + p.getPageNumber() + ", it is the last page of " + (iterations+1) + " user pages"); p.unlatch(); PASS("R011"); } finally { t_util.t_commit(t); t.close(); } } /* * test 12 - test estimated page count */ protected void S012() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); long cid = t_util.t_addContainer(t, 0, 4096); t_util.t_commit(t); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); if (c.getEstimatedPageCount(0) != 1) throw T_Fail.testFailMsg("Expect 2 user page, got " + c.getEstimatedPageCount(0)); // allocate 30 pages Page p = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); T_RawStoreRow row = new T_RawStoreRow(REC_001); t_util.t_insert(p, row); p.unlatch(); for (int i = 2; i <= 30; i++) { p = t_util.t_addPage(c); t_util.t_insert(p, row); p.unlatch(); } register(key(12, 1), cid); REPORT("Setup S012"); } finally { t_util.t_commit(t); t.close(); } } protected void R012() throws T_Fail, StandardException { long cid = find(key(12,1)); if (cid < 0) { REPORT("R012 not run"); return; } Transaction t = t_util.t_startTransaction(); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, false); if (c.getEstimatedPageCount(0) != 30) throw T_Fail.testFailMsg("expect 30 pages, got " + c.getEstimatedPageCount(0)); PASS("R012"); } finally { t_util.t_commit(t); t.close(); } } /* * test 20 - create multiple containers */ protected void S020() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); T_RawStoreRow row1 = new T_RawStoreRow(REC_001); T_RawStoreRow row2 = new T_RawStoreRow(REC_002); T_RawStoreRow row3 = new T_RawStoreRow(REC_003); try { long cid1 = t_util.t_addContainer(t, 0); ContainerHandle c1 = t_util.t_openContainer(t, 0, cid1, true); Page page = t_util.t_getPage(c1, ContainerHandle.FIRST_PAGE_NUMBER); t_util.t_insertAtSlot(page, 0, row1); page.unlatch(); long cid2 = t_util.t_addContainer(t, 0); ContainerHandle c2 = t_util.t_openContainer(t, 0, cid2, true); long cid3 = t_util.t_addContainer(t, 0); ContainerHandle c3 = t_util.t_openContainer(t, 0, cid3, true); page = t_util.t_getPage(c2, ContainerHandle.FIRST_PAGE_NUMBER); // blank first page page.unlatch(); page = t_util.t_addPage(c2); t_util.t_insertAtSlot(page, 0, row2); long pageId = page.getPageNumber(); page.unlatch(); page = t_util.t_getPage(c3, ContainerHandle.FIRST_PAGE_NUMBER); t_util.t_insertAtSlot(page, 0, row3); page.unlatch(); REPORT("setup S020: container1 " + cid1 + " container2 " + cid2 + " container3 " + cid3 + " page " + pageId); register(key(20, 1), cid1); register(key(20, 2), cid2); register(key(20, 3), cid3); register(key(20, 4), pageId); } finally { t_util.t_commit(t); t.close(); } } /* recover test 20 */ protected void R020() throws T_Fail, StandardException { long cid1 = find(key(20, 1)); if (cid1 < 0) { REPORT("R020 not run"); return; } long cid2 = find(key(20,2)); long cid3 = find(key(20,3)); long pageId = find(key(20,4)); Transaction t = t_util.t_startTransaction(); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid1, false); Page page = t_util.t_getPage(c, c.FIRST_PAGE_NUMBER); t_util.t_checkRecordCount(page, 1, 1); t_util.t_checkFetchBySlot(page, 0, REC_001, false, false); page.unlatch(); c = t_util.t_openContainer(t, 0, cid2, false); page = t_util.t_getPage(c, c.FIRST_PAGE_NUMBER); t_util.t_checkEmptyPage(page); page.unlatch(); page = t_util.t_getPage(c, pageId); t_util.t_checkRecordCount(page, 1, 1); t_util.t_checkFetchBySlot(page, 0, REC_002, false, false); page.unlatch(); c = t_util.t_openContainer(t, 0, cid3, false); page = t_util.t_getPage(c, c.FIRST_PAGE_NUMBER); t_util.t_checkRecordCount(page, 1, 1); t_util.t_checkFetchBySlot(page, 0, REC_003, false, false); page.unlatch(); } finally { t_util.t_commit(t); t.close(); } PASS("R020 container1 " + cid1 + " container2 " + cid2 + " container3 " + cid3 + " page " + pageId); } /* * test 022 - drop containers */ protected void S022() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); try { long cid = t_util.t_addContainer(t, 0); t_util.t_commit(t); t_util.t_openContainer(t, 0, cid, true); t_util.t_dropContainer(t, 0, cid); t_util.t_abort(t); // this should rollback the drop t_util.t_openContainer(t, 0, cid, true); REPORT("rollback of drop container tested"); t.dropContainer(new ContainerKey(0, cid)); t.commit(); REPORT("setup S022: containerId " + cid); register(key(22, 1), cid); } finally { t_util.t_commit(t); t.close(); } } /* * recover test 022 - drop container */ protected void R022() throws T_Fail, StandardException { long cid = find(key(22, 1)); if (cid < 0) { REPORT("R022 not run"); return; } Transaction t = t_util.t_startTransaction(); try { ContainerKey id = new ContainerKey(0, cid); ContainerHandle c1 = t.openContainer(id, ContainerHandle.MODE_READONLY); // this should fail if (c1 != null) throw T_Fail.testFailMsg("dropped container should fail to open"); } finally { t_util.t_commit(t); t.close(); } PASS("R022 : containerId " + cid); } /* * test 100 - multiple intervening committed transactions */ protected void S100() throws T_Fail, StandardException { T_TWC t1 = t_util.t_startTransactionWithContext(); T_TWC t2 = t_util.t_startTransactionWithContext(); try { long cid10 = t_util.t_addContainer(t1,0); long cid11 = t_util.t_addContainer(t1,0); t_util.t_commit(t1); long cid20 = t_util.t_addContainer(t2, 0); long cid21 = t_util.t_addContainer(t2, 0); t_util.t_commit(t2); ContainerHandle c10 = t_util.t_openContainer(t1, 0, cid10, true); ContainerHandle c11 = t_util.t_openContainer(t1, 0, cid11, true); ContainerHandle c20 = t_util.t_openContainer(t2, 0, cid20, true); ContainerHandle c21 = t_util.t_openContainer(t2, 0, cid21, true); t1.switchTransactionContext(); Page p10 = t_util.t_getPage(c10, ContainerHandle.FIRST_PAGE_NUMBER); Page p11 = t_util.t_getPage(c11, ContainerHandle.FIRST_PAGE_NUMBER); t1.resetContext(); t2.switchTransactionContext(); Page p20 = t_util.t_getPage(c20, ContainerHandle.FIRST_PAGE_NUMBER); Page p21 = t_util.t_getPage(c21, ContainerHandle.FIRST_PAGE_NUMBER); // for each page, insert, update, updatefield, (some) delete T_RawStoreRow row1 = new T_RawStoreRow(3); row1.setColumn(0, REC_001); row1.setColumn(1, REC_002); row1.setColumn(2, (String) null); T_RawStoreRow row2 = new T_RawStoreRow(2); row2.setColumn(0, REC_003); row2.setColumn(1, REC_004); T_RawStoreRow rowP = new T_RawStoreRow(1); rowP.setColumn(0, REC_005); t2.resetContext(); t1.switchTransactionContext(); RecordHandle r10 = t_util.t_insertAtSlot(p10, 0, row1); RecordHandle r11 = t_util.t_insertAtSlot(p11, 0, row1); t1.resetContext(); t2.switchTransactionContext(); RecordHandle r20 = t_util.t_insertAtSlot(p20, 0, row1); RecordHandle r21 = t_util.t_insertAtSlot(p21, 0, row1); t2.resetContext(); t1.switchTransactionContext(); p10.update(r10, row2.getRow(), (FormatableBitSet) null); p11.update(r11, row2.getRow(), (FormatableBitSet) null); t1.resetContext(); t2.switchTransactionContext(); p20.update(r20, row2.getRow(), (FormatableBitSet) null); p21.update(r21, row2.getRow(), (FormatableBitSet) null); t2.resetContext(); t1.switchTransactionContext(); p10.update(r10, rowP.getRow(), BS_COL_0); p11.update(r11, rowP.getRow(), BS_COL_0); p10.unlatch(); p11.unlatch(); t1.resetContext(); t2.switchTransactionContext();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -