📄 heap.java
字号:
// 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); // 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, 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, new Long(id.getContainerId()).toString()); } 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; } public void compressConglomerate( TransactionManager xact_manager, Transaction rawtran) throws StandardException { OpenConglomerate open_conglom = null; HeapController heapcontroller = null; try { open_conglom = new OpenHeap(); // Open table in intended exclusive mode in the top level // transaction, this will stop any ddl from happening until // purge of whole table is finished. if (open_conglom.init( (ContainerHandle) null, this, this.format_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, new Long(id.getContainerId())); } heapcontroller = new HeapController(); heapcontroller.init(open_conglom); open_conglom.getContainer().compressContainer(); } finally { if (open_conglom != null) open_conglom.close(); } return; } /** * 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, 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, new Long(id.getContainerId())); } HeapCompressScan heap_compress_scan = new HeapCompressScan(); heap_compress_scan.init( open_conglom, null, null, 0, null, null, 0); return(heap_compress_scan); } /** * Return an open StoreCostController for the conglomerate. * <p> * Return an open StoreCostController which can be used to ask about * the estimated row counts and costs of ScanController and * ConglomerateController operations, on the given conglomerate. * <p> * @param xact_manager The TransactionController under which this * operation takes place. * @param rawtran raw transaction context in which scan is managed. * * @return The open StoreCostController. * * @exception StandardException Standard exception policy. * * @see StoreCostController **/ public StoreCostController openStoreCost( TransactionManager xact_manager, Transaction rawtran) throws StandardException { OpenHeap open_conglom = new OpenHeap(); if (open_conglom.init( (ContainerHandle) null, this, this.format_ids, xact_manager, rawtran, false, ContainerHandle.MODE_READONLY, TransactionController.MODE_TABLE, (LockingPolicy) null, (DynamicCompiledOpenConglomInfo) null) == null) { throw StandardException.newException( SQLState.HEAP_CONTAINER_NOT_FOUND, new Long(id.getContainerId())); } HeapCostController heapcost = new HeapCostController(); heapcost.init(open_conglom); return(heapcost); } /** * Print this heap. **/ public String toString() { return (id == null) ? "null" : id.toString(); } /************************************************************************** * Public Methods of StaticCompiledOpenConglomInfo Interface: ************************************************************************** */ /** * return the "Conglomerate". * <p> * For heap just return "this", which both implements Conglomerate and * StaticCompiledOpenConglomInfo. * <p> * * @return this **/ public DataValueDescriptor getConglom() { return(this); } /************************************************************************** * Methods of Storable (via Conglomerate) * Storable interface, implies Externalizable, TypedFormat ************************************************************************** */ /** * Return my format identifier. * * @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId **/ public int getTypeFormatId() { return StoredFormatIds.ACCESS_HEAP_V2_ID; } /** * Return whether the value is null or not. * * @see org.apache.derby.iapi.services.io.Storable#isNull **/ public boolean isNull() { return id == null; } /** * Restore the in-memory representation to the null value. * * @see org.apache.derby.iapi.services.io.Storable#restoreToNull * **/ public void restoreToNull() { id = null; } /** * Store the stored representation of the column value in the stream. * **/ public void writeExternal(ObjectOutput out) throws IOException { // write the format id of this conglomerate FormatIdUtil.writeFormatIdInteger(out, this.getTypeFormatId()); out.writeInt((int) id.getSegmentId()); out.writeLong(id.getContainerId()); // write number of columns in heap. out.writeInt(format_ids.length); // write out array of format id's ConglomerateUtil.writeFormatIdArray(format_ids, out); } /** * Restore the in-memory representation from the stream. * * @see java.io.Externalizable#readExternal **/ public void readExternal(ObjectInput in) throws IOException { // read the format id of this conglomerate. FormatIdUtil.readFormatIdInteger(in); int segmentid = in.readInt(); long containerid = in.readLong(); id = new ContainerKey(segmentid, containerid); // read the number of columns in the heap. int num_columns = in.readInt(); // read the array of format ids. format_ids = ConglomerateUtil.readFormatIdArray(num_columns, in); } public void readExternalFromArray(ArrayInputStream in) throws IOException { // read the format id of this conglomerate. FormatIdUtil.readFormatIdInteger(in); int segmentid = in.readInt(); long containerid = in.readLong(); id = new ContainerKey(segmentid, containerid); // read the number of columns in the heap. int num_columns = in.readInt(); // read the array of format ids. format_ids = ConglomerateUtil.readFormatIdArray(num_columns, in); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -