Search in sources :

Example 11 with ContainerKey

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

the class BaseDataFileFactory method dropStreamContainer.

/**
 *		Drop a stream container.
 *
 *	    <P><B>Synchronisation</B>
 *		<P>
 *		This call will remove the container.
 *
 *		@exception StandardException Standard Derby error policy
 */
public void dropStreamContainer(RawTransaction t, long segmentId, long containerId) throws StandardException {
    boolean tmpContainer = (segmentId == ContainerHandle.TEMPORARY_SEGMENT);
    StreamContainerHandle containerHdl = null;
    try {
        ContainerKey ckey = new ContainerKey(segmentId, containerId);
        // close all open containers and 'onCommit' objects of the container
        t.notifyObservers(ckey);
        containerHdl = t.openStreamContainer(segmentId, containerId, false);
        if (tmpContainer && (containerHdl != null)) {
            containerHdl.removeContainer();
            return;
        }
    } finally {
        if (containerHdl != null)
            containerHdl.close();
    }
}
Also used : StreamContainerHandle(org.apache.derby.iapi.store.raw.StreamContainerHandle) ContainerKey(org.apache.derby.iapi.store.raw.ContainerKey)

Example 12 with ContainerKey

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

the class LockCount method reached.

/*
	** Lock escalation related
	*/
/*
	** Methods of Limit
	*/
public void reached(CompatibilitySpace compatibilitySpace, Object group, int limit, Enumeration lockList, int lockCount) throws StandardException {
    // Count row locks by table
    Dictionary<ContainerKey, LockCount> containers = new java.util.Hashtable<ContainerKey, LockCount>();
    for (; lockList.hasMoreElements(); ) {
        Object plainLock = lockList.nextElement();
        if (!(plainLock instanceof RecordHandle)) {
            // only interested in rows locks
            continue;
        }
        ContainerKey ckey = ((RecordHandle) plainLock).getContainerId();
        LockCount lc = (LockCount) containers.get(ckey);
        if (lc == null) {
            lc = new LockCount();
            containers.put(ckey, lc);
        }
        lc.count++;
    }
    // Determine the threshold for lock escalation
    // based upon our own limit, not the current count
    int threshold = limit / (containers.size() + 1);
    if (threshold < (limit / 4))
        threshold = limit / 4;
    // try to table lock all tables that are above
    // this threshold
    boolean didEscalate = false;
    for (Enumeration<ContainerKey> e = containers.keys(); e.hasMoreElements(); ) {
        ContainerKey ckey = e.nextElement();
        LockCount lc = containers.get(ckey);
        if (lc.count < threshold) {
            continue;
        }
        try {
            if (openContainer(ckey, new RowLocking3Escalate(getLockFactory()), ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY | ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_LOCK_NOWAIT) != null) {
                didEscalate = true;
            }
        } catch (StandardException se) {
            if (!se.isLockTimeout()) {
                // just fall through.
                throw se;
            }
        }
    }
    // of BaseContainerHandle look for its ContainerKey within it.
    if (didEscalate) {
        notifyObservers(LOCK_ESCALATE);
        checkObserverException();
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) RecordHandle(org.apache.derby.iapi.store.raw.RecordHandle) ContainerKey(org.apache.derby.iapi.store.raw.ContainerKey)

Example 13 with ContainerKey

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

the class PageKey method read.

public static PageKey read(ObjectInput in) throws IOException {
    ContainerKey c = ContainerKey.read(in);
    long pn = CompressedNumber.readLong(in);
    return new PageKey(c, pn);
}
Also used : ContainerKey(org.apache.derby.iapi.store.raw.ContainerKey)

Example 14 with ContainerKey

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

the class BTree method readExternal.

/**
 *	Restore the in-memory representation from the stream.
 *
 *	@exception ClassNotFoundException Thrown if the stored representation is
 *	serialized and a class named in the stream could not be found.
 *
 *    @exception IOException thrown by readObject()
 *
 *	@see java.io.Externalizable#readExternal
 */
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    // read in the conglomerate format id.
    conglom_format_id = FormatIdUtil.readFormatIdInteger(in);
    // XXX (nat) need to improve error handling
    long containerid = in.readLong();
    int segmentid = in.readInt();
    nKeyFields = in.readInt();
    nUniqueColumns = in.readInt();
    allowDuplicates = in.readBoolean();
    maintainParentLinks = in.readBoolean();
    // read in the array of format id's
    format_ids = ConglomerateUtil.readFormatIdArray(this.nKeyFields, in);
    id = new ContainerKey(segmentid, containerid);
}
Also used : ContainerKey(org.apache.derby.iapi.store.raw.ContainerKey)

Example 15 with ContainerKey

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

the class Heap method readExternal.

/**
 * Restore the in-memory representation from the stream.
 * <p>
 *
 * @exception ClassNotFoundException Thrown if the stored representation
 *                                   is serialized and a class named in
 *                                   the stream could not be found.
 *
 * @see java.io.Externalizable#readExternal
 */
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    // read the format id of this conglomerate.
    conglom_format_id = 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);
    // In memory maintain a collation id per column in the template.
    collation_ids = new int[format_ids.length];
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(!hasCollatedTypes);
    }
    // this is the default and no resetting is necessary.
    for (int i = 0; i < format_ids.length; i++) collation_ids[i] = StringDataValue.COLLATION_TYPE_UCS_BASIC;
    if (conglom_format_id == StoredFormatIds.ACCESS_HEAP_V3_ID) {
        // current format id, read collation info from disk
        hasCollatedTypes = ConglomerateUtil.readCollationIdArray(collation_ids, in);
    } else if (conglom_format_id != StoredFormatIds.ACCESS_HEAP_V2_ID) {
        if (SanityManager.DEBUG) {
            SanityManager.THROWASSERT("Unexpected format id: " + conglom_format_id);
        }
    }
}
Also used : ContainerKey(org.apache.derby.iapi.store.raw.ContainerKey)

Aggregations

ContainerKey (org.apache.derby.iapi.store.raw.ContainerKey)16 ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)4 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)3 Page (org.apache.derby.iapi.store.raw.Page)3 StreamContainerHandle (org.apache.derby.iapi.store.raw.StreamContainerHandle)3 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)2 StandardException (org.apache.derby.shared.common.error.StandardException)2 RawStoreFactory (org.apache.derby.iapi.store.raw.RawStoreFactory)1 RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)1 Transaction (org.apache.derby.iapi.store.raw.Transaction)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1