📄 t_rawstorefactory.java
字号:
} int count2 = page2.recordCount(); // now purge them all and start over page1.purgeAtSlot(1, page1.recordCount()-1, logDataForPurges); page2.purgeAtSlot(1, page2.recordCount()-1, logDataForPurges); if (page1.recordCount() != 1) throw T_Fail.testFailMsg("purge did not clean up page"); if (page2.recordCount() != 1) throw T_Fail.testFailMsg("purge did not clean up page"); i = 0; while(page1.spaceForInsert()) { if (t_util.t_insertAtSlot(page1, 1, row1) == null) return; i++; } if (page1.recordCount() != count1) throw T_Fail.testFailMsg("cannot insert back same number of rows we purged"); i = 1; while(page2.spaceForInsert()) { if (t_util.t_insertAtSlot(page2, i++, row1) == null) break; } if (page2.recordCount() != count2) throw T_Fail.testFailMsg("cannot insert back same number of rows we purged"); page1.unlatch(); page2.unlatch(); t_util.t_dropContainer(t, segment, cid); // cleanup t_util.t_commit(t); t.close(); PASS("P005"); } /* P006 test page time stamp - make sure all operation changes page time stamp */ protected void P006() throws StandardException, T_Fail { Transaction t = t_util.t_startTransaction(); PageTimeStamp ts; long cid = t_util.t_addContainer(t, 0); t_util.t_commit(t); ContainerHandle c = t_util.t_openContainer(t, 0, cid, true); Page page1 = t_util.t_getLastPage(c); ts = page1.currentTimeStamp(); if (ts != null && !page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("page returns non-null time stamp which is not equal to its current time stamp"); T_RawStoreRow row = new T_RawStoreRow(REC_001); RecordHandle rh = t_util.t_insert(page1, row); if (page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("timestamp on page not changed after insert operation"); page1.setTimeStamp(ts); if (ts != null && !page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("page returns non-null time stamp which is not equal to its current time stamp"); // failed update should not change time stamp t_util.t_updateSlotOutOfRange(page1, 3); if (ts != null && !page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("failed pdate should not change time stamp"); T_RawStoreRow row2 = new T_RawStoreRow(REC_002); page1.update(rh, row2.getRow(), (FormatableBitSet) null); if (page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("timestamp on page not changed after update operation"); page1.setTimeStamp(ts); T_RawStoreRow upd1 = new T_RawStoreRow(REC_003); page1.update(rh, upd1.getRow(), BS_COL_0); if (page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("timestamp on page not changed after update field operation"); page1.setTimeStamp(ts); page1.delete(rh, (LogicalUndo)null); if (page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("timestamp on page not changed after delete operation"); page1.setTimeStamp(ts); page1.purgeAtSlot(0, 1, logDataForPurges); if (page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("timestamp on page not changed after delete operation"); page1.setTimeStamp(ts); page1.unlatch(); if (testRollback) { t_util.t_abort(t); c = t_util.t_openContainer(t, 0, cid, true); page1 = t_util.t_getLastPage(c); if (page1.equalTimeStamp(ts)) throw T_Fail.testFailMsg("timestamp on page not changed after rollback"); page1.setTimeStamp(ts); } Page page2 = c.addPage(); Page page3 = c.addPage(); page2.setTimeStamp(ts); if (ts != null) { try { if (page3.equalTimeStamp(ts)) throw T_Fail.testFailMsg("timestamp on 2 different pages should not equate"); } catch (StandardException se) { // either throw an exception or return false is OK } } t_util.t_dropContainer(t, 0, cid); // cleanup t_util.t_commit(t); t.close(); PASS("P006"); } /** P007 this test exercises repeated updates on a 1K page 2 rows (with 1 column) will be inserted into the page. We expand the row data in slot 0 by 1 byte until the page is completely full, and overflows the record to an overflow page. @exception T_Fail Unexpected behaviour from the API @exception StandardException Unexpected exception from the implementation */ protected void P007(long segment) throws StandardException, T_Fail { Transaction t = t_util.t_startTransaction(); // PART 1: // insert two 1-column rows into the page, expand the first row, until it overflows. long cid = t_util.t_addContainer(t, segment, 4096, 0, 1, false); ContainerHandle c = t_util.t_openContainer(t, segment, cid, true); Page page = t_util.t_getLastPage(c); T_RawStoreRow row = new T_RawStoreRow(REC_001); // McLaren T_RawStoreRow row2 = new T_RawStoreRow(new String(new char[300])); RecordHandle r1 = t_util.t_insertAtSlot(page, 0, row); RecordHandle r2 = t_util.t_insertAtSlot(page, 1, row2); // update the row size 1 byte larger, until the page is full String rowData = REC_001; // 900 is an estimated number, because for 1K page, // if you expand your row by 1 byte 900 times, the row will overflow for sure. for (int i = 0; i <= 900; i++) { t_util.t_checkFetch(page, r1, rowData); rowData = rowData + REC_008; // "z" row = new T_RawStoreRow(rowData); page.updateAtSlot(0, row.getRow(), (FormatableBitSet) null); } t_util.t_dropContainer(t, segment, cid); // cleanup // PART 2: // insert two 2-column rows into the page, // expand the first row by expanding the first column by 300 bytes, // and shrinking the second column by 300 bytes. Update should secceed. cid = t_util.t_addContainer(t, segment, 4096, 0, 1, false); c = t_util.t_openContainer(t, segment, cid, true); page = t_util.t_getLastPage(c); long pid = page.getPageNumber(); row = new T_RawStoreRow(2); row.setColumn(0, REC_001); // small column row.setColumn(1, new String (new char[400])); // large column r1 = t_util.t_insertAtSlot(page, 0, row); r2 = t_util.t_insertAtSlot(page, 1, row2); row.setColumn(0, REC_001 + new String (new char[300])); row.setColumn(1, new String (new char[100])); page.updateAtSlot(0, row.getRow(), (FormatableBitSet) null); Page page2 = t_util.t_addPage(c); long pid2 = page2.getPageNumber(); if (pid2 != (pid + 1)) throw T_Fail.testFailMsg("The update should not have overflowed the record"); // Now, shrink the first column by 300 bytes, and expand the second column by 300 bytes. // the update should also succeed. row.setColumn(0, REC_001); row.setColumn(1, new String (new char[400])); page.updateAtSlot(0, row.getRow(), (FormatableBitSet) null); Page page3 = t_util.t_addPage(c); long pid3 = page3.getPageNumber(); if (pid3 != (pid2 + 1)) throw T_Fail.testFailMsg("The update should not have overflowed the record"); t_util.t_dropContainer(t, segment, cid); // cleanup t_util.t_commit(t); t.close(); PASS("P007"); } /** P008 this test exercises repeated inserts with small rows on a 1K page we will insert as many rows as possible into the page. Then we reduce the row by 1 byte at a time, we will try to insert another smaller row. This test also tests spaceForInsert(). @exception T_Fail Unexpected behaviour from the API @exception StandardException Unexpected exception from the implementation */ protected void P008(long segment) throws StandardException, T_Fail { Transaction t = t_util.t_startTransaction(); long cid = t_util.t_addContainer(t, segment, 4096, 0, 1, false); ContainerHandle c = t_util.t_openContainer(t, segment, cid, true); Page page1 = t_util.t_getLastPage(c); T_RawStoreRow row = new T_RawStoreRow(REC_001); // McLaren t_util.t_insertAtSlot(page1, 0, row); int i = 0; while (page1.spaceForInsert(row.getRow(), (FormatableBitSet) null, 100)) { // if it says there is enough room for this row, the insert should succeed. if (t_util.t_insertAtSlot(page1, 1, row) == null) throw T_Fail.testFailMsg("There is space for this insert. It shouldn't have failed. " + "record #" + i); i++; } REPORT(i + " rows inserted."); // We got out of the while loop because there is no room for the insert. // So, if the insert succeed, then we have a problem. if (t_util.t_insertAtSlot(page1, 1, row) != null) throw T_Fail.testFailMsg("There is no space for this insert. It should have failed."); // Now, we will try to fill the page with smaller rows. String[] s = new String[7]; s[6] = "McLare"; s[5] = "McLar"; s[4] = "McLa"; s[3] = "McL"; s[2] = "Mc"; s[1] = "M"; s[0] = null; // reduce the row by 1 byte i = 6; boolean notDone = true; do { row = new T_RawStoreRow(s[i]); if (page1.spaceForInsert(row.getRow(), (FormatableBitSet) null, 100)) { // If it says there is enough room for the row, then the insert should succed. if (t_util.t_insertAtSlot(page1, 1, row) == null) throw T_Fail.testFailMsg("There should be space for this insert, row is " + s[i]); else notDone = false; } else i--; } while ((notDone) && (i >= 0)); page1.unlatch(); t_util.t_dropContainer(t, segment, cid); // cleanup t_util.t_commit(t); t.close(); PASS("P008"); } /** P009 this test exercises repeated shrinking and expanding of fields using updateFieldBySlot we will insert as many rows as possible into the page. Then set some of the columns to null, That should not create more space on the page for inserts, because the extra space become reservedspace for the row. So, the next insert should fail. @exception T_Fail Unexpected behaviour from the API @exception StandardException Unexpected exception from the implementation */ protected void P009(long segment) throws StandardException, T_Fail { int slot = 0; int i = 0; int j = 0; String field = REC_001; Transaction t = t_util.t_startTransaction(); long cid = t_util.t_addContainer(t, segment); // Get the first page & check the record counts are zero ContainerHandle c = t_util.t_openContainer(t, segment, cid, true); Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER); t_util.t_checkEmptyPage(page); // Create a 13-column row T_RawStoreRow row = new T_RawStoreRow(13); row.setColumn(0, (String) null); row.setColumn(1, REC_001); row.setColumn(2, REC_002); row.setColumn(3, REC_003); row.setColumn(4, REC_004); row.setColumn(5, REC_005); row.setColumn(6, REC_006); row.setColumn(7, REC_007); row.setColumn(8, (String) null); row.setColumn(9, (String) null); row.setColumn(10, REC_007); row.setColumn(11, (String) null); row.setColumn(12, REC_006); // insert the row into the page until the page is full int numRows = 0; slot = page.FIRST_SLOT_NUMBER; while (page.spaceForInsert(row.getRow(), (FormatableBitSet) null, 100)) { t_util.t_insert(page, row); numRows++; } REPORT(numRows + " rows inserted "); // update all the fields in the even number rows to null // set all the fields in the odd number rows to REC_001 DataValueDescriptor col = new SQLChar(); // null for (i = page.FIRST_SLOT_NUMBER; i < (page.FIRST_SLOT_NUMBER + 2); i++) { for (slot = i; slot <= (numRows - 1); slot += 2) { for (j = 0; j <= 12; j++) { if (page.updateFieldAtSlot(slot, j, col, null) == null) { throw T_Fail.testFailMsg("Failed to update field " + j+ ", in row " + slot); } } } col = new SQLChar(REC_001); } // fetch all the fields, and see if they are correct DataValueDescriptor storedColumn = new SQLChar(); field = null; for (i = page.FIRST_SLOT_NUMBER; i < (page.FIRST_SLOT_NUMBER + 2); i++) { for (slot = i; slot <= (numRows - 1); slot += 2) { for (j = 0; j <= 12; j++) { t_util.t_checkFetchColFromSlot(page, slot, j, storedColumn, false, field); } } field = REC_001; } // Now if we try to insert the old row again, there should still be no room if (page.spaceForInsert()) throw T_Fail.testFailMsg("Did not get no room for record on page error"); // update the first and last field of every row to REC_006 col = new SQLChar(REC_006); for (slot = page.FIRST_SLOT_NUMBER; slot <= (numRows - 1); slot++) { if (page.updateFieldAtSlot(slot, 0, col, null) == null || page.updateFieldAtSlot(slot, 12, col, null) == null) { throw T_Fail.testFailMsg("Failed to update fields to REC_006 in row " + slot); } } // update field 5 and 6 of every row to REC_007 col = new SQLChar(REC_007); for (slot = page.FIRST_SLOT_NUMBER; slot <= (numRows - 1); slot++) { if (page.updateFieldAtSlot(slot, 5, col, null) == null || page.updateFieldAtSlot(slot, 6, col, null) == null) { throw T_Fail.testFailMsg("Failed to update fields to REC_007 in row " + slot); } } // fetch all the fields again, and see if they are correct for (i = page.FIRST_SLOT_NUMBER; i < (page.FIRST_SLOT_NUMBER + 2); i++) { for (slot = i; slot <= (numRows - 1); slot += 2) { for (j = 0; j <= 12; j++) { switch (j) { case 0: case 12: field = REC_006; break; case 5: case 6: field = REC_007; break; default: if ((slot % 2) == 0) field = null; else field = REC_001; break; } t_util.t_checkFetchColFromSlot(page, slot, j, storedColumn, false, field); } } } // We now try to insert the old row one last time, there should still be no room if (page.spaceForInsert()) throw T_Fail.testFailMsg("Did not get no room for record on page error"); // now we want to increase row 0 and column 5 one byte at a time, until the page is full // but, every 5 increases we will reduce the field size by one byte field = REC_007; i = 0; St
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -