use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class T_RawStoreFactory method P056.
/**
* Test rollback of partial row update.
* Create a long row with 15 columns on 3 pages (5 columns on each page).
* Update the 1st column on the 2nd page (the 6th column) which causes the
* last column of that page (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 P056(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(15);
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);
r0.setColumn(10, colSize, REC_014);
r0.setColumn(11, colSize, REC_015);
r0.setColumn(12, colSize, REC_016);
r0.setColumn(13, colSize, REC_017);
r0.setColumn(14, colSize, REC_018);
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_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 10, column, false, REC_014, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 11, column, false, REC_015, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 12, column, false, REC_016, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 13, column, false, REC_017, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 14, column, false, REC_018, 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(15);
for (int i = 0; i < 15; i++) updateRow.setColumn(i, (String) null);
updateRow.setColumn(5, colSize * 2, REC_009);
FormatableBitSet colList = new FormatableBitSet(15);
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);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 10, column, false, REC_014, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 11, column, false, REC_015, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 12, column, false, REC_016, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 13, column, false, REC_017, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 14, column, false, REC_018, 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);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 10, column, false, REC_014, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 11, column, false, REC_015, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 12, column, false, REC_016, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 13, column, false, REC_017, colSize);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 14, column, false, REC_018, colSize);
page.unlatch();
if (segment != ContainerHandle.TEMPORARY_SEGMENT) {
// cleanup
t_util.t_dropContainer(t, segment, cid);
}
t_util.t_commit(t);
t.close();
PASS("P056: segment = " + segment);
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class T_RawStoreFactory method P703Helper.
private void P703Helper(Page page, RecordHandle rh, int colNum, String newVal, String unchangedCol) throws StandardException, T_Fail {
FormatableBitSet colList = new FormatableBitSet(2);
T_RawStoreRow rowU = new T_RawStoreRow(2);
// -1 indicates no columns set in bit set
if (colNum != -1) {
colList.grow(colNum + 1);
colList.set(colNum);
rowU.setColumn(colNum, newVal);
} else {
// only used for read from now on
colNum = 0;
}
int slot = page.getSlotNumber(rh);
page.updateAtSlot(slot, rowU.getRow(), colList);
T_RawStoreRow row = new T_RawStoreRow(2);
row.setColumn(colNum, newVal);
row.setColumn(colNum == 0 ? 1 : 0, unchangedCol);
t_util.t_checkFetch(page, rh, row);
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class T_Recovery method S003.
/*
* 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();
}
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class T_Util method t_checkUpdateCol.
/**
* Using sparse representation:
* Update a column of a record and check resulting value.
*
* @exception T_Fail Record handle returned is null.
* @exception StandardException Unexpected exception from the implementation
*
* @see Page#updateAtSlot
*/
public void t_checkUpdateCol(Page page, RecordHandle rh, int colNum, int numCols, String data) throws T_Fail, StandardException {
if (!page.recordExists(rh, false))
throw T_Fail.testFailMsg("Record does not exist");
T_RawStoreRow writeRow = new T_RawStoreRow(numCols);
for (int i = 0; i < numCols; i++) writeRow.setColumn(i, (String) null);
writeRow.setColumn(colNum, data);
FormatableBitSet colList = new FormatableBitSet(numCols);
colList.set(colNum);
int slot = page.getSlotNumber(rh);
if (page.updateAtSlot(slot, writeRow.getRow(), colList) == null)
throw T_Fail.testFailMsg("update failed");
t_checkFetchCol(page, rh, colNum, numCols, data);
}
use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.
the class commit_method method XATest_5.
/**
* Very simple testing of the recover() call.
* <p>
* @exception StandardException Standard exception policy.
*/
void XATest_5(commit_method commit_method) throws StandardException, T_Fail {
REPORT("(XATest_5) starting");
// Should be no prepared transactions when we first start.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// Should be no prepared transactions when we first start.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMNOFLAGS).length != 0) {
throw T_Fail.testFailMsg("NOFLAGS should always return 0.");
}
ContextManager cm = getContextService().getCurrentContextManager();
// COMMIT AN IDLE TRANSACTION.
// Start a global transaction
XATransactionController xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Should be no prepared transactions, there is one idle global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// COMMIT AN UPDATE ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Create a heap conglomerate.
T_AccessRow template_row = new T_AccessRow(1);
long conglomid = xa_tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order - not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// COMMIT A READ ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Open a scan on the conglomerate.
ScanController scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// PREPARE AN UPDATE TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Create a heap conglomerate.
template_row = new T_AccessRow(1);
conglomid = xa_tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order - not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// prepare the update xact.
if (xa_tc.xa_prepare() != XATransactionController.XA_OK) {
throw T_Fail.testFailMsg("prepare of update xact did not return XA_OK.");
}
try {
// Open a scan on the conglomerate.
scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
throw T_Fail.testFailMsg("Should not be able to do anything on xact after prepare.");
} catch (StandardException se) {
// expected exception, fall through.
}
// Should be no prepared transactions, there is one update global xact.
Xid[] prepared_xacts = ((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN);
if (prepared_xacts.length != 1) {
throw T_Fail.testFailMsg("recover incorrectly returned wrong prepared xacts.");
}
if (prepared_xacts[0].getFormatId() != 42)
throw T_Fail.testFailMsg("bad format id = " + prepared_xacts[0].getFormatId());
byte[] gid = prepared_xacts[0].getGlobalTransactionId();
if (!java.util.Arrays.equals(gid, global_id)) {
throw T_Fail.testFailMsg("bad global id = " + org.apache.derbyTesting.unitTests.util.BitUtil.hexDump(gid));
}
byte[] bid = prepared_xacts[0].getBranchQualifier();
if (!java.util.Arrays.equals(bid, branch_id)) {
throw T_Fail.testFailMsg("bad branch id = " + org.apache.derbyTesting.unitTests.util.BitUtil.hexDump(bid));
}
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMNOFLAGS).length != 0) {
throw T_Fail.testFailMsg("NOFLAGS should always return 0.");
}
// commit a prepared transaction - using two phase.
commit_method.commit(false, 42, global_id, branch_id, xa_tc);
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// done with this xact.
xa_tc.destroy();
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
REPORT("(XATest_5) finishing");
}
Aggregations