use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.
the class T_CreateConglomRet method t_010.
/**
* Test restoreToNull
*
* @exception StandardException Standard exception policy.
* @exception T_Fail Throws T_Fail on any test failure.
*/
protected boolean t_010(TransactionController tc) throws StandardException, T_Fail {
REPORT("Starting t_006");
B2I testbtree = new B2I();
// test restoreToNull()
testbtree.restoreToNull();
if (!(testbtree.isNull()))
throw T_Fail.testFailMsg("bad restoreToNull/isNull");
// test bad container open not working.
try {
// the following open should fail with a containerNotFound error
// for testing purposes - assume TransactionController can be casted
TransactionManager tm = (TransactionManager) tc;
ConglomerateController cc = testbtree.open(tm, tm.getRawStoreXact(), false, 0, 0, (LockingPolicy) null, null, null);
throw T_Fail.testFailMsg("bad open succeeded.");
} catch (StandardException t) {
// expected path comes here.
}
// create the base table
DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
T_SecondaryIndexRow index_row1 = new T_SecondaryIndexRow();
long base_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", // base table template row
base_row, // column sort order - not required for heap
null, // default collation
null, // default properties
null, TransactionController.IS_DEFAULT);
// Open the base table
ConglomerateController base_cc = tc.openConglomerate(base_conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
RowLocation base_rowloc1 = base_cc.newRowLocationTemplate();
index_row1.init(base_row, base_rowloc1, 3);
// create the secondary index
Properties properties = createProperties(// no current properties list
null, // don't allow duplicates
false, // index on all base row cols + row location
3, // non-unique index
2, // maintain parent links
true, // fake base conglom for now
-42, // row loc in last column
2);
TransactionManager tm = (TransactionManager) tc;
// test bad property
try {
testbtree.create(tm, -1, ContainerHandle.DEFAULT_ASSIGN_ID, index_row1.getRow(), null, null, null, TransactionController.IS_TEMPORARY);
throw T_Fail.testFailMsg("bad create succeeded.");
} catch (StandardException t) {
// expected path comes here.
}
// try bad properties
// create the secondary index
properties = createProperties(// no current properties list
null, // don't allow duplicates
false, // index on all base row cols + row location
3, // 1 unique field leaving 1 non key field
1, // maintain parent links
true, // fake base conglom for now
-42, // row loc in last column
2);
try {
long index_conglomid = tc.createConglomerate(// create a btree secondary
"BTREE", // row template
index_row1.getRow(), // column sort order - default
null, // default collation
null, // properties
properties, // not temporary
TransactionController.IS_DEFAULT);
throw T_Fail.testFailMsg("bad create succeeded.");
} catch (Throwable t) {
// expected path comes here
}
REPORT("Ending t_010");
return (true);
}
use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.
the class BTreePostCommit method performWork.
/**
* perform the work described in the postcommit work.
* <p>
* In this implementation the only work that can be executed by this
* post commit processor is this class itself.
* <p>
*
* @return Returns Serviceable.DONE when work has completed, or
* returns Serviceable.REQUEUE if work needs to be requeued.
*
* @param contextMgr the context manager started by the
* post commit daemon
*
* @exception StandardException Standard exception policy.
*/
public int performWork(ContextManager contextMgr) throws StandardException {
// requeue if work was not completed in this try because of locks
boolean requeue_work = false;
TransactionManager tc = (TransactionManager) this.access_factory.getAndNameTransaction(contextMgr, AccessFactoryGlobals.SYS_TRANS_NAME);
TransactionManager internal_xact = tc.getInternalTransaction();
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON("verbose_btree_post_commit"))
System.out.println("starting internal xact\n");
}
OpenBTree open_btree = null;
try {
// Get lock on base table.
// First attempt to get a table lock on the btree. This lock is
// requested NOWAIT to not impede normal operation on the table.
// If the lock were to wait then the current lock manager livelock
// algorithm would block all subsequent lock requests on this
// btree even if they are compatible with the current holder of
// the lock.
//
// If this lock is granted then:
// 1) deleted rows on the page can automatically be purged as
// they must be committed, otherwise lock would not have been
// granted.
// 2) if all rows from page are reclaimed then a structure shrink
// which requires table level lock can be executed.
//
open_btree = openIndex(internal_xact, TransactionController.MODE_TABLE, LockingPolicy.MODE_CONTAINER);
DataValueDescriptor[] shrink_key = purgeCommittedDeletes(open_btree, this.page_number);
if (shrink_key != null)
doShrink(open_btree, shrink_key);
} catch (StandardException se) {
if (se.isLockTimeoutOrDeadlock()) {
try {
open_btree = openIndex(internal_xact, TransactionController.MODE_RECORD, LockingPolicy.MODE_RECORD);
purgeRowLevelCommittedDeletes(open_btree);
} catch (StandardException se2) {
if (se2.isLockTimeoutOrDeadlock()) {
// Could not get intended exclusive table lock, so
// requeue and hope other user gives up table level
// lock soon. This should not be normal case.
requeue_work = true;
}
}
}
} finally {
if (open_btree != null)
open_btree.close();
// counting on this commit to release latches associated with
// row level purge, that have been left to prevent others from
// getting to purged pages before the commit. If latch is released
// early, other transactions could insert on the page which could
// prevent undo of the purges in case of a crash before the commit
// gets to the disk.
internal_xact.commit();
internal_xact.destroy();
}
return (requeue_work ? Serviceable.REQUEUE : Serviceable.DONE);
}
use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.
the class BTreeController method start_xact_and_dosplit.
/**
* Start an internal transaction and do the split.
* <p>
* This routine starts a new transaction, and handles any errors that
* may come during the transaction. This transation must not obtain any
* locks as they are likely to conflict with the current user transaction.
* <p>
* If attempt_to_reclaim_deleted_rows is true this routine will
* attempt to reclaim space on the leaf page input, by purging
* committed deleted rows from the leaf. If it succeeds in purging at
* least one row, then it will commit the internal transaction and return
* without actually performing a split.
*
* @param scratch_template A scratch template used to search a page.
* @param rowToInsert The row to insert, make sure during split to
* make room for this row.
*
* @exception StandardException Standard exception policy.
*/
private long start_xact_and_dosplit(boolean attempt_to_reclaim_deleted_rows, long leaf_pageno, DataValueDescriptor[] scratch_template, DataValueDescriptor[] rowToInsert, int flag) throws StandardException {
TransactionManager split_xact = null;
OpenBTree split_open_btree = null;
ControlRow root = null;
// Get an internal transaction to be used for the split.
split_xact = this.init_open_user_scans.getInternalTransaction();
if (SanityManager.DEBUG) {
if (((getOpenMode() & ContainerHandle.MODE_FORUPDATE) != ContainerHandle.MODE_FORUPDATE)) {
SanityManager.THROWASSERT("Container not opened with update should not cause split");
}
}
boolean do_split = true;
if (attempt_to_reclaim_deleted_rows) {
// Get lock on base table.
ConglomerateController base_cc = null;
try {
base_cc = this.getConglomerate().lockTable(split_xact, (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_LOCK_NOWAIT), TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
} catch (StandardException se) {
// any error just don't try to reclaim deleted rows. The
// expected error is that we can't get the lock, which the
// current interface throws as a containerNotFound exception.
}
if (base_cc != null) {
// we got IX lock on the base table, so can try reclaim space.
// We can only reclaim space by opening the btree in row lock
// mode. Table level lock row recovery is hard as we can't
// determine if the deleted rows we encounter have been
// deleted by our parent caller and have been committed or
// not. We will have to get those rows offline.
split_open_btree = new OpenBTree();
split_open_btree.init(this.init_open_user_scans, split_xact, // open the container.
null, split_xact.getRawStoreXact(), false, (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_LOCK_NOWAIT), TransactionManager.MODE_RECORD, this.getConglomerate().getBtreeLockingPolicy(split_xact.getRawStoreXact(), TransactionController.MODE_RECORD, LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, (ConglomerateController) base_cc, split_open_btree), this.getConglomerate(), (LogicalUndo) null, (DynamicCompiledOpenConglomInfo) null);
// don't split if we reclaim any rows.
do_split = !reclaim_deleted_rows(split_open_btree, leaf_pageno);
// on return if !do_split then the latch on leaf_pageno is held
// and will be released by the committing or aborting the
// transaction. If a purge has been done, no other action on
// the page should be attempted (ie. a split) before committing
// the purges.
split_open_btree.close();
}
}
long new_leaf_pageno = leaf_pageno;
if (do_split) {
// no space was reclaimed from deleted rows, so do split to allow
// space for a subsequent insert.
split_open_btree = new OpenBTree();
split_open_btree.init(this.init_open_user_scans, split_xact, // open the container.
null, split_xact.getRawStoreXact(), false, // use same mode this controller
getOpenMode(), // was opened with
TransactionManager.MODE_NONE, this.getConglomerate().getBtreeLockingPolicy(split_xact.getRawStoreXact(), this.init_lock_level, LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // no base row locks during split
(ConglomerateController) null, split_open_btree), this.getConglomerate(), (LogicalUndo) null, (DynamicCompiledOpenConglomInfo) null);
// Get the root page back, and perform a split following the
// to-be-inserted key. The split releases the root page latch.
root = ControlRow.get(split_open_btree, BTree.ROOTPAGEID);
if (SanityManager.DEBUG)
SanityManager.ASSERT(root.page.isLatched());
new_leaf_pageno = root.splitFor(split_open_btree, scratch_template, null, rowToInsert, flag);
split_open_btree.close();
}
split_xact.commit();
split_xact.destroy();
return (new_leaf_pageno);
}
use of org.apache.derby.iapi.store.access.conglomerate.TransactionManager in project derby by apache.
the class CacheLock method bootPasswordChange.
private boolean bootPasswordChange(TransactionController tc, String key, Serializable value) throws StandardException {
// boot password in clear text
if (key.equals(Attribute.BOOT_PASSWORD)) {
// The user is trying to change the secret key.
// The secret key is never stored in clear text, but we
// store the encrypted form in the services.properties
// file. Swap the secret key with the encrypted form and
// put that in the services.properties file.
AccessFactory af = ((TransactionManager) tc).getAccessManager();
RawStoreFactory rsf = (RawStoreFactory) findServiceModule(af, RawStoreFactory.MODULE);
// remove secret key from properties list if possible
serviceProperties.remove(Attribute.BOOT_PASSWORD);
value = rsf.changeBootPassword(serviceProperties, value);
serviceProperties.put(RawStoreFactory.ENCRYPTED_KEY, value);
return true;
} else {
return false;
}
}
Aggregations