use of org.apache.derby.iapi.store.raw.ContainerHandle 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.raw.ContainerHandle in project derby by apache.
the class D_HeapController method diag.
/**
* Default implementation of diagnostic on the object.
* <p>
* This routine returns a string with whatever diagnostic information
* you would like to provide about this object.
* <p>
* This routine should be overriden by a real implementation of the
* diagnostic information you would like to provide.
* <p>
*
* @return A string with diagnostic information about the object.
*
* @exception StandardException Standard Derby exception policy
*/
public String diag() throws StandardException {
long pageid;
ContainerHandle container = ((HeapController) this.diag_object).getOpenConglom().getContainer();
TableStats stat = new TableStats();
// ask page to provide diag info:
Properties prop = new Properties();
prop.put(Page.DIAG_PAGE_SIZE, "");
prop.put(Page.DIAG_BYTES_FREE, "");
prop.put(Page.DIAG_BYTES_RESERVED, "");
prop.put(Page.DIAG_RESERVED_SPACE, "");
prop.put(Page.DIAG_MINIMUM_REC_SIZE, "");
prop.put(Page.DIAG_NUMOVERFLOWED, "");
prop.put(Page.DIAG_ROWSIZE, "");
prop.put(Page.DIAG_MINROWSIZE, "");
prop.put(Page.DIAG_MAXROWSIZE, "");
// scan all pages in the heap gathering summary stats in stat
Page page = container.getFirstPage();
while (page != null) {
D_HeapController.diag_page(page, prop, stat);
pageid = page.getPageNumber();
page.unlatch();
page = container.getNextPage(pageid);
}
return (D_HeapController.diag_tabulate(prop, stat));
}
use of org.apache.derby.iapi.store.raw.ContainerHandle in project derby by apache.
the class Heap method compressConglomerate.
public void compressConglomerate(TransactionManager xact_manager, Transaction rawtran) throws StandardException {
OpenConglomerate open_conglom = null;
HeapController heapcontroller = null;
try {
open_conglom = new OpenHeap();
if (open_conglom.init((ContainerHandle) null, this, this.format_ids, this.collation_ids, xact_manager, rawtran, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, rawtran.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_REPEATABLE_READ, true), null) == null) {
throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, id.getContainerId());
}
heapcontroller = new HeapController();
heapcontroller.init(open_conglom);
open_conglom.getContainer().compressContainer();
} finally {
if (open_conglom != null)
open_conglom.close();
}
return;
}
use of org.apache.derby.iapi.store.raw.ContainerHandle in project derby by apache.
the class Heap method defragmentConglomerate.
/**
* Open a heap compress scan.
* <p>
*
* @see Conglomerate#defragmentConglomerate
*
* @exception StandardException Standard exception policy.
*/
public ScanManager defragmentConglomerate(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, int isolation_level) throws StandardException {
OpenConglomerate open_conglom = new OpenHeap();
if (open_conglom.init((ContainerHandle) null, this, this.format_ids, this.collation_ids, xact_manager, rawtran, hold, open_mode, lock_level, rawtran.newLockingPolicy(LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, true), null) == null) {
throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, id.getContainerId());
}
HeapCompressScan heap_compress_scan = new HeapCompressScan();
heap_compress_scan.init(open_conglom, null, null, 0, null, null, 0);
return (heap_compress_scan);
}
use of org.apache.derby.iapi.store.raw.ContainerHandle in project derby by apache.
the class Heap method purgeConglomerate.
public void purgeConglomerate(TransactionManager xact_manager, Transaction rawtran) throws StandardException {
OpenConglomerate open_for_ddl_lock = null;
HeapController heapcontroller = null;
TransactionManager nested_xact = null;
try {
open_for_ddl_lock = new OpenHeap();
if (open_for_ddl_lock.init((ContainerHandle) null, this, this.format_ids, this.collation_ids, xact_manager, rawtran, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, null, null) == null) {
throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, id.getContainerId());
}
// perform all the "real" work in a non-readonly nested user
// transaction, so that as work is completed on each page resources
// can be released. Must be careful as all locks obtained in nested
// transaction will conflict with parent transaction - so this call
// must be made only if parent transaction can have no conflicting
// locks on the table, otherwise the purge will fail with a self
// deadlock.
nested_xact = (TransactionManager) xact_manager.startNestedUserTransaction(false, true);
// now open the table in a nested user transaction so that each
// page worth of work can be committed after it is done.
OpenConglomerate open_conglom = new OpenHeap();
if (open_conglom.init((ContainerHandle) null, this, this.format_ids, this.collation_ids, nested_xact, nested_xact.getRawStoreXact(), true, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, nested_xact.getRawStoreXact().newLockingPolicy(LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, true), null) == null) {
throw StandardException.newException(SQLState.HEAP_CONTAINER_NOT_FOUND, Long.toString(id.getContainerId()));
}
heapcontroller = new HeapController();
heapcontroller.init(open_conglom);
Page page = open_conglom.getContainer().getFirstPage();
boolean purgingDone = false;
while (page != null) {
long pageno = page.getPageNumber();
purgingDone = heapcontroller.purgeCommittedDeletes(page);
if (purgingDone) {
page = null;
// commit xact to free resouurces ASAP, commit will
// unlatch the page if it has not already been unlatched
// by a remove.
open_conglom.getXactMgr().commitNoSync(TransactionController.RELEASE_LOCKS);
// the commit closes the underlying container, so let
// the heapcontroller know this has happened. Usually
// the transaction takes care of this, but this controller
// is internal, so the transaction does not know about it.
heapcontroller.closeForEndTransaction(false);
// the commit will close the underlying
open_conglom.reopen();
} else {
page.unlatch();
page = null;
}
page = open_conglom.getContainer().getNextPage(pageno);
}
} finally {
if (open_for_ddl_lock != null)
open_for_ddl_lock.close();
if (heapcontroller != null)
heapcontroller.close();
if (nested_xact != null) {
nested_xact.commitNoSync(TransactionController.RELEASE_LOCKS);
nested_xact.destroy();
}
}
return;
}
Aggregations