⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 heapcontroller.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.store.access.heap.HeapController   Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License. */package org.apache.derby.impl.store.access.heap;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException; import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;import org.apache.derby.iapi.store.access.AccessFactoryGlobals;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.RowLocationRetRowSource;import org.apache.derby.iapi.store.access.RowUtil;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.store.raw.ContainerHandle;import org.apache.derby.iapi.store.raw.LockingPolicy;import org.apache.derby.iapi.store.raw.Page;import org.apache.derby.iapi.store.raw.RecordHandle;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.impl.store.access.conglomerate.OpenConglomerate;import org.apache.derby.impl.store.access.conglomerate.GenericConglomerateController;import org.apache.derby.impl.store.access.conglomerate.RowPosition;import org.apache.derby.iapi.services.io.FormatableBitSet;/****/public class HeapController     extends GenericConglomerateController     implements ConglomerateController{    /**************************************************************************     * Fields of the class     **************************************************************************     */    /**************************************************************************     * Constructors for This class:     **************************************************************************     */    /**************************************************************************     * Protected concrete impl of abstract methods of      *     GenericConglomerateController class:     **************************************************************************     */    protected final void getRowPositionFromRowLocation(    RowLocation row_loc,    RowPosition pos)        throws StandardException    {        if (SanityManager.DEBUG)        {            SanityManager.ASSERT(row_loc instanceof HeapRowLocation);        }        pos.current_rh =             ((HeapRowLocation) row_loc).getRecordHandle(                open_conglom.getContainer());        pos.current_rh_qualified = true;    }    protected void queueDeletePostCommitWork(    RowPosition pos)        throws StandardException    {        TransactionManager xact_mgr = open_conglom.getXactMgr();        xact_mgr.addPostCommitWork(            new HeapPostCommit(                xact_mgr.getAccessManager(),                 (Heap) open_conglom.getConglomerate(),                pos.current_page.getPageNumber()));    }    /**************************************************************************     * Private/Protected methods of This class:     **************************************************************************     */    /**     * Check and purge committed deleted rows on a page.     * <p>     * 	 * @return true, if no purging has been done on page, and thus latch     *         can be released before end transaction.  Otherwise the latch     *         on the page can not be released before commit.     *     * @param page   A non-null, latched page must be passed in.  If all     *               rows on page are purged, then page will be removed and     *               latch released.     *	 * @exception  StandardException  Standard exception policy.     **/    protected final boolean purgeCommittedDeletes(    Page                page)        throws StandardException    {        boolean purgingDone = false;        // The number records that can be reclaimed is:        // total recs - recs_not_deleted        int num_possible_commit_delete =             page.recordCount() - page.nonDeletedRecordCount();        if (num_possible_commit_delete > 0)        {            // loop backward so that purges which affect the slot table             // don't affect the loop (ie. they only move records we             // have already looked at).            for (int slot_no = page.recordCount() - 1;                  slot_no >= 0;                  slot_no--)             {                boolean row_is_committed_delete =                     page.isDeletedAtSlot(slot_no);                if (row_is_committed_delete)                {                    // At this point we only know that the row is                    // deleted, not whether it is committed.                    // see if we can purge the row, by getting an                    // exclusive lock on the row.  If it is marked                    // deleted and we can get this lock, then it                    // must be a committed delete and we can purge                     // it.                    RecordHandle rh =                        page.fetchFromSlot(                            (RecordHandle) null,                            slot_no,                            RowUtil.EMPTY_ROW,                            RowUtil.EMPTY_ROW_FETCH_DESCRIPTOR,                            true);                    row_is_committed_delete =                        this.lockRowAtSlotNoWaitExclusive(rh);                    if (row_is_committed_delete)                    {                        purgingDone = true;                        page.purgeAtSlot(slot_no, 1, false);                    }                }            }        }        if (page.recordCount() == 0)        {            // Deallocate the current page with 0 rows on it.            this.removePage(page);            // removePage guarantees to unlatch the page even if an            // exception is thrown. The page is protected against reuse            // because removePage locks it with a dealloc lock, so it            // is OK to release the latch even after a purgeAtSlot is            // called.            // @see ContainerHandle#removePage            purgingDone = true;        }        return(purgingDone);    }    /**     * Insert a new row into the heap.     * <p>     * Overflow policy:     * The current heap access method implements an algorithm that optimizes     * for fetch efficiency vs. space efficiency.  A row will not be over     * flowed unless it is bigger than a page.  If it is bigger than a page     * then it's initial part will be placed on a page and then subsequent     * parts will be overflowed to other pages.     * <p>     *	 * @return The record handle of the inserted row.     *     * @param row           The row to insert.     *	 * @exception  StandardException  Standard exception policy.     **/	private RecordHandle doInsert(DataValueDescriptor[] row)		throws StandardException	{		Page page = null;        byte  insert_mode;		        RecordHandle rh;        if (SanityManager.DEBUG)        {            Heap heap = (Heap) open_conglom.getConglomerate();            // Make sure valid columns are in the list.  The RowUtil            // call is too expensive to make in a released system for            // every insert.            int invalidColumn =                 RowUtil.columnOutOfRange(                    row, null, heap.format_ids.length);            if (invalidColumn >= 0)            {                throw(StandardException.newException(                        SQLState.HEAP_TEMPLATE_MISMATCH,                        new Long(invalidColumn),                         new Long(heap.format_ids.length)));            }        }        // Get the last page that was returned for insert or the last page        // that was allocated.        page = open_conglom.getContainer().getPageForInsert(0);        if (page != null) {            // if there are 0 rows on the page allow the insert to overflow.            insert_mode =                 (page.recordCount() == 0) ?                     Page.INSERT_OVERFLOW : Page.INSERT_DEFAULT;            // Check to see if there is enough space on the page            // for the row.            rh = page.insert(row, null, insert_mode,				AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);            page.unlatch();            page = null;            // If we have found a page with enough space for the row,            // insert it and release exclusive access to the page.            if (rh != null)            {                return rh;            }        }        // If the last inserted page is now full, or RawStore have        // forgotten what it was, or the row cannot fit on the last        // inserted page, try to have rawStore get a relatively unfilled        // page.        page =             open_conglom.getContainer().getPageForInsert(                ContainerHandle.GET_PAGE_UNFILLED);        if (page != null)        {            // Do the insert all over again hoping that it will fit into            // this page, and if not, allocate a new page.            // if there are 0 rows on the page allow the insert to overflow.            insert_mode =                 (page.recordCount() == 0) ?                     Page.INSERT_OVERFLOW : Page.INSERT_DEFAULT;                        rh = page.insert(row, null, insert_mode,				AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);            page.unlatch();            page = null;            // If we have found a page with enough space for the row,            // insert it and release exclusive access to the page.            if (rh != null)            {                return rh;            }        }        page = open_conglom.getContainer().addPage();        // At this point with long rows the raw store will guarantee        // that any size row will fit on an empty page.        rh = page.insert(row, null, Page.INSERT_OVERFLOW,			AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);        page.unlatch();        page = null;        if (SanityManager.DEBUG)        {            // a null will only be returned if this page is not empty            SanityManager.ASSERT(rh != null);        }        return rh;	}	protected long load(    TransactionManager      xact_manager,    Heap                    heap,    boolean                 createConglom,    RowLocationRetRowSource rowSource)		 throws StandardException	{        long    num_rows_loaded = 0;		if (SanityManager.DEBUG)        {			SanityManager.ASSERT(open_conglom == null,				"load expects container handle to be closed on entry.");        }		// The individual rows that are inserted are not logged.  To use a		// logged interface, use insert.  RESOLVE: do we want to allow client		// to use the load interface even for logged insert?		int mode =             (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_UNLOGGED); 		// If the container is being created in the same operation, don't log		// page allocation.  		if (createConglom)			mode |= ContainerHandle.MODE_CREATE_UNLOGGED;        OpenConglomerate open_conglom = new OpenHeap();        if (open_conglom.init(                (ContainerHandle) null,                heap,                heap.format_ids,                xact_manager,                xact_manager.getRawStoreXact(),                false,                mode,                TransactionController.MODE_TABLE,                xact_manager.getRawStoreXact().newLockingPolicy(                    LockingPolicy.MODE_CONTAINER,                    TransactionController.ISOLATION_SERIALIZABLE, true),                (DynamicCompiledOpenConglomInfo) null) == null)        {            throw StandardException.newException(                    SQLState.HEAP_CONTAINER_NOT_FOUND,                     new Long(heap.id.getContainerId()));        }        this.init(open_conglom);		// For bulk loading, we always use only brand new page because the row		// insertion itself is not logged.  We cannot pollute pages with

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -