Top Description Fields Constructors Methods
org.apache.derby.impl.store.raw.data

public abstract Class CachedPage

extends BasePage
implements Cacheable
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.cache.Cacheable
Known Direct Subclasses
org.apache.derby.impl.store.raw.data.StoredPage
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.store.raw.PageKey, org.apache.derby.iapi.services.cache.Cacheable, .CacheManager, org.apache.derby.iapi.services.monitor.Monitor, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.services.io.FormatIdUtil, org.apache.derby.shared.common.error.StandardException, .ExceptionSeverity, org.apache.derby.iapi.util.InterruptStatus, java.io.IOException

A base page that is cached. Since there are multiple page formats, use this abstract class to implement cacheable interface.

Field Summary

Modifier and TypeField and Description
protected boolean
protected CacheManager
containerCache

The container cache my container lives in. MT - Immutable

private long
protected BaseDataFileFactory
dataFactory

My factory class.

protected int
protected boolean
protected static final int
protected CacheManager
pageCache

The page cache I live in. MT - Immutable

protected byte[]
protected boolean
public static final int
public static final int
Inherited from org.apache.derby.impl.store.raw.data.BasePage:
identityinCleanINIT_PAGE_OVERFLOWINIT_PAGE_REUSEINIT_PAGE_REUSE_RECORDIDINVALID_PAGELOG_RECORD_DEFAULTLOG_RECORD_FOR_PURGELOG_RECORD_FOR_UPDATEownerpreLatchVALID_PAGE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private CachedPage

Returns:

The new object created with the input fid and transfered info.
changeInstanceTo
(int
The format id of the new page.
fid
,
PageKey
The key of the new page.
newIdentity
)

Convert this page to requested type, as defined by input format id.

The current cache entry is a different format id than the requested type, change it.

public void
clean(boolean
True if the object will be removed
remove
)

Implements org.apache.derby.iapi.services.cache.Cacheable.clean.

Write the page to disk.

public void
public Cacheable

Returns:

new page, higher levels have already checked the page number is valid for an open.
createIdentity
(Object
Which page is this?
key
,
Object
details needed to create page like size, format id, ...
createParameter
)

Implements org.apache.derby.iapi.services.cache.Cacheable.createIdentity.

Find the container and then create the page in that container.

protected abstract void
protected byte[]

Returns:

The array of bytes that is the on disk version of page.
getPageArray
()

Implements abstract org.apache.derby.impl.store.raw.data.BasePage.getPageArray.

Returns the page data array used to write on disk version.

protected abstract void
protected void
public boolean

Returns:

true if changes have actually been made to the page in memory.
isActuallyDirty
()

Has the page or its header been modified.

public boolean

Returns:

true if the page is dirty.
isDirty
()

Implements org.apache.derby.iapi.services.cache.Cacheable.isDirty.

Is the page dirty?

public void
preDirty()

Implements abstract org.apache.derby.impl.store.raw.data.BasePage.preDirty.

Set state to indicate the page or its header is about to be modified.

private void
readPage(FileContainer
the container to read the page from.
myContainer
,
PageKey
indentity (ie. page number) of the page to read
newIdentity
)

read the page from disk into this CachedPage object.

protected void
releaseExclusive()

Overrides org.apache.derby.impl.store.raw.data.BasePage.releaseExclusive.

exclusive latch on page is being released.

public void
setContainerRowCount(long rowCount)

Implements abstract org.apache.derby.impl.store.raw.data.BasePage.setContainerRowCount.

Set the number of rows in the container - the page uses this to decide whether it needs to aggressive set the container's row count when it changes.

protected void
setDirty()

Set state to indicate the page or its header has been modified.

public final void
public Cacheable

Returns:

always true, higher levels have already checked the page number is valid for an open.
setIdentity
(Object
The handle on the cacheable
key
)

Implements org.apache.derby.iapi.services.cache.Cacheable.setIdentity.

Find the container and then read the page from that container.

protected void
setPageArray(int pageSize)

if the page size is different from the page buffer, then make a new page buffer and make subclass use the new page buffer

protected abstract void
usePageBuffer(byte[] buffer)

protected abstract void
private void
writePage(PageKey
indentity (ie. page number) of the page to read
identity
,
boolean
does the write of this single page have to be sync'd?
syncMe
)

write the page from this CachedPage object to disk.

protected abstract void
Inherited from org.apache.derby.impl.store.raw.data.BasePage:
allowInsertappendOverflowFieldHeaderbumpPageVersionbumpRecordCountcleanPageForReuseclearLastLogInstantcompactRecordcompactRecordcopyAndPurgedeallocatePagedeleteAtSlotdoUpdateAtSlotentireRecordOnPagefetchFieldFromSlotfetchFromSlotfetchNumFieldsfetchNumFieldsAtSlotfillInIdentityfindRecordByIdgetAuxObjectgetHeaderAtSlotgetIdentitygetInvalidRecordHandlegetLastLogInstantgetNewOverflowPagegetNextSlotNumbergetOverflowPageForInsertgetPageIdgetPageKeygetPageNumbergetPageStatusgetPageVersiongetRecordHandlegetRecordHandleAtSlotgetRecordLengthgetReservedCountgetSlotNumbergetTotalSpaceinitializeHeadersinitPageinitPageinsertinsertAllowOverflowinsertAtSlotinsertLongColumninsertNoOverflowinternalDeletedRecordCountinternalNonDeletedRecordCountisDeletedAtSlotisDeletedOnPageisLatchedisOverflowPageisRepositionNeededlogColumnlogFieldlogLongColumnlogRecordlogRowMakeRecordHandlemakeRecordHandlenewRecordIdnewRecordIdnewRecordIdAndBumpnonDeletedRecordCountpurgeAtSlotpurgeRecordpurgeRowPiecesrecordCountrecordExistsrecordHeaderOnDemandremoveAndShiftDownreserveSpaceForSlotrestorePortionLongColumnrestoreRecordFromSlotrestoreRecordFromStreamsetAuxObjectsetDeleteStatussetDeleteStatussetExclusivesetExclusiveNoWaitsetHeaderAtSlotsetPageStatussetPageStatussetPageVersionsetRepositionNeededsetReservedSpaceshiftUpshouldReclaimSpaceskipFieldskipRecordslotTableToStringspaceForCopystoreFieldstoreRecordunfilledunlatchupdateupdateAtSlotupdateFieldAtSlotupdateFieldOverflowDetailsupdateLastLogInstantupdateOverflowDetails

Field Detail

alreadyReadPageback to summary
protected boolean alreadyReadPage
containerCacheback to summary
protected CacheManager containerCache

The container cache my container lives in.
MT - Immutable

containerRowCountback to summary
private long containerRowCount
dataFactoryback to summary
protected BaseDataFileFactory dataFactory

My factory class.
MT - Immutable -

initialRowCountback to summary
protected int initialRowCount
isDirtyback to summary
protected boolean isDirty
PAGE_FORMAT_ID_SIZEback to summary
protected static final int PAGE_FORMAT_ID_SIZE
pageCacheback to summary
protected CacheManager pageCache

The page cache I live in.
MT - Immutable

pageDataback to summary
protected byte[] pageData
preDirtyback to summary
protected boolean preDirty
WRITE_NO_SYNCback to summary
public static final int WRITE_NO_SYNC
WRITE_SYNCback to summary
public static final int WRITE_SYNC

Constructor Detail

CachedPageback to summary
public CachedPage()

Method Detail

changeInstanceToback to summary
private CachedPage changeInstanceTo(int fid, PageKey newIdentity) throws StandardException

Convert this page to requested type, as defined by input format id.

The current cache entry is a different format id than the requested type, change it. This object is instantiated to the wrong subtype of cachedPage, this routine will create an object with the correct subtype, and transfer all pertinent information from this to the new correct object.

Parameters
fid:int

The format id of the new page.

newIdentity:PageKey

The key of the new page.

Returns:CachedPage

The new object created with the input fid and transfered info.

Exceptions
StandardException:
Standard exception policy.
cleanback to summary
public void clean(boolean remove) throws StandardException

Implements org.apache.derby.iapi.services.cache.Cacheable.clean.

Write the page to disk.

MP - In a simple world we would just not allow clean until it held the latch on the page. But in order to fit into the cache system, we don't have enough state around to just make clean() latch the page while doing the I/O - but we still need someway to insure that no changes happen to the page while the I/O is taking place. Also someday it would be fine to allow reads of this page while the I/O was taking place.

Parameters
remove:boolean

Doc from org.apache.derby.iapi.services.cache.Cacheable.clean.

True if the object will be removed

Exceptions
StandardException:
Error writing the page.
See Also
Cacheable#clean
clearIdentityback to summary
public void clearIdentity()

Overrides org.apache.derby.impl.store.raw.data.BasePage.clearIdentity.

Implements org.apache.derby.iapi.services.cache.Cacheable.clearIdentity.

Doc from org.apache.derby.iapi.services.cache.Cacheable.clearIdentity.

Put the object into the No Identity state.
MT - single thread required - Method must only be called be cache manager and the cache manager will guarantee only one thread can be calling it.

createIdentityback to summary
public Cacheable createIdentity(Object key, Object createParameter) throws StandardException

Implements org.apache.derby.iapi.services.cache.Cacheable.createIdentity.

Find the container and then create the page in that container.

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.

Parameters
key:Object

Which page is this?

createParameter:Object

details needed to create page like size, format id, ...

Returns:Cacheable

new page, higher levels have already checked the page number is valid for an open.

