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

public Class AllocPage

extends StoredPage
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.io.TypedFormat, .FormatIdUtil, .StoredFormatIds, .ArrayInputStream, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.raw.ContainerHandle, .Loggable, .PageKey, .PageTimeStamp, .RawStoreFactory, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.store.raw.xact.RawTransaction, org.apache.derby.impl.store.raw.data.BaseContainerHandle, .BasePage, .PageVersion, java.io.IOException, .ObjectOutput, .ObjectInput

An allocation page of the file container.

This class extends a normal Stored page, with the exception that a hunk of space may be 'borrowed' by the file container to store the file header.

The borrowed space is not visible to the alloc page even though it is present in the page data array. It is accessed directly by the FileContainer. Any change made to the borrowed space is not managed or seen by the allocation page.

The reason for having this borrowed space is so that the container header does not need to have a page of its own.

Page Format
An allocation page extends a stored page, the on disk format is different from a stored page in that N bytes are 'borrowed' by the container and the page header of an allocation page will be slightly bigger than a normal stored page. This N bytes are stored between the page header and the record space.

The reason why this N bytes can't simply be a row is because it needs to be statically accessible by the container object to avoid a chicken and egg problem of the container object needing to instantiate an alloc page object before it can be objectified, and an alloc page object needing to instantiate a container object before it can be objectified. So this N bytes must be stored outside of the normal record interface yet it must be settable because only the first alloc page has this borrowed space. Other (non-first) alloc page have N == 0.

                             [ borrowed ]
	+----------+-------------+---+---------+-------------------+-------------+--------+
	| FormatId | page header | N | N bytes | alloc extend rows | slot offset |checksum|
	+----------+-------------+---+---------+-------------------+-------------+--------+
	
N is a byte that indicates the size of the borrowed space. Once an alloc page is initialized, the value of N cannot change.

The maximum space that can be borrowed by the container is 256 bytes.

The allocation page are of the same page size as any other pages in the container. The first allocation page of the FileContainer starts at the first physical byte of the container. Subsequent allocation pages are chained via the nextAllocPageOffset. Each allocation page is expected to manage at least 1000 user pages (for 1K page size) so this chaining may not be a severe performance hit. The logical -> physical mapping of an allocation page is stored in the previous allocation page. The container object will need to maintain this mapping.

The following fields are stored in the page header

See Also
AllocExtent

Field Summary

Modifier and TypeField and Description
protected static final int
protected static final int
protected static final int
protected static final int
private int
private AllocExtent
public static final int
protected static final int
private long
nextAllocPageNumber

alloc page header

private long
private long
private long
private long
private long
public static final String
TEST_MULTIPLE_ALLOC_PAGE

Extent Testing Use these strings to simulate error conditions for testing purposes.

Inherited from org.apache.derby.impl.store.raw.data.StoredPage:
bhCHECKSUM_SIZECOLUMN_CREATE_NULLCOLUMN_FIRSTCOLUMN_LONGCOLUMN_NONEfreeSpaceLARGE_SLOT_SIZElogicalDataOutminimumRecordSizeOVERFLOW_POINTER_SIZEOVERFLOW_PTR_FIELD_SIZEPAGE_HEADER_OFFSETPAGE_HEADER_SIZEPAGE_VERSION_OFFSETrawDataInrawDataOutRECORD_SPACE_OFFSETSMALL_SLOT_SIZEspareSpacetotalSpace

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addPage(FileContainer
(future) allows the alloc page to call back to the container to grow the container by creating and syncing multiple pages at once
mycontainer
,
long newPageNumber, RawTransaction
the nested top action that is the allocation transaction. NTT will comit before the user transaction
ntt
,
BaseContainerHandle
the container handle that is opened by the user transaction. Use the userHandle to latch the new page so that it may remain latched after NTT is committed so the user transaction can guarentee to have an empty page
userHandle
)

Add a page which is managed by this alloc page.

public boolean
canAddFreePage(long lastAllocatedPage)

public void
chainNewAllocPage(BaseContainerHandle allocHandle, long newAllocPageNum, long newAllocPageOffset)

protected void
chainNextAllocPage(LogInstant instant, long newAllocPageNum, long newAllocPageOffset)

Chain the next page number and offset underneath a log record

protected boolean
compress(RawTransaction ntt, FileContainer myContainer)

compress out empty pages at end of container.

protected void
compressSpace(LogInstant
log address for this operation.
instant
,
int
The new highest page on this allocation page. The number is the offset of the page in the array of pages maintained by this allocation page, for instance a value of 0 indicates all page except the first one are to be truncated. If all pages are truncated then the offset is set to -1.
new_highest_page
,
int
The number of allocated pages in this allocation page prior to the truncate. Note that all pages from NewHighestPage+1 through newHighestPage+num_pages_truncated should be FREE.
num_pages_truncated
)

Compress free pages.

private AllocExtent
createExtent(long pageNum, int pageSize, int pagesAlloced, int availspace)

protected void
createPage(PageKey
The key describing page (segment,container,page).
newIdentity
,
PageCreationArgs
information stored about the page, once in the container header and passed in through the object.
args
)

Overrides org.apache.derby.impl.store.raw.data.StoredPage.createPage.

Create a new alloc page.

public void
deallocatePage(BaseContainerHandle userHandle, long pageNumber)

protected AllocExtent
getAllocExtent()

Return a copy of the allocExtent to be cached by the container.

public long
protected long
protected int
getMaxFreeSpace()

Overrides org.apache.derby.impl.store.raw.data.StoredPage.getMaxFreeSpace.

The maximum free space on this page possible.

public long
public long
public long
protected int
getPageStatus(long pageNumber)

public int
protected void
initFromData(FileContainer
The container to read the page in from.
myContainer
,
PageKey
The key representing page being read in (segment, container, page number)
newIdentity
)

Overrides org.apache.derby.impl.store.raw.data.StoredPage.initFromData.

Initialize in memory structure using the buffer in pageData

public boolean
public long
nextFreePageNumber(long pnum)

Return the next free page number after given page number

protected void
preAllocatePage(FileContainer
the container object
myContainer
,
int
start preallocating after this threshold
preAllocThreshold
,
int
preallocate this number of pages
preAllocSize
)

Preallocate user page if needed.

private void
public static void
ReadContainerInfo(byte[]
where to put the extracted information
containerInfo
,
byte[]
the allocation page which has the container information. Epage may not be fully formed, but is guarenteed to be big enough to cover the area inhibited by the container info
epage
)

Extract the container information from epage.

private AllocExtent
readExtent(int offset)

protected void
setPageStatus(LogInstant instant, long pageNumber, int newStatus)

Do the actual page allocation/deallocation/ree underneath a log operation.

public String
protected void
undoCompressSpace(LogInstant instant, int new_highest_page, int num_pages_truncated)

Handle undo of compress space operation.

private void
protected void
public static void
WriteContainerInfo(byte[]
the container information
containerInfo
,
byte[]
the allocation page data which may not be fully formed, but is guarenteed to be big enough to cover the area inhibited by the container info
epage
,
boolean
if create, write out the length of the container info also. Else check to make sure epage's original container info is of the same length
create
)

Write the container information into the container information area.

private void
writeExtent(int offset)

protected void
writePage(PageKey
The key of this page.
identity
)

Overrides org.apache.derby.impl.store.raw.data.StoredPage.writePage.

Write the page out

Inherited from org.apache.derby.impl.store.raw.data.StoredPage:
allowInsertappendOverflowFieldHeaderclearSectioncompactRecordcurrentTimeStampdoUpdateAtSlotentireRecordOnPageequalTimeStampexpandPagefetchNumFieldsAtSlotgetCurrentFreeSpacegetIsOverflowgetNewOverflowPagegetOverflowPagegetOverflowPageForInsertgetOverflowPageForInsertgetOverflowSlotgetPageDumpStringgetPageSizegetRecordLengthgetRecordPortionLengthgetReservedCountgetSlotsInUsegetTotalSpaceinitializeinitPageinsertAtSlotinternalDeletedRecordCountisOverflowPagelogActionlogColumnlogFieldlogLongColumnlogRecordlogRowmoveRecordForCompressAtSlotnewRecordIdnewRecordIdnewRecordIdAndBumppurgeOverflowAtSlotpurgeRecordpurgeRowPiecesrecordHeaderOnDemandreleaseExclusiveremoveOrphanedColumnChainreserveSpaceForSlotrestorePortionLongColumnrestoreRecordFromSlotrestoreRecordFromStreamsetDeleteStatussetPageStatussetReservedSpacesetTimeStampskipFieldskipRecordspaceForCopyspaceForCopyspaceForInsertspaceForInsertstoreFieldstoreRecordtoUncheckedStringunfilledupdateChecksumupdateFieldAtSlotupdateFieldOverflowDetailsupdateOverflowDetailsupdateOverflowedusePageBuffervalidateChecksumwriteFormatId

Field Detail

ALLOC_PAGE_HEADER_OFFSETback to summary
protected static final int ALLOC_PAGE_HEADER_OFFSET

constants

ALLOC_PAGE_HEADER_SIZEback to summary
protected static final int ALLOC_PAGE_HEADER_SIZE
BORROWED_SPACE_LENback to summary
protected static final int BORROWED_SPACE_LEN
BORROWED_SPACE_OFFSETback to summary
protected static final int BORROWED_SPACE_OFFSET
borrowedSpaceback to summary
private int borrowedSpace
extentback to summary
private AllocExtent extent
FORMAT_NUMBERback to summary
public static final int FORMAT_NUMBER

