📄 t_recovery.java
字号:
t_util.t_commit(t); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); T_RawStoreRow row1 = new T_RawStoreRow(REC_001); T_RawStoreRow row2 = new T_RawStoreRow(REC_002); T_RawStoreRow row3 = new T_RawStoreRow(REC_003); T_RawStoreRow row4 = new T_RawStoreRow(REC_004); T_RawStoreRow row5 = new T_RawStoreRow(REC_005); RecordHandle r1 = t_util.t_insertAtSlot(page, 0, row1); RecordHandle r2 = t_util.t_insertAtSlot(page, 1, row2); RecordHandle r3 = (r2 == null) ? r2 : t_util.t_insertAtSlot(page, 2, row3); RecordHandle r4 = (r3 == null) ? r3 : t_util.t_insertAtSlot(page, 3, row4); RecordHandle r5 = (r4 == null) ? r4 : t_util.t_insertAtSlot(page, 4, row5); REPORT("setup S002: containerId " + cid + " recordCount " + page.recordCount()); register(key(2, 1), cid); register(key(2, 2), page.recordCount()); page.unlatch(); c.close(); } finally { t_util.t_commit(t); t.close(); } } /* recover test 2 */ protected void R002() throws T_Fail, StandardException { long cid = find(key(2,1)); if (cid < 0) { REPORT("R002 not run"); return; } int recordCount = (int)find(key(2,2)); Transaction t = t_util.t_startTransaction(); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, false); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); t_util.t_checkRecordCount(page, recordCount, recordCount); switch(recordCount) { case 5: t_util.t_checkFetchBySlot(page, 4, REC_005, false, false); case 4: t_util.t_checkFetchBySlot(page, 3, REC_004, false, false); case 3: t_util.t_checkFetchBySlot(page, 2, REC_003, false, false); case 2: t_util.t_checkFetchBySlot(page, 1, REC_002, false, false); case 1: t_util.t_checkFetchBySlot(page, 0, REC_001, false, false); } page.unlatch(); } finally { t_util.t_commit(t); t.close(); } PASS("R002: containerId " + cid + " recordCount " + recordCount); } /* * test 3 - update row */ protected void S003() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); try { long cid = t_util.t_addContainer(t, 0); t_util.t_commit(t); ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); T_RawStoreRow row1 = new T_RawStoreRow(REC_001); RecordHandle r1 = t_util.t_insertAtSlot(page, 0, row1); t_util.t_checkFetch(page, r1, row1); // REPORT("grows the #column in row"); T_RawStoreRow upd1 = new T_RawStoreRow(3); upd1.setColumn(0, (String) null); upd1.setColumn(1, REC_003); upd1.setColumn(2, REC_004); r1 = page.updateAtSlot(0, upd1.getRow(), (FormatableBitSet) null); // REPORT("update that shrinks the #columns in row"); T_RawStoreRow row2 = new T_RawStoreRow(3); row2.setColumn(0, REC_001); row2.setColumn(1, REC_002); row2.setColumn(2, REC_003); T_RawStoreRow upd2 = new T_RawStoreRow(REC_005); RecordHandle r2 = t_util.t_insertAtSlot(page, 1, row2); if (r2 != null) { r2 = page.updateAtSlot(1, upd2.getRow(), (FormatableBitSet) null); } t_util.t_checkFetch(page, r1, upd1); // first row should contain (null, REC_003, REC_004) DataValueDescriptor column = new SQLChar(); // page, slot, field, column, forUpdate, data t_util.t_checkFetchColFromSlot(page, 0, 0, column, true, null); t_util.t_checkFetchColFromSlot(page, 0, 1, column, true, REC_003); t_util.t_checkFetchColFromSlot(page, 0, 2, column, true, REC_004); if (r2 != null) { t_util.t_checkFetch(page, r2, upd2); // second row should contain (REC_005) t_util.t_checkFetchColFromSlot(page, 1, 0, column, true, REC_005); } REPORT("setup S003: containerId " + cid + " recordCount " + page.recordCount()); register(key(3, 1), cid); register(key(3, 2), page.recordCount()); page.unlatch(); } finally { t_util.t_commit(t); t.close(); } } /* * recover test 3 */ protected void R003() throws T_Fail, StandardException { long cid = find(key(3,1)); if (cid < 0) { REPORT("R003 not run"); return; } int recordCount = (int)find(key(3,2)); Transaction t = t_util.t_startTransaction(); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, false); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); t_util.t_checkRecordCount(page, recordCount, recordCount); // first row should contain (null, REC_003, REC_004) t_util.t_checkFieldCount(page, 0, 3); DataValueDescriptor column = new SQLChar(); t_util.t_checkFetchColFromSlot(page, 0, 0, column, false, null); t_util.t_checkFetchColFromSlot(page, 0, 1, column, false, REC_003); t_util.t_checkFetchColFromSlot(page, 0, 2, column, false, REC_004); if (recordCount == 2) { // second row should contain (REC_005) t_util.t_checkFieldCount(page, 1, 1); t_util.t_checkFetchColFromSlot(page, 1, 0, column, false, REC_005); } page.unlatch(); } finally { t_util.t_commit(t); t.close(); } PASS("R003: containerId " + cid + " recordCount " + recordCount); } /* * test 4 - update field */ protected void S004() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); try { long cid = t_util.t_addContainer(t, 0); t_util.t_commit(t); ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); T_RawStoreRow row = new T_RawStoreRow(5); row.setColumn(0, (String) null); row.setColumn(1, REC_004); row.setColumn(2, (String) null); row.setColumn(3, REC_005); row.setColumn(4, REC_005); RecordHandle rh = t_util.t_insert(page, row); DataValueDescriptor col0 = new SQLChar(null); DataValueDescriptor col1 = new SQLChar(REC_001); DataValueDescriptor col2 = new SQLChar(REC_002); DataValueDescriptor col3 = new SQLChar(null); if (page.updateFieldAtSlot(page.FIRST_SLOT_NUMBER, 0, col0, null) == null || page.updateFieldAtSlot(page.FIRST_SLOT_NUMBER, 1, col1, null) == null || page.updateFieldAtSlot(page.FIRST_SLOT_NUMBER, 2, col2, null) == null || page.updateFieldAtSlot(page.FIRST_SLOT_NUMBER, 3, col3, null) == null) { throw T_Fail.testFailMsg("Failed to update field"); } page.unlatch(); REPORT("setup S004: containerId " + cid); register(key(4,1), cid); } finally { t_util.t_commit(t); t.close(); } } /* recover test 4 */ protected void R004() throws T_Fail,StandardException { long cid = find(key(4,1)); if (cid < 0) { REPORT("R004 not run"); return; } Transaction t = t_util.t_startTransaction(); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, false); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); // first row should contain (null, REC_001, REC_002, null, REC_005) DataValueDescriptor column = new SQLChar(); t_util.t_checkFetchColFromSlot(page, 0, 0, column, false, null); t_util.t_checkFetchColFromSlot(page, 0, 1, column, false, REC_001); t_util.t_checkFetchColFromSlot(page, 0, 2, column, false, REC_002); t_util.t_checkFetchColFromSlot(page, 0, 3, column, false, null); t_util.t_checkFetchColFromSlot(page, 0, 4, column, false, REC_005); page.unlatch(); } finally { t_util.t_commit(t); t.close(); } PASS("R004: containerId " + cid ); } /* * test 5 - purge and delete */ protected void S005() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); try { long cid = t_util.t_addContainer(t, 0); t_util.t_commit(t); ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); T_RawStoreRow row1 = new T_RawStoreRow(REC_001); T_RawStoreRow row2 = new T_RawStoreRow(REC_002); T_RawStoreRow row3 = new T_RawStoreRow(REC_003); T_RawStoreRow row4 = new T_RawStoreRow(REC_004); T_RawStoreRow row5 = new T_RawStoreRow(REC_005); long numPurged = 0; // row 0 RecordHandle r1 = t_util.t_insertAtSlot(page, 0, row1); // purge slot 0 page.purgeAtSlot(0, 1, true); numPurged++; // slot 0 RecordHandle r2 = t_util.t_insertAtSlot(page, 0, row2); if (r2 != null) { page.delete(r2, (LogicalUndo)null); } // slot 1 RecordHandle r3 = (r2 == null) ? r2 : t_util.t_insertAtSlot(page, 1, row3); if (r3 != null) { page.delete(r3, (LogicalUndo)null); } // slot 2 RecordHandle r4 = (r3 == null) ? r3 : t_util.t_insertAtSlot(page, 2, row4); // slot 3 RecordHandle r5 = (r4 == null) ? r4 : t_util.t_insertAtSlot(page, 3, row5); if (r5 != null) { // purge slot 1 and 2 page.purgeAtSlot(1, 2, true); numPurged += 2; } REPORT("setup S005: containerId " + cid + " recordCount " + page.recordCount() + " numPurges " + numPurged); register(key(5,1), cid); register(key(5,2), page.recordCount()); register(key(5,3), numPurged); page.unlatch(); } finally { t_util.t_commit(t); t.close(); } } /* recover test 5 */ protected void R005() throws T_Fail, StandardException { long cid = find(key(5,1)); if (cid < 0) { REPORT("R005 not run"); return; } int recordCount = (int)find(key(5,2)); int numPurged = (int)find(key(5,3)); Transaction t = t_util.t_startTransaction(); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, false); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); t_util.t_checkRecordCount(page, recordCount, 1); T_RawStoreRow row1 = new T_RawStoreRow(REC_001); T_RawStoreRow row2 = new T_RawStoreRow(REC_002); T_RawStoreRow row3 = new T_RawStoreRow(REC_003); T_RawStoreRow row4 = new T_RawStoreRow(REC_004); T_RawStoreRow row5 = new T_RawStoreRow(REC_005); if (numPurged == 1) { // REC_002 (deleted), REC_003 (deleted), REC_004 switch(recordCount) { case 3: t_util.t_checkFetchBySlot(page, 2, REC_004, false, false); case 2: t_util.t_checkFetchBySlot(page, 1, REC_003, true, false); case 1: t_util.t_checkFetchBySlot(page, 0, REC_002, true, false); } } else { // REC_002 (deleted), REC_005 switch(recordCount) { case 2: t_util.t_checkFetchBySlot(page, 1, REC_005, false, false); case 1: t_util.t_checkFetchBySlot(page, 0, REC_002, true, false); if (!page.isDeletedAtSlot(0)) throw T_Fail.testFailMsg("record should be deleted"); } } page.unlatch(); } finally { t_util.t_commit(t); t.close(); } PASS("R005: containerId " + cid + " recordCount " + recordCount + " numPurges " + numPurged); } /* * test 6 - page allocation */ protected void S006() 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_RawStoreRow row1 = new T_RawStoreRow(REC_001); T_RawStoreRow row2 = new T_RawStoreRow(REC_002); T_RawStoreRow row3 = new T_RawStoreRow(REC_003); ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); t_util.t_insertAtSlot(page, 0, row1); long page1_Id = page.getPageNumber(); page.unlatch(); page = t_util.t_addPage(c); t_util.t_insertAtSlot(page, 0, row2); long page2_Id = page.getPageNumber(); page.unlatch(); page = t_util.t_addPage(c); t_util.t_insertAtSlot(page, 0, row3); long page3_Id = page.getPageNumber(); page.unlatch(); if (page1_Id == page2_Id || page1_Id == page3_Id || page2_Id == page3_Id) throw T_Fail.testFailMsg("not getting new pages"); REPORT("setup S006: containerId " + cid); register(key(6,1), cid); register(key(6,2), page1_Id); register(key(6,3), page2_Id); register(key(6,4), page3_Id); } finally { t_util.t_commit(t); t.close(); } } /* recover test 6 */ protected void R006() throws T_Fail, StandardException { long cid = find(key(6,1)); if (cid < 0) { REPORT("R006 not run"); return; } long page1_Id = find(key(6,2)); long page2_Id = find(key(6,3)); long page3_Id = find(key(6,4)); Transaction t = t_util.t_startTransaction(); try { ContainerHandle c = t_util.t_openContainer(t, 0, cid, false); if (page1_Id != c.FIRST_PAGE_NUMBER) throw T_Fail.testFailMsg("first page != container first page"); Page page = t_util.t_getPage(c, page1_Id); t_util.t_checkRecordCount(page, 1, 1); t_util.t_checkFetchBySlot(page, 0, REC_001, false, false); page.unlatch(); page = t_util.t_getPage(c, page2_Id); t_util.t_checkRecordCount(page, 1, 1); t_util.t_checkFetchBySlot(page, 0, REC_002, false, false); page.unlatch();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -