Search in sources :

Example 26 with Page

use of org.apache.derby.iapi.store.raw.Page in project derby by apache.

the class OpenConglomerate method debugConglomerate.

public void debugConglomerate() throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.DEBUG_PRINT("p_heap", "\nHEAP DUMP:containerId " + container.getId());
        // get a template.
        DataValueDescriptor[] row = runtime_mem.get_row_for_export(getRawTran());
        // Print pages of the heap.
        Page page = container.getFirstPage();
        while (page != null) {
            SanityManager.DEBUG_PRINT("p_heap", ConglomerateUtil.debugPage(page, 0, false, row));
            long pageid = page.getPageNumber();
            page.unlatch();
            page = container.getNextPage(pageid);
        }
    }
    return;
}
Also used : Page(org.apache.derby.iapi.store.raw.Page) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 27 with Page

use of org.apache.derby.iapi.store.raw.Page in project derby by apache.

the class Heap method addColumn.

/*
	** Methods of Conglomerate
	*/
/**
 * Add a column to the heap conglomerate.
 * <p>
 * This routine update's the in-memory object version of the Heap
 * Conglomerate to have one more column of the type described by the
 * input template column.
 *
 * @param column_id        The column number to add this column at.
 * @param template_column  An instance of the column to be added to table.
 * @param collation_id     Collation id of the column added.
 *
 * @exception  StandardException  Standard exception policy.
 */
public void addColumn(TransactionManager xact_manager, int column_id, Storable template_column, int collation_id) throws StandardException {
    // need to open the container and update the row containing the
    // serialized format of the heap.
    ContainerHandle container = null;
    Page page = null;
    Transaction rawtran = xact_manager.getRawStoreXact();
    try {
        container = rawtran.openContainer(id, rawtran.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true), ContainerHandle.MODE_FORUPDATE | (isTemporary() ? ContainerHandle.MODE_TEMP_IS_KEPT : 0));
        if (column_id != format_ids.length) {
            if (SanityManager.DEBUG)
                SanityManager.THROWASSERT("Expected (column_id == format_ids.length)" + "column_id = " + column_id + "format_ids.length = " + format_ids.length + "format_ids = " + format_ids);
            throw (StandardException.newException(SQLState.HEAP_TEMPLATE_MISMATCH, column_id, this.format_ids.length));
        }
        // create a new array, and copy old values to it.
        int[] old_format_ids = format_ids;
        format_ids = new int[old_format_ids.length + 1];
        System.arraycopy(old_format_ids, 0, format_ids, 0, old_format_ids.length);
        // add the new column
        format_ids[old_format_ids.length] = template_column.getTypeFormatId();
        // create a new collation array, and copy old values to it.
        int[] old_collation_ids = collation_ids;
        collation_ids = new int[old_collation_ids.length + 1];
        System.arraycopy(old_collation_ids, 0, collation_ids, 0, old_collation_ids.length);
        // add the new column's collation id.
        collation_ids[old_collation_ids.length] = collation_id;
        // row in slot 0 of heap page 1 which is just a single column with
        // the heap entry.
        DataValueDescriptor[] control_row = new DataValueDescriptor[1];
        control_row[0] = this;
        page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
        page.updateAtSlot(Page.FIRST_SLOT_NUMBER, control_row, (FormatableBitSet) null);
        page.unlatch();
        page = null;
    } finally {
        if (container != null)
            container.close();
        if (page != null)
            page.unlatch();
    }
    return;
}
Also used : Transaction(org.apache.derby.iapi.store.raw.Transaction) Page(org.apache.derby.iapi.store.raw.Page) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Example 28 with Page

use of org.apache.derby.iapi.store.raw.Page in project derby by apache.

the class Heap method create.

/* Private/Protected methods of This class: */
/**
 * Create a heap conglomerate.
 * <p>
 * Create a heap conglomerate.  This method is called from the heap factory
 * to create a new instance of a heap.
 * <p>
 *
 * @exception  StandardException  Standard exception policy.
 */
