use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class BasePage method purgeAtSlot.
/**
* Purge one or more rows on a non-overflow page.
*
* @see Page#purgeAtSlot
* @exception StandardException Standard exception policy.
*/
public void purgeAtSlot(int slot, int numpurges, boolean needDataLogged) throws StandardException {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(isLatched());
if (isOverflowPage())
SanityManager.THROWASSERT("purge committed deletes on an overflow page. Page = " + this);
}
if (numpurges <= 0)
return;
if (!owner.updateOK()) {
throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
}
if ((slot < 0) || ((slot + numpurges) > recordCount)) {
throw StandardException.newException(SQLState.DATA_SLOT_NOT_ON_PAGE);
}
RawTransaction t = owner.getTransaction();
// lock the records to be purged
int[] recordIds = new int[numpurges];
// RESOLVE: MT problem ?
PageKey pageId = getPageId();
for (int i = 0; i < numpurges; i++) {
recordIds[i] = getHeaderAtSlot(slot + i).getId();
// get row lock on head row piece
RecordHandle handle = getRecordHandleAtSlot(slot);
owner.getLockingPolicy().lockRecordForWrite(t, handle, false, true);
if (owner.isTemporaryContainer() || entireRecordOnPage(slot + i))
continue;
// row[slot+i] has overflow rows and/or long columns, reclaim
// them in a loop.
RecordHandle headRowHandle = getHeaderAtSlot(slot + i).getHandle(pageId, slot + i);
purgeRowPieces(t, slot + i, headRowHandle, needDataLogged);
}
owner.getActionSet().actionPurge(t, this, slot, numpurges, recordIds, needDataLogged);
}
use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class CachedPage method createIdentity.
/**
* Find the container and then create the page in that container.
* <p>
* This is the process of creating a new page in a container, in that
* case no need to read the page from disk - just need to initialize it
* in the cache.
* <p>
*
* @return new page, higher levels have already checked the page number is
* valid for an open.
*
* @param key Which page is this?
* @param createParameter details needed to create page like size,
* format id, ...
*
* @exception StandardException Standard exception policy.
*
* @see Cacheable#createIdentity
*/
public Cacheable createIdentity(Object key, Object createParameter) throws StandardException {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(key instanceof PageKey);
}
initialize();
PageKey newIdentity = (PageKey) key;
PageCreationArgs createArgs = (PageCreationArgs) createParameter;
int formatId = createArgs.formatId;
if (formatId == -1) {
throw StandardException.newException(SQLState.DATA_UNKNOWN_PAGE_FORMAT_2, newIdentity, org.apache.derby.iapi.util.StringUtil.hexDump(pageData));
}
// real page object
if (formatId != getTypeFormatId()) {
return (changeInstanceTo(formatId, newIdentity).createIdentity(key, createParameter));
}
// this is the correct page instance
initializeHeaders(5);
createPage(newIdentity, createArgs);
fillInIdentity(newIdentity);
initialRowCount = 0;
/*
* if we need to grow the container and the page has not been
* preallocated, writing page before the log is written so that we
* know if there is an IO error - like running out of disk space - then
* we don't write out the log record, because if we do, it may fail
* after the log goes to disk and then the database may not be
* recoverable.
*
* WRITE_SYNC is used when we create the page without first
* preallocating it
* WRITE_NO_SYNC is used when we are preallocating the page - there
* will be a SYNC call after all the pages are preallocated
* 0 means creating a page that has already been preallocated.
*/
int syncFlag = createArgs.syncFlag;
if ((syncFlag & WRITE_SYNC) != 0 || (syncFlag & WRITE_NO_SYNC) != 0)
writePage(newIdentity, (syncFlag & WRITE_SYNC) != 0);
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON(FileContainer.SPACE_TRACE)) {
String sync = ((syncFlag & WRITE_SYNC) != 0) ? "Write_Sync" : (((syncFlag & WRITE_NO_SYNC) != 0) ? "Write_NO_Sync" : "No_write");
SanityManager.DEBUG(FileContainer.SPACE_TRACE, "creating new page " + newIdentity + " with " + sync);
}
}
return this;
}
use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class BaseContainerHandle method compactRecord.
/**
* @see ContainerHandle#compactRecord
* @exception StandardException Standard Derby error policy
*/
public void compactRecord(RecordHandle record) throws StandardException {
if (!forUpdate) {
throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
}
PageKey pkey = (PageKey) record.getPageId();
BasePage headPage = (BasePage) getPage(pkey.getPageNumber());
if (headPage != null) {
// the record may not even be there and we got a lock for nothing.
try {
headPage.compactRecord(record);
} finally {
headPage.unlatch();
}
}
}
use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class FileContainer method deallocatePagenum.
/**
* deallocate the page from the alloc page
*/
private void deallocatePagenum(BaseContainerHandle handle, long pnum) throws StandardException {
synchronized (allocCache) {
long allocPageNum = allocCache.getAllocPageNumber(handle, pnum, firstAllocPageNumber);
if (SanityManager.DEBUG) {
if (allocPageNum == ContainerHandle.INVALID_PAGE_NUMBER)
allocCache.dumpAllocationCache();
if (allocPageNum == ContainerHandle.INVALID_PAGE_NUMBER)
SanityManager.THROWASSERT("can't find alloc page for page number " + pnum);
}
// get the alloc page to deallocate this pnum
AllocPage allocPage = (AllocPage) handle.getAllocPage(allocPageNum);
if (allocPage == null) {
PageKey pkey = new PageKey(identity, allocPageNum);
throw StandardException.newException(SQLState.FILE_NO_ALLOC_PAGE, pkey);
}
try {
allocCache.invalidate(allocPage, allocPageNum);
// Unlatch alloc page. The page is protected by the dealloc
// lock.
allocPage.deallocatePage(handle, pnum);
} finally {
allocPage.unlatch();
}
}
// make sure this page gets looked at when someone needs a new page
if (pnum <= lastAllocatedPage) {
lastAllocatedPage = pnum - 1;
}
}
use of org.apache.derby.iapi.store.raw.PageKey in project derby by apache.
the class FileContainer method doPreAllocatePages.
/**
* Preallocate the pages - actually doing it, called by subclass only
*/
protected int doPreAllocatePages(long lastPreallocPagenum, int preAllocSize) {
if (SanityManager.DEBUG)
SanityManager.ASSERT(!dataFactory.isReadOnly(), "how can we be Preallocating pages in a read only database?");
// initialize and a new page in cache
PageCreationArgs createArgs = new PageCreationArgs(// default is a stored page
StoredPage.FORMAT_NUMBER, // write it but no sync
CachedPage.WRITE_NO_SYNC, pageSize, spareSpace, minimumRecordSize, 0);
StoredPage page = new StoredPage();
page.setFactory(dataFactory);
boolean error = false;
int count = 0;
while (count < preAllocSize) {
PageKey pkey = new PageKey(identity, lastPreallocPagenum + count + 1);
try {
// create Identity will do a writePage
page.createIdentity(pkey, createArgs);
// if create identity somehow failed to do a write page
if (SanityManager.DEBUG)
SanityManager.ASSERT(!page.isDirty(), "create identity failed to do a write page");
// ready the page for the next loop
page.clearIdentity();
} catch (StandardException se) {
// if something went wrong, stop and return how many we did
// successfully
error = true;
}
if (error)
break;
count++;
}
return count;
}
Aggregations