use of org.apache.derby.iapi.store.access.conglomerate.Conglomerate in project derby by apache.
the class B2IController method init.
void init(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, boolean get_locks, B2I conglomerate, B2IUndo undo, B2IStaticCompiledInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) throws StandardException {
// open and lock the base table.
int base_open_mode = open_mode | TransactionController.OPENMODE_FOR_LOCK_ONLY;
// used for geting the IX intent lock on the table.
if (static_info != null) {
base_cc_for_locking = xact_manager.openCompiledConglomerate(false, base_open_mode, lock_level, TransactionController.ISOLATION_REPEATABLE_READ, static_info.base_table_static_info, /* TODO - maintain a dynamic info for this */
((Conglomerate) static_info.getConglom()).getDynamicCompiledConglomInfo());
} else {
base_cc_for_locking = xact_manager.openConglomerate(conglomerate.baseConglomerateId, false, base_open_mode, lock_level, TransactionController.ISOLATION_REPEATABLE_READ);
}
BTreeLockingPolicy b2i_locking_policy;
if (lock_level == TransactionController.MODE_TABLE) {
b2i_locking_policy = new B2ITableLocking3(rawtran, lock_level, locking_policy, base_cc_for_locking, this);
} else if (lock_level == TransactionController.MODE_RECORD) {
b2i_locking_policy = new B2IRowLocking3(rawtran, lock_level, locking_policy, base_cc_for_locking, this);
} else {
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("Bad lock level: " + lock_level);
}
b2i_locking_policy = null;
}
// Do generic b-tree initialization.
super.init(xact_manager, hold, (ContainerHandle) null, rawtran, open_mode, lock_level, b2i_locking_policy, conglomerate, undo, static_info, dynamic_info);
if (SanityManager.DEBUG)
SanityManager.ASSERT(conglomerate != null);
}
use of org.apache.derby.iapi.store.access.conglomerate.Conglomerate in project derby by apache.
the class B2IFactory method readConglomerate.
/**
* Return Conglomerate object for conglomerate with conglomid.
* <p>
* Return the Conglomerate Object. This is implementation specific.
* Examples of what will be done is using the id to find the file where
* the conglomerate is located, and then executing implementation specific
* code to instantiate an object from reading a "special" row from a
* known location in the file. In the btree case the btree conglomerate
* is stored as a column in the control row on the root page.
* <p>
* This operation is costly so it is likely an implementation using this
* will cache the conglomerate row in memory so that subsequent accesses
* need not perform this operation.
* <p>
* The btree object returned by this routine may be installed in a cache
* so the object must not change.
*
* @return An instance of the conglomerate.
*
* @exception StandardException Standard exception policy.
*/
public Conglomerate readConglomerate(TransactionManager xact_manager, ContainerKey container_key) throws StandardException {
Conglomerate btree = null;
ContainerHandle container = null;
ControlRow root = null;
try {
// open readonly, with no locks. Dirty read is ok as it is the
// responsibility of client code to make sure this data is not
// changing while being read. The only changes that currently
// happen to this data is creation and deletion - no updates
// ever happen to btree conglomerates.
container = (xact_manager.getRawStoreXact()).openContainer(container_key, (LockingPolicy) null, ContainerHandle.MODE_READONLY);
if (container == null) {
throw StandardException.newException(SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST, container_key.getContainerId());
}
// The conglomerate is located in the control row on the root page.
root = ControlRow.get(container, BTree.ROOTPAGEID);
if (SanityManager.DEBUG)
SanityManager.ASSERT(root.getPage().isLatched());
// read the Conglomerate from it's entry in the control row.
btree = (Conglomerate) root.getConglom(B2I.FORMAT_NUMBER);
if (SanityManager.DEBUG)
SanityManager.ASSERT(btree instanceof B2I);
} finally {
if (root != null)
root.release();
if (container != null)
container.close();
}
return (btree);
}
use of org.apache.derby.iapi.store.access.conglomerate.Conglomerate in project derby by apache.
the class B2IForwardScan method init.
/**
* Initialize the scan for use.
* <p>
* Any changes to this method may have to be reflected in close as well.
* <p>
* The btree init opens the container (super.init), and stores away the
* state of the qualifiers. The actual searching for the first position
* is delayed until the first next() call.
*
* @exception StandardException Standard exception policy.
*/
public void init(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, int isolation_level, boolean open_for_locking, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, B2I conglomerate, B2IUndo undo, B2IStaticCompiledInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) throws StandardException {
// open and lock the base table.
int base_open_mode = open_mode | TransactionController.OPENMODE_FOR_LOCK_ONLY;
// open the base conglomerate - just to get lock
if (static_info != null) {
base_cc_for_locking = xact_manager.openCompiledConglomerate(false, base_open_mode, lock_level, isolation_level, static_info.base_table_static_info, /* TODO - maintain a dynamic info for this */
((Conglomerate) static_info.getConglom()).getDynamicCompiledConglomInfo());
} else {
base_cc_for_locking = xact_manager.openConglomerate(conglomerate.baseConglomerateId, false, base_open_mode, lock_level, isolation_level);
}
BTreeLockingPolicy b2i_locking_policy = conglomerate.getBtreeLockingPolicy(rawtran, lock_level, open_mode, isolation_level, base_cc_for_locking, this);
super.init(xact_manager, rawtran, hold, open_mode, lock_level, b2i_locking_policy, scanColumnList, startKeyValue, startSearchOperator, qualifier, stopKeyValue, stopSearchOperator, conglomerate, undo, static_info, dynamic_info);
// todo - should just save the isolation level in OpenBtree but
// save it here for now.
init_isolation_level = isolation_level;
}
use of org.apache.derby.iapi.store.access.conglomerate.Conglomerate in project derby by apache.
the class RAMTransaction method defragmentConglomerate.
/**
* Compress table in place.
* <p>
* Returns a GroupFetchScanController which can be used to move rows
* around in a table, creating a block of free pages at the end of the
* table. The process will move rows from the end of the table toward
* the beginning. The GroupFetchScanController will return the
* old row location, the new row location, and the actual data of any
* row moved. Note that this scan only returns moved rows, not an
* entire set of rows, the scan is designed specifically to be
* used by either explicit user call of the SYSCS_ONLINE_COMPRESS_TABLE()
* procedure, or internal background calls to compress the table.
*
* The old and new row locations are returned so that the caller can
* update any indexes necessary.
*
* This scan always returns all collumns of the row.
*
* All inputs work exactly as in openScan(). The return is
* a GroupFetchScanController, which only allows fetches of groups
* of rows from the conglomerate.
* <p>
*
* @return The GroupFetchScanController to be used to fetch the rows.
*
* @param conglomId see openScan()
* @param hold see openScan()
* @param open_mode see openScan()
* @param lock_level see openScan()
* @param isolation_level see openScan()
*
* @exception StandardException Standard exception policy.
*
* @see ScanController
* @see GroupFetchScanController
*/
public GroupFetchScanController defragmentConglomerate(long conglomId, boolean online, boolean hold, int open_mode, int lock_level, int isolation_level) throws StandardException {
if (SanityManager.DEBUG) {
if ((open_mode & ~(TransactionController.OPENMODE_FORUPDATE | TransactionController.OPENMODE_FOR_LOCK_ONLY | TransactionController.OPENMODE_SECONDARY_LOCKED)) != 0)
SanityManager.THROWASSERT("Bad open mode to openScan:" + Integer.toHexString(open_mode));
if (!(lock_level == MODE_RECORD | lock_level == MODE_TABLE))
SanityManager.THROWASSERT("Bad lock level to openScan:" + lock_level);
}
// Find the conglomerate.
Conglomerate conglom = findExistingConglomerate(conglomId);
// Get a scan controller.
ScanManager sm = conglom.defragmentConglomerate(this, rawtran, hold, open_mode, determine_lock_level(lock_level), determine_locking_policy(lock_level, isolation_level), isolation_level);
// Keep track of it so we can release on close.
scanControllers.add(sm);
return (sm);
}
use of org.apache.derby.iapi.store.access.conglomerate.Conglomerate in project derby by apache.
the class RAMTransaction method createConglomerate.
/**
* Create a new conglomerate.
* <p>
* @see TransactionController#createConglomerate
*
* @exception StandardException Standard exception policy.
*/
public long createConglomerate(String implementation, DataValueDescriptor[] template, ColumnOrdering[] columnOrder, int[] collationIds, Properties properties, int temporaryFlag) throws StandardException {
// Find the appropriate factory for the desired implementation.
MethodFactory mfactory;
mfactory = accessmanager.findMethodFactoryByImpl(implementation);
if (mfactory == null || !(mfactory instanceof ConglomerateFactory)) {
throw StandardException.newException(SQLState.AM_NO_SUCH_CONGLOMERATE_TYPE, implementation);
}
ConglomerateFactory cfactory = (ConglomerateFactory) mfactory;
// Create the conglomerate
// RESOLVE (mikem) - eventually segmentid's will be passed into here
// in the properties. For now just use 0.]
int segment;
long conglomid;
if ((temporaryFlag & TransactionController.IS_TEMPORARY) == TransactionController.IS_TEMPORARY) {
segment = ContainerHandle.TEMPORARY_SEGMENT;
conglomid = ContainerHandle.DEFAULT_ASSIGN_ID;
} else {
// RESOLVE - only using segment 0
segment = 0;
conglomid = accessmanager.getNextConglomId(cfactory.getConglomerateFactoryId());
}
// call the factory to actually create the conglomerate.
Conglomerate conglom = cfactory.createConglomerate(this, segment, conglomid, template, columnOrder, collationIds, properties, temporaryFlag);
long conglomId;
if ((temporaryFlag & TransactionController.IS_TEMPORARY) == TransactionController.IS_TEMPORARY) {
conglomId = nextTempConglomId--;
if (tempCongloms == null)
tempCongloms = new HashMap<Long, Conglomerate>();
tempCongloms.put(conglomId, conglom);
} else {
conglomId = conglom.getContainerid();
accessmanager.conglomCacheAddEntry(conglomId, conglom);
}
return conglomId;
}
Aggregations