use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class GenericScanController method positionAtInitScan.
/**
************************************************************************
* Protected methods implementing mechanics of scanning rows:
*
* positionAtInitScan() - move scan state to SCAN_INIT
* positionAtStartForForwardScan() - SCAN_INIT -> SCAN_INPROGRESS
* positionAtResumeScan() - reposition after losing scan latch
* fetchRows() - move scan while in SCAN_INPROGRESS
* positionAtNextPage() - move page while in SCAN_INPROGRESS
* positionAtDoneScan() - SCAN_INPROGRESS -> SCAN_DONE
*
**************************************************************************
*/
/**
* Move scan to the the SCAN_INIT state.
* <p>
* This routine is called to move the scan to the SCAN_INIT state.
* It is used both for initialization of the ScanController and
* by reopenScan().
*/
protected void positionAtInitScan(DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, RowPosition pos) throws StandardException {
// startKeyValue init.
this.init_startKeyValue = startKeyValue;
if (RowUtil.isRowEmpty(this.init_startKeyValue))
this.init_startKeyValue = null;
// startSearchOperator init.
this.init_startSearchOperator = startSearchOperator;
// qualifier init.
if ((qualifier != null) && (qualifier.length == 0))
qualifier = null;
this.init_qualifier = qualifier;
// TODO (mikem) - this could be more efficient, by writing
// code to figure out length of row, but scratch row is cached
// so allocating it here is probably not that bad.
init_fetchDesc = new FetchDescriptor((open_conglom.getRuntimeMem().get_scratch_row(open_conglom.getRawTran())).length, init_scanColumnList, init_qualifier);
// stopKeyValue init.
this.init_stopKeyValue = stopKeyValue;
if (RowUtil.isRowEmpty(this.init_stopKeyValue))
this.init_stopKeyValue = null;
// stopSearchOperator init.
this.init_stopSearchOperator = stopSearchOperator;
// reset the "current" position to starting condition.
pos.init();
// scanColumnList.
if (SanityManager.DEBUG) {
if (init_scanColumnList != null) {
// verify that all columns specified in qualifiers, start
// and stop positions are specified in the scanColumnList.
FormatableBitSet required_cols;
if (qualifier != null)
required_cols = RowUtil.getQualifierBitSet(qualifier);
else
required_cols = new FormatableBitSet(0);
// add in start columns
if (this.init_startKeyValue != null) {
required_cols.grow(this.init_startKeyValue.length);
for (int i = 0; i < this.init_startKeyValue.length; i++) required_cols.set(i);
}
if (this.init_stopKeyValue != null) {
required_cols.grow(this.init_stopKeyValue.length);
for (int i = 0; i < this.init_stopKeyValue.length; i++) required_cols.set(i);
}
FormatableBitSet required_cols_and_scan_list = (FormatableBitSet) required_cols.clone();
required_cols_and_scan_list.and(init_scanColumnList);
// FormatableBitSet equals requires the two FormatableBitSets to be of same
// length.
required_cols.grow(init_scanColumnList.size());
if (!required_cols_and_scan_list.equals(required_cols)) {
SanityManager.THROWASSERT("Some column specified in a Btree " + " qualifier/start/stop list is " + "not represented in the scanColumnList." + "\n:required_cols_and_scan_list = " + required_cols_and_scan_list + "\n;required_cols = " + required_cols + "\n;init_scanColumnList = " + init_scanColumnList);
}
}
}
// Scan is fully initialized and ready to go.
scan_state = SCAN_INIT;
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class T_RawStoreFactory method P055.
/**
* Test rollback of partial row update.
* Create a long row with 10 columns on 2 pages (5 columns on each page).
* Update the 1st column on the 2nd page (the 6th column) which causes the
* last column (10th column) to move off the page. Then abort and make sure
* that all the original columns are there and correct.
*
* NOTE: stored length is twice string length + 2
*
* @exception T_Fail Unexpected behaviour from the API
* @exception StandardException Unexpected exception from the implementation
*/
protected void P055(long segment) throws StandardException, T_Fail {
if (!testRollback)
return;
Transaction t = t_util.t_startTransaction();
long cid = t_util.t_addContainer(t, segment, 4096);
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);
int colSize = 90;
T_RawStoreRow r0 = new T_RawStoreRow(10);
r0.setColumn(0, colSize, REC_001);
r0.setColumn(1, colSize, REC_002);
r0.setColumn(2, colSize, REC_003);
r0.setColumn(3, colSize, REC_004);
r0.setColumn(4, colSize, REC_005);
r0.setColumn(5, colSize, REC_009);
r0.setColumn(6, colSize, REC_010);
r0.setColumn(7, colSize, REC_011);
r0.setColumn(8, colSize, REC_012);
r0.setColumn(9, colSize, REC_013);
int insertFlag = Page.INSERT_INITIAL;
insertFlag |= Page.INSERT_OVERFLOW;
RecordHandle rh0 = null;
try {
rh0 = t_util.t_insertAtSlot(page, 0, r0, (byte) insertFlag);
} catch (StandardException se) {
throw T_Fail.testFailMsg("insert of long row failed.");
}
if (rh0 == null)
throw T_Fail.testFailMsg("insert of first long row failed.");
else {
REPORT("about to check fetch...");
DataValueDescriptor column = new SQLChar();
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 0, column, false, REC_001, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 1, column, false, REC_002, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 2, column, false, REC_003, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 3, column, false, REC_004, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 4, column, false, REC_005, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 5, column, false, REC_009, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 6, column, false, REC_010, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 7, column, false, REC_011, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 8, column, false, REC_012, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 9, column, false, REC_013, colSize);
}
t_util.t_commit(t);
// update col 5 (the 6th column, the first column on the 2nd overflow page), which causes
// the last column (col 9, the 10th column) to move off the page.
c = t_util.t_openContainer(t, segment, cid, true);
page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
T_RawStoreRow updateRow = new T_RawStoreRow(10);
for (int i = 0; i < 10; i++) updateRow.setColumn(i, (String) null);
updateRow.setColumn(5, colSize * 2, REC_009);
FormatableBitSet colList = new FormatableBitSet(10);
colList.set(5);
page.updateAtSlot(0, updateRow.getRow(), colList);
REPORT("about to check fetch after update ...");
DataValueDescriptor column = new SQLChar();
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 0, column, false, REC_001, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 1, column, false, REC_002, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 2, column, false, REC_003, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 3, column, false, REC_004, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 4, column, false, REC_005, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 5, column, false, REC_009, colSize * 2);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 6, column, false, REC_010, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 7, column, false, REC_011, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 8, column, false, REC_012, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 9, column, false, REC_013, colSize);
page.unlatch();
t_util.t_abort(t);
REPORT("about to check fetch after abort ...");
c = t_util.t_openContainer(t, segment, cid, false);
page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 0, column, false, REC_001, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 1, column, false, REC_002, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 2, column, false, REC_003, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 3, column, false, REC_004, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 4, column, false, REC_005, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 5, column, false, REC_009, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 6, column, false, REC_010, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 7, column, false, REC_011, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 8, column, false, REC_012, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 9, column, false, REC_013, colSize);
page.unlatch();
if (segment != ContainerHandle.TEMPORARY_SEGMENT) {
// cleanup
t_util.t_dropContainer(t, segment, cid);
}
t_util.t_commit(t);
t.close();
PASS("P055: segment = " + segment);
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class T_RawStoreFactory method P702.
/*
** Update and update partial tests aimed at long rows
*/
/**
* Insert a single row and keep updating it, adding columns
* using partial rows.
*
* @exception T_Fail Unexpected behaviour from the API
* @exception StandardException Unexpected exception from the implementation
*/
protected void P702(long segment) throws StandardException, T_Fail {
Transaction t = t_util.t_startTransaction();
long cid = t_util.t_addContainer(t, segment, 4096);
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);
T_RawStoreRow row = new T_RawStoreRow(0);
RecordHandle rh = t_util.t_insertAtSlot(page, 0, row, (byte) (Page.INSERT_INITIAL | Page.INSERT_OVERFLOW));
t_util.t_checkFetch(page, rh, row);
page.unlatch();
page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
for (int i = 0; i < 10; i++) {
REPORT("P702 - iteration " + i);
FormatableBitSet colList = new FormatableBitSet(i + 1);
colList.set(i);
T_RawStoreRow rowU = new T_RawStoreRow(i + 1);
rowU.setColumn(i, 256, "XX" + i + "YY");
int slot = page.getSlotNumber(rh);
page.updateAtSlot(slot, rowU.getRow(), colList);
page.unlatch();
T_RawStoreRow rowF = new T_RawStoreRow(i + 1);
for (int j = 0; j <= i; j++) {
rowF.setColumn(j, 256, "XX" + j + "YY");
}
page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
t_util.t_checkFetch(page, rh, rowF);
}
page.unlatch();
if (segment != ContainerHandle.TEMPORARY_SEGMENT) {
// cleanup
t_util.t_dropContainer(t, segment, cid);
}
t_util.t_commit(t);
t.close();
PASS("P702: segment = " + segment);
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class T_RawStoreFactory method P040.
/**
* Test space reclaimation - shrink a non head row piece.
*
* @exception T_Fail Unexpected behaviour from the API
* @exception StandardException Unexpected exception from the implementation
*/
protected void P040() throws StandardException, T_Fail {
// Manufacture a row that has a small head row piece, a large 2nd row
// piece and a small third row piece.
// Using the same head page, add a second row that has a small head row
// piece and a medium sized 2nd row piece, a new overflow page should
// be allocated.
// Update the first row to now have a small 2nd row piece.
// Using the same head page, add a third row that has a small head row
// piece and a medium sized 2nd row piece, no new overflow page should
// be allocated.
long segment = 0;
Transaction t = t_util.t_startTransaction();
long cid = t_util.t_addContainer(t, 0, 4096);
ContainerHandle c = t_util.t_openContainer(t, segment, cid, true);
Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
try {
int insertFlag = Page.INSERT_INITIAL | Page.INSERT_OVERFLOW | Page.INSERT_UNDO_WITH_PURGE;
T_RawStoreRow row1 = new T_RawStoreRow(3);
row1.setColumn(0, 400, REC_001);
// this takes ~1600 bytes
row1.setColumn(1, 800, REC_002);
row1.setColumn(2, 400, REC_003);
RecordHandle rh1 = t_util.t_insertAtSlot(page, 0, row1, (byte) insertFlag);
t_util.t_checkFetch(page, rh1, row1);
page.unlatch();
page = null;
t_util.t_commit(t);
c = t_util.t_openContainer(t, segment, cid, true);
Page nextPage = t_util.t_addPage(c);
// remember where next page is
long nextPageNumber = nextPage.getPageNumber();
t_util.t_removePage(c, nextPage);
t_util.t_commit(t);
T_RawStoreRow row2 = new T_RawStoreRow(3);
row2.setColumn(0, 1200, REC_001);
row2.setColumn(1, 1200, REC_002);
row2.setColumn(2, 400, REC_003);
c = t_util.t_openContainer(t, segment, cid, true);
page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
RecordHandle rh2 = t_util.t_insertAtSlot(page, 1, row2, (byte) insertFlag);
t_util.t_checkFetch(page, rh2, row2);
page.unlatch();
page = null;
// this should have allocated more overflow page
nextPage = t_util.t_addPage(c);
long checkNextPageNumber = nextPage.getPageNumber();
if (checkNextPageNumber == nextPageNumber)
throw T_Fail.testFailMsg("expected to allocate more pages");
t_util.t_removePage(c, nextPage);
t_util.t_commit(t);
// now this is the next free page
nextPageNumber = checkNextPageNumber;
// shrink first row 2nd column, and second row 1st column so we
// have space on both the first and the second page on the row
// chain.
// use sparse rows
T_RawStoreRow partialRow = new T_RawStoreRow(2);
partialRow.setColumn(1, 400, REC_004);
T_RawStoreRow partialRow2 = new T_RawStoreRow(2);
partialRow2.setColumn(0, 400, REC_004);
c = t_util.t_openContainer(t, segment, cid, true);
page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
FormatableBitSet colList = new FormatableBitSet(2);
// update first row column 1, the second column
colList.set(1);
int slot1 = page.getSlotNumber(rh1);
page.updateAtSlot(slot1, partialRow.getRow(), colList);
colList.clear(1);
// update second row column 0, the first column
colList.set(0);
int slot2 = page.getSlotNumber(rh2);
page.updateAtSlot(slot2, partialRow2.getRow(), colList);
// verify the update worked.
row1.setColumn(1, 400, REC_004);
row2.setColumn(0, 400, REC_004);
t_util.t_checkFetch(page, rh1, row1);
t_util.t_checkFetch(page, rh2, row2);
page.unlatch();
page = null;
t_util.t_commit(t);
// give post commit a chance to work
t_util.t_wait(10);
// We think the head row should have 2 200 bytes row.
// One of the overflow row piece chain has an overflow page with a
// 200 bytes row followed by another overflow page with a 200 bytes
// row.
// The other overflow row piece should have 1 600 bytes row and no
// other overflow page.
T_RawStoreRow row3 = new T_RawStoreRow(2);
row3.setColumn(0, 400, REC_001);
row3.setColumn(1, 800, REC_002);
// We think this should select the first overflow chain.
c = t_util.t_openContainer(t, segment, cid, true);
page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
if (!page.spaceForInsert())
throw T_Fail.testFailMsg("No space for insert after shrink row");
RecordHandle rh3 = t_util.t_insertAtSlot(page, 1, row3, (byte) insertFlag);
t_util.t_checkFetch(page, rh3, row3);
page.unlatch();
page = null;
// this should not allocate more overflow pages
nextPage = t_util.t_addPage(c);
checkNextPageNumber = nextPage.getPageNumber();
if (checkNextPageNumber != nextPageNumber)
throw T_Fail.testFailMsg("not expected to allocate more pages " + nextPageNumber + "," + checkNextPageNumber);
// cleanup
t_util.t_dropContainer(t, segment, cid);
} finally {
if (page != null)
page.unlatch();
t_util.t_commit(t);
t.close();
}
PASS("P040");
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class T_RawStoreFactory method P015.
/**
* P015
*
* this test exercises updateAtSlot
*
* @exception T_Fail Unexpected behaviour from the API
* @exception StandardException Unexpected exception from the implementation
*/
protected void P015() throws StandardException, T_Fail {
Transaction t = t_util.t_startTransaction();
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);
// REPORT("insert 3 records");
T_RawStoreRow row1 = new T_RawStoreRow(REC_001);
T_RawStoreRow row2 = new T_RawStoreRow(2);
row2.setColumn(0, (String) null);
row2.setColumn(1, REC_001);
T_RawStoreRow row3 = new T_RawStoreRow(3);
row3.setColumn(0, REC_001);
row3.setColumn(1, REC_002);
row3.setColumn(2, REC_003);
RecordHandle r1, r2, r3;
r1 = t_util.t_insertAtSlot(page, 0, row1);
r2 = r3 = null;
r2 = t_util.t_insertAtSlot(page, 1, row2);
if (r2 == null) {
REPORT("P015 not completed - cannot insert second row");
return;
}
r3 = t_util.t_insertAtSlot(page, 2, row3);
if (r3 == null) {
REPORT("P015 not completed - cannot insert third row");
return;
}
// check that they are inserted correctly
t_util.t_checkFetch(page, r1, row1);
t_util.t_checkFetch(page, r2, row2);
t_util.t_checkFetch(page, r3, row3);
// now update the middle row with a large value
T_RawStoreRow row2u = new T_RawStoreRow(2);
row2u.setColumn(0, "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
row2u.setColumn(1, "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
page.updateAtSlot(1, row2u.getRow(), (FormatableBitSet) null);
t_util.t_checkFetch(page, r2, row2u);
// now update the field of the first record with a large value
((T_RawStoreRow) row1).setColumn(0, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
FormatableBitSet validColumn = new FormatableBitSet(2);
validColumn.clear();
validColumn.set(0);
page.updateAtSlot(0, row1.getRow(), validColumn);
t_util.t_checkFetch(page, r1, row1);
((T_RawStoreRow) row3).setColumn(1, "XXabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
validColumn.clear();
validColumn.set(1);
page.updateAtSlot(2, row3.getRow(), validColumn);
t_util.t_checkFetch(page, r3, row3);
// clean up
PASS("P015");
// cleanup
t_util.t_dropContainer(t, 0, cid);
t_util.t_commit(t);
t.close();
}
Aggregations