Hides org.apache.derby.impl.store.raw.data.StoredPage.FORMAT_NUMBER.

MAX_BORROWED_SPACEback to summary
protected static final int MAX_BORROWED_SPACE
nextAllocPageNumberback to summary
private long nextAllocPageNumber

alloc page header

nextAllocPageOffsetback to summary
private long nextAllocPageOffset
reserved1back to summary
private long reserved1
reserved2back to summary
private long reserved2
reserved3back to summary
private long reserved3
reserved4back to summary
private long reserved4
TEST_MULTIPLE_ALLOC_PAGEback to summary
public static final String TEST_MULTIPLE_ALLOC_PAGE

Extent Testing Use these strings to simulate error conditions for testing purposes.

Constructor Detail

AllocPageback to summary
public AllocPage()

Method Detail

addPageback to summary
public void addPage(FileContainer mycontainer, long newPageNumber, RawTransaction ntt, BaseContainerHandle userHandle) throws StandardException

Add a page which is managed by this alloc page. Return the page number of the newly added page.
MT - thread aware (latched)

Parameters
mycontainer:FileContainer

(future) allows the alloc page to call back to the container to grow the container by creating and syncing multiple pages at once

ntt:RawTransaction

the nested top action that is the allocation transaction. NTT will comit before the user transaction

userHandle:BaseContainerHandle

the container handle that is opened by the user transaction. Use the userHandle to latch the new page so that it may remain latched after NTT is committed so the user transaction can guarentee to have an empty page

Exceptions
StandardException:
If the page cannot be added
canAddFreePageback to summary
public boolean canAddFreePage(long lastAllocatedPage)
chainNewAllocPageback to summary
public void chainNewAllocPage(BaseContainerHandle allocHandle, long newAllocPageNum, long newAllocPageOffset) throws StandardException
chainNextAllocPageback to summary
protected void chainNextAllocPage(LogInstant instant, long newAllocPageNum, long newAllocPageOffset) throws StandardException

Chain the next page number and offset underneath a log record

Exceptions
StandardException:
Standard Derby error policy
compressback to summary
protected boolean compress(RawTransaction ntt, FileContainer myContainer) throws StandardException

compress out empty pages at end of container.

Call the extent to update the data structure make the bit map look like contiguous free pages at the end of the extent no longer exist. Similar to preallocate do the operation unlogged, need to force the change to the extent before actually removing the space from the file.

The sequence is: 1) update extent data structure 2) force extent changes to disk 3) truncate pages If the system crashes between 1 and 2 then no changes are on disk. If the system crashes between 2 and 3 then there are extra pages in the file that extent does not know about, this is the same case as preallocation which the code already handes. It will handle any set of pages from 0 to all of the intended pages being truncated. The next allocate looks at actual size of file as does the right thing.

MT - expect Container level X lock

Exceptions
StandardException:
Standard exception policy.
compressSpaceback to summary
protected void compressSpace(LogInstant instant, int new_highest_page, int num_pages_truncated) throws StandardException

Compress free pages.

Compress the free pages at the end of the range maintained by this allocation page. All pages being compressed should be FREE. Only pages in the last allocation page can be compressed.

Parameters
instant:LogInstant

log address for this operation.

new_highest_page:int

The new highest page on this allocation page. The number is the offset of the page in the array of pages maintained by this allocation page, for instance a value of 0 indicates all page except the first one are to be truncated. If all pages are truncated then the offset is set to -1.

num_pages_truncated:int

The number of allocated pages in this allocation page prior to the truncate. Note that all pages from NewHighestPage+1 through newHighestPage+num_pages_truncated should be FREE.

Exceptions
StandardException:
Standard exception policy.
createExtentback to summary
private AllocExtent createExtent(long pageNum, int pageSize, int pagesAlloced, int availspace)
createPageback to summary
protected void createPage(PageKey newIdentity, PageCreationArgs args) throws StandardException

Overrides org.apache.derby.impl.store.raw.data.StoredPage.createPage.

Create a new alloc page.

Parameters
newIdentity:PageKey

Doc from org.apache.derby.impl.store.raw.data.StoredPage.createPage.

The key describing page (segment,container,page).

args:PageCreationArgs

Doc from org.apache.derby.impl.store.raw.data.StoredPage.createPage.

information stored about the page, once in the container header and passed in through the object.

Exceptions
StandardException:
Standard exception policy.
deallocatePageback to summary
public void deallocatePage(BaseContainerHandle userHandle, long pageNumber) throws StandardException
getAllocExtentback to summary
protected AllocExtent getAllocExtent()

Return a copy of the allocExtent to be cached by the container. the container must take care to maintain its coherency by invalidating the cache before any update.

getLastPagenumback to summary
public long getLastPagenum()
getLastPreallocPagenumback to summary
protected long getLastPreallocPagenum()
getMaxFreeSpaceback to summary
protected int getMaxFreeSpace()

Overrides org.apache.derby.impl.store.raw.data.StoredPage.getMaxFreeSpace.

Doc from org.apache.derby.impl.store.raw.data.StoredPage.getMaxFreeSpace.

The maximum free space on this page possible.

The the maximum amount of space that can be used on the page for the records and the slot offset table.

Note

subclass may have overwitten it to report less freeSpace

Returns:int

the maximum free space on this page possible.

getMaxPagenumback to summary
public long getMaxPagenum()
getNextAllocPageNumberback to summary
public long getNextAllocPageNumber()
getNextAllocPageOffsetback to summary
public long getNextAllocPageOffset()
getPageStatusback to summary
protected int getPageStatus(long pageNumber)
getTypeFormatIdback to summary
public int getTypeFormatId()

Overrides org.apache.derby.impl.store.raw.data.StoredPage.getTypeFormatId.

Implements org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

Return my format identifier.

Returns:int

Doc from org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

The identifier. (A UUID stuffed in an array of 16 bytes).

initFromDataback to summary
protected void initFromData(FileContainer myContainer, PageKey newIdentity) throws StandardException

Overrides org.apache.derby.impl.store.raw.data.StoredPage.initFromData.

Initialize in memory structure using the buffer in pageData

Parameters
myContainer:FileContainer

Doc from org.apache.derby.impl.store.raw.data.StoredPage.initFromData.

The container to read the page in from.

newIdentity:PageKey

Doc from org.apache.derby.impl.store.raw.data.StoredPage.initFromData.

The key representing page being read in (segment, container, page number)

Exceptions
StandardException:
If the page cannot be read correctly, or is inconsistent.
isLastback to summary
public boolean isLast()
nextFreePageNumberback to summary
public long nextFreePageNumber(long pnum)

Return the next free page number after given page number

preAllocatePageback to summary
protected void preAllocatePage(FileContainer myContainer, int preAllocThreshold, int preAllocSize)

Preallocate user page if needed.

Parameters
myContainer:FileContainer

the container object

preAllocThreshold:int

start preallocating after this threshold

preAllocSize:int

preallocate this number of pages

readAllocPageHeaderback to summary
private void readAllocPageHeader() throws IOException
ReadContainerInfoback to summary
public static void ReadContainerInfo(byte[] containerInfo, byte[] epage) throws StandardException

Extract the container information from epage.

Parameters
containerInfo:byte[]

where to put the extracted information

epage:byte[]

the allocation page which has the container information. Epage may not be fully formed, but is guarenteed to be big enough to cover the area inhibited by the container info

readExtentback to summary
private AllocExtent readExtent(int offset) throws IOException, ClassNotFoundException
setPageStatusback to summary
protected void setPageStatus(LogInstant instant, long pageNumber, int newStatus) throws StandardException

Do the actual page allocation/deallocation/ree underneath a log operation. Change the page status to new status

Exceptions
StandardException:
If the page cannot be allocated
toStringback to summary
public String toString()

Overrides org.apache.derby.impl.store.raw.data.StoredPage.toString.

Doc from org.apache.derby.impl.store.raw.data.StoredPage.toString.

debugging, print this page

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

undoCompressSpaceback to summary
protected void undoCompressSpace(LogInstant instant, int new_highest_page, int num_pages_truncated) throws StandardException

Handle undo of compress space operation.

updateAllocPageHeaderback to summary
private void updateAllocPageHeader() throws IOException
updateUnfilledPageInfoback to summary
protected void updateUnfilledPageInfo(AllocExtent inputExtent)
WriteContainerInfoback to summary
public static void WriteContainerInfo(byte[] containerInfo, byte[] epage, boolean create) throws StandardException

Write the container information into the container information area.

Parameters
containerInfo:byte[]

the container information

epage:byte[]

the allocation page data which may not be fully formed, but is guarenteed to be big enough to cover the area inhibited by the container info

create:boolean

if create, write out the length of the container info also. Else check to make sure epage's original container info is of the same length

Exceptions
StandardException:
standard Derby error policy
writeExtentback to summary
private void writeExtent(int offset) throws IOException
writePageback to summary
protected void writePage(PageKey identity) throws StandardException

Overrides org.apache.derby.impl.store.raw.data.StoredPage.writePage.

Write the page out

Parameters
identity:PageKey

Doc from org.apache.derby.impl.store.raw.data.StoredPage.writePage.

The key of this page.

Exceptions
StandardException:
If the page cannot be written