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();
}
}
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();
}
}
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);
}
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);
}
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);
}
}
}
Aggregations