protected void create(Transaction rawtran, int segmentId, long input_containerid, DataValueDescriptor[] template, ColumnOrdering[] columnOrder, int[] collationIds, Properties properties, int conglom_format_id, int tmpFlag) throws StandardException {
    // care of in fileContainer.java: createInfoFromProp().
    if (properties != null) {
        String value = properties.getProperty(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER);
        int minimumRecordSize = (value == null) ? RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT : Integer.parseInt(value);
        if (minimumRecordSize < RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT) {
            properties.put(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER, Integer.toString(RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT));
        }
    }
    // Create a container for the heap with default page size.
    long containerid = rawtran.addContainer(segmentId, input_containerid, ContainerHandle.MODE_DEFAULT, properties, tmpFlag);
    // Make sure the container was actually created.
    if (containerid < 0) {
        throw StandardException.newException(SQLState.HEAP_CANT_CREATE_CONTAINER);
    }
    // Keep track of what segment the container's in.
    id = new ContainerKey(segmentId, containerid);
    // Heap requires a template representing every column in the table.
    if ((template == null) || (template.length == 0)) {
        throw StandardException.newException(SQLState.HEAP_COULD_NOT_CREATE_CONGLOMERATE);
    }
    // get format id's from each column in template and store it in the
    // conglomerate state.
    this.format_ids = ConglomerateUtil.createFormatIds(template);
    // copy the format id of the conglomerate.
    this.conglom_format_id = conglom_format_id;
    // get collation ids from input collation ids, store it in the
    // conglom state.
    collation_ids = ConglomerateUtil.createCollationIds(format_ids.length, collationIds);
    hasCollatedTypes = hasCollatedColumns(collation_ids);
    // need to open the container and insert the row.  Since we are
    // creating it no need to bother with locking since no one can get
    // to it until after we have created it and returned it's id.
    ContainerHandle container = null;
    Page page = null;
    try {
        container = rawtran.openContainer(id, (LockingPolicy) null, ContainerHandle.MODE_FORUPDATE | (isTemporary() ? ContainerHandle.MODE_TEMP_IS_KEPT : 0));
        // row in slot 0 of heap page 1 which is just a single column with
        // the heap entry.
        DataValueDescriptor[] control_row = new DataValueDescriptor[1];
        control_row[0] = this;
        page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
        page.insertAtSlot(Page.FIRST_SLOT_NUMBER, control_row, (FormatableBitSet) null, (LogicalUndo) null, Page.INSERT_OVERFLOW, AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);
        page.unlatch();
        page = null;
        // Don't include the control row in the estimated row count.
        container.setEstimatedRowCount(0, /* unused flag */
        0);
    } finally {
        if (container != null)
            container.close();
        if (page != null)
            page.unlatch();
    }
}
Also used : Page(org.apache.derby.iapi.store.raw.Page) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ContainerKey(org.apache.derby.iapi.store.raw.ContainerKey) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Aggregations

Page (org.apache.derby.iapi.store.raw.Page)28 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)11 ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)10 RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)9 FetchDescriptor (org.apache.derby.iapi.store.raw.FetchDescriptor)5 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)4 ContainerKey (org.apache.derby.iapi.store.raw.ContainerKey)3 Transaction (org.apache.derby.iapi.store.raw.Transaction)2 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)2 OpenConglomerate (org.apache.derby.impl.store.access.conglomerate.OpenConglomerate)2 BasePage (org.apache.derby.impl.store.raw.data.BasePage)2 Properties (java.util.Properties)1 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 DynamicCompiledOpenConglomInfo (org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo)1 TransactionManager (org.apache.derby.iapi.store.access.conglomerate.TransactionManager)1 PageKey (org.apache.derby.iapi.store.raw.PageKey)1 PageTimeStamp (org.apache.derby.iapi.store.raw.PageTimeStamp)1 RawStoreFactory (org.apache.derby.iapi.store.raw.RawStoreFactory)1 StreamContainerHandle (org.apache.derby.iapi.store.raw.StreamContainerHandle)1 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)1