Exceptions
StandardException:
Standard exception policy.
See Also
Cacheable#createIdentity
createPageback to summary
protected abstract void createPage(PageKey id, PageCreationArgs args) throws StandardException
getPageArrayback to summary
protected byte[] getPageArray() throws StandardException

Implements abstract org.apache.derby.impl.store.raw.data.BasePage.getPageArray.

Returns the page data array used to write on disk version.

returns the page data array, that is actually written to the disk, when the page is cleaned from the page cache. Takes care of flushing in-memory information to the array (like page header and format id info).

Returns:byte[]

The array of bytes that is the on disk version of page.

Exceptions
StandardException:
Standard exception policy.
initFromDataback to summary
protected abstract void initFromData(FileContainer container, PageKey id) throws StandardException
initializeback to summary
protected void initialize()

Overrides org.apache.derby.impl.store.raw.data.BasePage.initialize.

Initialize a CachedPage.

Initialize the object, ie. perform work normally perfomed in constructor. Called by setIdentity() and createIdentity().

isActuallyDirtyback to summary
public boolean isActuallyDirty()

Has the page or its header been modified.

See comment on class header on meaning of isDirty and preDirty bits.

Returns:boolean

true if changes have actually been made to the page in memory.

isDirtyback to summary
public boolean isDirty()

Implements org.apache.derby.iapi.services.cache.Cacheable.isDirty.

Is the page dirty?

The isDirty flag indicates if the pageData or pageHeader has been modified. The preDirty flag indicates that the pageData or the pageHeader is about to be modified. The reason for these 2 flags instead of just one is to accomodate checkpoint. After a clean (latched) page sends a log record to the log stream but before that page is dirtied by the log operation, a checkpoint could be taken. If so, then the redoLWM will be after the log record but, without preDirty, the cache cleaning will not have waited for the change. So the preDirty bit is to stop the cache cleaning from skipping over this (latched) page even though it has not really been modified yet.

Returns:boolean

true if the page is dirty.

See Also
Cacheable#isDirty
preDirtyback to summary
public void preDirty()

Implements abstract org.apache.derby.impl.store.raw.data.BasePage.preDirty.

Set state to indicate the page or its header is about to be modified.

See comment on class header on meaning of isDirty and preDirty bits.

readPageback to summary
private void readPage(FileContainer myContainer, PageKey newIdentity) throws StandardException

read the page from disk into this CachedPage object.

A page is read in from disk into the pageData array of this object, and then put in the cache.

Parameters
myContainer:FileContainer

the container to read the page from.

newIdentity:PageKey

indentity (ie. page number) of the page to read

Exceptions
StandardException:
Standard exception policy.
releaseExclusiveback to summary
protected void releaseExclusive()

Overrides org.apache.derby.impl.store.raw.data.BasePage.releaseExclusive.

exclusive latch on page is being released.

The only work done in CachedPage is to update the row count on the container if it is too out of sync.

setContainerRowCountback to summary
public void setContainerRowCount(long rowCount)

Implements abstract org.apache.derby.impl.store.raw.data.BasePage.setContainerRowCount.

Doc from org.apache.derby.impl.store.raw.data.BasePage.setContainerRowCount.

Set the number of rows in the container - the page uses this to decide whether it needs to aggressive set the container's row count when it changes.

setDirtyback to summary
protected void setDirty()

Set state to indicate the page or its header has been modified.

See comment on class header on meaning of isDirty and preDirty bits.

setFactoryback to summary
public final void setFactory(BaseDataFileFactory factory)
setIdentityback to summary
public Cacheable setIdentity(Object key) throws StandardException

Implements org.apache.derby.iapi.services.cache.Cacheable.setIdentity.

Find the container and then read the page from that container.

This is the way new pages enter the page cache.

Parameters
key:Object

Doc from org.apache.derby.iapi.services.cache.Cacheable.setIdentity.

The handle on the cacheable

Returns:Cacheable

always true, higher levels have already checked the page number is valid for an open.

Exceptions
StandardException:
Standard Derby policy.
See Also
Cacheable#setIdentity
setPageArrayback to summary
protected void setPageArray(int pageSize)

if the page size is different from the page buffer, then make a new page buffer and make subclass use the new page buffer

usePageBufferback to summary
protected abstract void usePageBuffer(byte[] buffer)
writeFormatIdback to summary
protected abstract void writeFormatId(PageKey identity) throws StandardException
writePageback to summary
private void writePage(PageKey identity, boolean syncMe) throws StandardException

write the page from this CachedPage object to disk.

Parameters
identity:PageKey

indentity (ie. page number) of the page to read

syncMe:boolean

does the write of this single page have to be sync'd?

Exceptions
StandardException:
Standard exception policy.
writePageback to summary
protected abstract void writePage(PageKey id) throws StandardException