use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class D_RecordId method diag.
/**
* Return string identifying the underlying container.
* <p>
*
* @return A string of the form TABLE(conglomerate_id, container_id).
* @exception StandardException Standard Derby Error
*/
public String diag() throws StandardException {
RecordId record_id = (RecordId) diag_object;
PageKey page_key = (PageKey) record_id.getPageId();
long container_id = page_key.getContainerId().getContainerId();
long conglom_id = Long.MIN_VALUE;
String str = null;
if (conglom_id == Long.MIN_VALUE) {
str = "ROW(?, " + container_id + ", " + record_id.getPageNumber() + ", " + record_id.getId() + ")";
} else {
str = "ROW(" + conglom_id + ", " + record_id.getPageNumber() + ", " + record_id.getId() + ")";
}
return (str);
}
use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class ReclaimSpaceHelper method reclaimSpace.
/**
* Reclaim space based on work.
*/
public static int reclaimSpace(BaseDataFileFactory dataFactory, RawTransaction tran, ReclaimSpace work) throws StandardException {
if (work.reclaimWhat() == ReclaimSpace.CONTAINER)
return reclaimContainer(dataFactory, tran, work);
// Else, not reclaiming container. Get a no-wait shared lock on the
// container regardless of how the user transaction had the
// container opened.
LockingPolicy container_rlock = tran.newLockingPolicy(LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, true);
if (SanityManager.DEBUG)
SanityManager.ASSERT(container_rlock != null);
ContainerHandle containerHdl = openContainerNW(tran, container_rlock, work.getContainerId());
if (containerHdl == null) {
tran.abort();
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) {
SanityManager.DEBUG(DaemonService.DaemonTrace, " aborted " + work + " because container is locked or dropped");
}
}
if (// retry this for serveral times
work.incrAttempts() < 3) // it is however, unlikely that three tries will be
// enough because there is no delay between retries.
// See DERBY-4059 and DERBY-4055 for details.
{
return Serviceable.REQUEUE;
} else {
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) {
SanityManager.DEBUG(DaemonService.DaemonTrace, " gave up after 3 tries to get container lock " + work);
}
}
return Serviceable.DONE;
}
}
if (work.reclaimWhat() == ReclaimSpace.PAGE) {
// Reclaiming a page - called by undo of insert which purged the
// last row off an overflow page. It is safe to reclaim the page
// without first locking the head row because unlike post commit
// work, this is post abort work. Abort is guarenteed to happen
// and to happen only once, if at all.
Page p = containerHdl.getPageNoWait(work.getPageId().getPageNumber());
if (p != null)
containerHdl.removePage(p);
tran.commit();
return Serviceable.DONE;
}
// We are reclaiming row space or long column.
// First get an xlock on the head row piece.
RecordHandle headRecord = work.getHeadRowHandle();
if (!container_rlock.lockRecordForWrite(tran, headRecord, false, /* not insert */
false)) {
// cannot get the row lock, retry
tran.abort();
if (work.incrAttempts() < 3) {
return Serviceable.REQUEUE;
} else {
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) {
SanityManager.DEBUG(DaemonService.DaemonTrace, " gave up after 3 tries to get row lock " + work);
}
}
return Serviceable.DONE;
}
}
if (work.reclaimWhat() == ReclaimSpace.ROW_RESERVE) {
// This row may benefit from compaction.
containerHdl.compactRecord(headRecord);
// This work is being done - post commit, there is no user
// transaction that depends on the commit being sync'd. It is safe
// to commitNoSync() This do as one of 2 things will happen:
//
// 1) if any data page associated with this transaction is
// moved from cache to disk, then the transaction log
// must be sync'd to the log record for that change and
// all log records including the commit of this xact must
// be sync'd before returning.
//
// 2) if the data page is never written then the log record
// for the commit may never be written, and the xact will
// never make to disk. This is ok as no subsequent action
// depends on this operation being committed.
//
tran.commitNoSync(Transaction.RELEASE_LOCKS);
return Serviceable.DONE;
} else {
if (SanityManager.DEBUG)
SanityManager.ASSERT(work.reclaimWhat() == ReclaimSpace.COLUMN_CHAIN);
// Reclaiming a long column chain due to update. The long column
// chain being reclaimed is the before image of the update
// operation.
//
long headPageId = ((PageKey) headRecord.getPageId()).getPageNumber();
// DERBY-4050 - we wait for the page so we don't have to retry.
// prior to the 4050 fix, we called getPageNoWait and just
// retried 3 times. This left unreclaimed space if we were
// not successful after three tries.
StoredPage headRowPage = (StoredPage) containerHdl.getPage(headPageId);
if (headRowPage == null) {
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) {
SanityManager.DEBUG(DaemonService.DaemonTrace, "gave up because hadRowPage was null" + work);
}
}
tran.abort();
return Serviceable.DONE;
}
try {
headRowPage.removeOrphanedColumnChain(work, containerHdl);
} finally {
headRowPage.unlatch();
}
// This work is being done - post commit, there is no user
// transaction that depends on the commit being sync'd. It is safe
// to commitNoSync() This do as one of 2 things will happen:
//
// 1) if any data page associated with this transaction is
// moved from cache to disk, then the transaction log
// must be sync'd to the log record for that change and
// all log records including the commit of this xact must
// be sync'd before returning.
//
// 2) if the data page is never written then the log record
// for the commit may never be written, and the xact will
// never make to disk. This is ok as no subsequent action
// depends on this operation being committed.
//
tran.commitNoSync(Transaction.RELEASE_LOCKS);
return Serviceable.DONE;
}
}
use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class FileContainer method getAnyPage.
/**
* Get any old page - turn off all validation
*
* @exception StandardException Derby Standard error policy
*/
protected BasePage getAnyPage(BaseContainerHandle handle, long pageNumber) throws StandardException {
if (// committed and dropped, cannot get a page
getCommittedDropState())
return null;
// make sure alloc cache has no stale info
synchronized (allocCache) {
allocCache.invalidate();
}
PageKey pageSearch = new PageKey(identity, pageNumber);
BasePage page = (BasePage) pageCache.find(pageSearch);
return page;
}
use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class FileContainer method getLatchedPage.
/**
* Get a latched page. Incase of backup page Latch is necessary to
* prevent modification to the page when it is being written to the backup.
* Backup process relies on latches to get consistent snap
* shot of the page , user level table/page/row locks are NOT
* acquired by the online backup mechanism.
*
* @param handle the container handle used to latch the page
* @param pageNumber the page number of the page to get
* @return the latched page
* @exception StandardException Standard Derby error policy
*/
protected BasePage getLatchedPage(BaseContainerHandle handle, long pageNumber) throws StandardException {
PageKey pageKey = new PageKey(identity, pageNumber);
BasePage page = (BasePage) pageCache.find(pageKey);
if (SanityManager.DEBUG) {
SanityManager.ASSERT(page != null, "page is not found :" + pageKey);
}
// latch the page
page = latchPage(handle, page, true);
if (SanityManager.DEBUG) {
SanityManager.ASSERT(page.isLatched(), "page is not latched:" + pageKey);
}
return page;
}
use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class BasePage method copyInto.
/**
* Copy num_rows from srcPage, src_slot into this page starting at dest_slot.
* This is destination page of the the copy half of copy and Purge.
*
* @see Page#copyAndPurge
*/
private void copyInto(BasePage srcPage, int src_slot, int num_rows, int dest_slot) throws StandardException {
if ((dest_slot < 0) || dest_slot > recordCount) {
throw StandardException.newException(SQLState.DATA_SLOT_NOT_ON_PAGE);
}
RawTransaction t = owner.getTransaction();
// get num_rows row locks, need to predict what those recordIds will be
int[] recordIds = new int[num_rows];
// RESOLVE - MT problem ?
PageKey pageId = getPageId();
for (int i = 0; i < num_rows; i++) {
if (i == 0)
recordIds[i] = newRecordId();
else
recordIds[i] = newRecordId(recordIds[i - 1]);
RecordHandle handle = new RecordId(pageId, recordIds[i], i);
owner.getLockingPolicy().lockRecordForWrite(t, handle, false, true);
}
// RESOLVE: need try block here to invalidate self and crash the system
owner.getActionSet().actionCopyRows(t, this, srcPage, dest_slot, num_rows, src_slot, recordIds);
}
Aggregations