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

pack-priv abstract Class BasePage

extends Object
implements Page, DerbyObserver, TypedFormat
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.io.TypedFormat, org.apache.derby.iapi.services.monitor.DerbyObserver, org.apache.derby.iapi.store.raw.Page
Known Direct Subclasses
org.apache.derby.impl.store.raw.data.CachedPage
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.io.FormatableBitSet, .DynamicByteArrayOutputStream, .LimitObjectInput, .TypedFormat, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.services.monitor.DerbyObservable, .DerbyObserver, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.raw.AuxObject, .ContainerHandle, .ContainerKey, .FetchDescriptor, .Page, .PageKey, .RecordHandle, org.apache.derby.iapi.store.raw.xact.RawTransaction, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.store.access.conglomerate.LogicalUndo, org.apache.derby.iapi.util.InterruptStatus, java.io.IOException, .OutputStream, .ObjectInput

This class implements all the the generic locking behaviour for a Page. It leaves method used to log and store the records up to sub-classes. It is intended that the object can represent multiple pages from different containers during its lifetime.

A page contains a set of records, which can be accessed by "slot", which defines the order of the records on the page, or by "id" which defines the identity of the records on the page. Clients access records by both slot and id, depending on their needs.

BasePage implements Observer to watch the ContainerHandle which notifies its Observers when it is closing.
MT - mutable

Field Summary

Modifier and TypeField and Description
private AuxObject
auxObj

auxiliary object MT - mutable - content dynamic : single thread required.

private StoredRecordHeader[]
headers

In-memory slot table, array of StoredRecordHeaders.

protected PageKey
identity

this page's identity MT - immutable - content dynamic : single thread required

protected boolean
public static final int
public static final int
INIT_PAGE_REUSE

Init page flag.

public static final int
public static final byte
private static final RecordHandle
private LogInstant
lastLog

Instant of last log record that updated this page.

public static final int
LOG_RECORD_DEFAULT

Log Record flag.

public static final int
public static final int
private int
nestedLatch

Count of times a latch is held nested during an abort

protected BaseContainerHandle
owner

Page owner during exclusive access.

private byte
pageStatus

Status of the page

private long
pageVersion

Version of the page.

protected boolean
preLatch

Used to determine latch state of a page.

private int
private long
repositionNeededAfterVersion

The oldest version where we know that any record id that was on the page at that version, must still be on the page.

public static final byte
VALID_PAGE

Values for pageStatus flag page goes thru the following transition: VALID_PAGE <-> deallocated page -> free page <-> VALID_PAGE deallocated and free page are both INVALID_PAGE as far as BasePage is concerned.

Constructor Summary

AccessConstructor and Description
protected
BasePage()

Create a new, empty page.

Method Summary

Modifier and TypeMethod and Description
public abstract boolean
allowInsert()

Returns false if an insert is not to be allowed in the page.

public abstract int
appendOverflowFieldHeader(DynamicByteArrayOutputStream
The buffer that contains the partially logged row.
logBuffer
,
RecordHandle
the overflow (continuation) pointer to the beginning of the long column
overflowHandle
)

Append an overflow pointer to a partly logged row, to point to a long column that just been logged.

protected final long
bumpPageVersion()

increment the version by one and return the new version.

protected final void
bumpRecordCount(int number)

private final void
checkSlotOnPage(int slot)

Is the given slot number on the page?

protected void
cleanPageForReuse()

Initialized this page for reuse or first use

public void
protected final void
public void
compactRecord(RecordHandle
Handle to deleted or non-deleted record
handle
)

Try to compact this record.

protected abstract void
compactRecord(RawTransaction t, int slot, int recordId)

Subclass implementation of compactRecord.

public void
copyAndPurge(Page
the page to copy to
destPage
,
int
start copying from this slot
src_slot
,
int
copy and purge this many rows from this page
num_rows
,
int
copying into this slot of destPage
dest_slot
)

Implements org.apache.derby.iapi.store.raw.Page.copyAndPurge.

move rows from one page to another, purging in the process.

private void
copyInto(BasePage srcPage, int src_slot, int num_rows, int dest_slot)

Copy num_rows from srcPage, src_slot into this page starting at dest_slot.

public void
deallocatePage()

Mark this page as being deallocated

public RecordHandle
deleteAtSlot(int
the slot number
slot
,
boolean
true if this record is to be deleted, false if this deleted record is to be marked undeleted
delete
,
LogicalUndo
logical undo logic if necessary
undo
)

Implements org.apache.derby.iapi.store.raw.Page.deleteAtSlot.

Mark the record at slot as deleted or undeleted according to delete flag.

public abstract void
doUpdateAtSlot(RawTransaction t, int slot, int id, Object[] row, FormatableBitSet validColumns)

public abstract boolean
entireRecordOnPage(int slot)

Returns true if the entire record of that slot fits inside of this page.

public final RecordHandle
fetchFieldFromSlot(int
is the slot number
slot
,
int
is the column id
fieldId
,
Object
is to be filled in with information from the record.
column
)

Implements org.apache.derby.iapi.store.raw.Page.fetchFieldFromSlot.

Fetch a single field from a deleted or non-deleted record.

public RecordHandle
fetchFromSlot(RecordHandle
the record handle of the row. If non-null it must refer to the same record as the slot.
rh
,
int
the slot number
slot
,
Object[]
Row to be filled in with information from record.
row
,
FetchDescriptor
A structure to efficiently carry a set of parameters needed to describe the fetch, these include: validColumns - A bit map of which columns in the row to be fetched. ValidColumns will not be changed by RawStore. qualifier_list - A list of Qualifiers to apply to the row to see if the row should be returned. An array of qualifiers which restrict whether or not the row should be returned by the fetch. Rows for which any one of the qualifiers returns false are not returned by the fetch. If null, no qualification is done and the requested columns of the rows are returned. Qualifiers can only reference columns which are included in the scanColumnList. The column id that a qualifier returns is the column id the table, not the column id in the partial row being returned. qualifier_scratch_space - An array of int's that matches the size of the row[] array. Used to process qualifiers, if no qualifiers are input then array need not be input. Passed in rather than allocated so that space can be allocated a single time in a scan. If not passed in then raw store will allocate and deallocate per call.
fetchDesc
,
boolean
if true, return row regardless of whether it is deleted or not. If false, only return non-deleted row.
ignoreDelete
)

Implements org.apache.derby.iapi.store.raw.Page.fetchFromSlot.

Fetch a record located in the passed in slot.

public final int
fetchNumFields(RecordHandle
record handle to deleted or non-deleted record
handle
)

Implements org.apache.derby.iapi.store.raw.Page.fetchNumFields.

Fetch the number of fields in a record.

public int
fetchNumFieldsAtSlot(int
is the slot number
slot
)

Implements org.apache.derby.iapi.store.raw.Page.fetchNumFieldsAtSlot.

Fetch the number of fields in a record.

protected void
private int
findNextRecordById(int
record id of the first record on the page with a record id higher than the one passed in. If no such record exists, -1 is returned.
recordId
)

Find the slot for the first record on the page with an id greater than the passed in identifier.

public int
findRecordById(int
record id of the record to search for.
recordId
,
int
"hint" about which slot the record might be in.
slotHint
)

Find the slot for the record with the passed in identifier.

public AuxObject
public final StoredRecordHeader
getHeaderAtSlot(int slot)

public Object
getIdentity()

OK to hand object outside to cache..

public final RecordHandle
public final LogInstant
protected abstract BasePage
public final int
getNextSlotNumber(RecordHandle
record handle to find the next higher id.
handle
)

Implements org.apache.derby.iapi.store.raw.Page.getNextSlotNumber.

Find slot for record with an id greater than the passed in identifier.

public abstract BasePage
getOverflowPageForInsert(int slot, Object[] row, FormatableBitSet validColumns, int startColumn)

protected abstract byte[]
public final PageKey
getPageId()

Get the Page identifer MT - RESOLVE

public final PageKey
getPageKey()

Implements org.apache.derby.iapi.store.raw.Page.getPageKey.

Return the page key of this page.

public final long
getPageNumber()

Implements org.apache.derby.iapi.store.raw.Page.getPageNumber.

Return the page number of this page.

public byte
getPageStatus()

Get the page status, one of the values in the above page status flag

public final long
getPageVersion()

Implements org.apache.derby.iapi.store.raw.Page.getPageVersion.

Return the current page version.

public final RecordHandle
getRecordHandle(int
previously stored recordId.
recordId
)

Implements org.apache.derby.iapi.store.raw.Page.getRecordHandle.

Get a record handle from a previously stored record id.

Get a record handle from a previously stored record identifier that was obtained from a RecordHandle.

public final RecordHandle
getRecordHandleAtSlot(int
the slot number
slot
)

Implements org.apache.derby.iapi.store.raw.Page.getRecordHandleAtSlot.

Get the record handle of row at slot.

public abstract int
getRecordLength(int slot)

Get the stored length of a record.

public abstract int
getReservedCount(int slot)

Return the total number of bytes reserved by the record at this slot.

public final int
getSlotNumber(RecordHandle
the record handle
handle
)

Implements org.apache.derby.iapi.store.raw.Page.getSlotNumber.

Get the slot number.

public abstract int
getTotalSpace(int slot)

Return the total number of bytes used, reserved, or wasted by the record at this slot.

protected void
initialize()

Initialized the BasePage.

protected void
initializeHeaders(int numRecords)

Must be called by a sub-class before calling setHeaderAtSlot.

public void
initPage(int initFlag, long pageOffset)

Mark this page as being allocated and initialize it to a pristine page

public abstract void
initPage(LogInstant instant, byte status, int recordId, boolean overflow, boolean reuse)

initialize a page for the first time or for reuse All subtypes are expected to overwrite this method if it has something to clean up

public final RecordHandle
insert(Object[]
The row version of the data
row
,
FormatableBitSet
a bit map of which columns in the row is valid. ValidColumns will not be changed by RawStore.
validColumns
,
byte
see values for insertFlag below.
insertFlag
,
int overflowThreshold)

Implements org.apache.derby.iapi.store.raw.Page.insert.

Insert a record anywhere on the page.

public RecordHandle
insertAllowOverflow(int slot, Object[] row, FormatableBitSet validColumns, int startColumn, byte insertFlag, int overflowThreshold, RecordHandle nextPortionHandle)

Insert a row allowing overflow.

public RecordHandle
insertAtSlot(int
The specified slot
slot
,
Object[]
The row version of the data
row
,
FormatableBitSet
a bit map of which columns in the row is valid. ValidColumns will not be changed by RawStore.
validColumns
,
LogicalUndo
if logical undo may be necessary, a function pointer to the access code where the logical undo logic resides. Null if logical undo is not necessary.
undo
,
byte
if INSERT_UNDO_WITH_PURGE set, then the undo of this insert will purge the row rather than mark it as deleted, which is the default bahavior for insertAtSlot and insert.
insertFlag
,
int overflowThreshold)

Implements org.apache.derby.iapi.store.raw.Page.insertAtSlot.

Insert a record at the specified slot.

protected RecordHandle

Returns:

The recordHandle of the first piece of the long column chain.
insertLongColumn
(BasePage
The parent page with row piece containing column that will eventually point to this long column chain.
mainChainPage
,
LongColumnException
The LongColumnException thrown when we recognized that the column being inserted was "long", this structure is used to cache the info that we have read so far about column. In the case of an insert of the stream it will have a copy of just the first page of the stream that has already been read once.
lce
,
byte
flags for insert operation.
insertFlag
)

Routine to insert a long column.

protected RecordHandle
insertNoOverflow(int slot, Object[] row, FormatableBitSet validColumns, LogicalUndo undo, byte insertFlag, int overflowThreshold)

protected abstract int
internalDeletedRecordCount()

get record count without checking for latch

protected int
internalNonDeletedRecordCount()

get record count without checking for latch

public boolean
isDeletedAtSlot(int
slot of record to be tested.
slot
)

Implements org.apache.derby.iapi.store.raw.Page.isDeletedAtSlot.

Test if a record is deleted.

protected final boolean
isDeletedOnPage(int slot)

public final synchronized boolean

Returns:

true if the page is latched, false otherwise
isLatched
()

Implements org.apache.derby.iapi.store.raw.Page.isLatched.

Check whether the page is latched.

public abstract boolean
isOverflowPage()

Return true if the page is an overflow page, false if not.

public boolean

Returns:

true if a repositioning is needed because the row on the current position may have been removed from this page after the specified version; false otherwise
isRepositionNeeded
(long
the last version on which the B-tree scan had a valid position on this page
version
)

Implements org.apache.derby.iapi.store.raw.Page.isRepositionNeeded.

Check if a B-tree scan positioned on this page needs to reposition.

public abstract void
logColumn(int
slot of the current record
slot
,
int
field number of the column being updated
fieldId
,
Object
column version of the field.
column
,
DynamicByteArrayOutputStream
Where to write the logged form.
out
,
int overflowThreshold)

Log a to be stored column.

public abstract void
logField(int
Slot number the record is stored in.
slot
,
int
Number of the field (starts at 0).
fieldNumber
,
OutputStream
Where to write the logged form.
out
)

Log a currently stored field.

public abstract int
logLongColumn(int
slot of the current record
slot
,
int
the id of the long column record
recordId
,
Object
column version of the field.
column
,
DynamicByteArrayOutputStream
Where to write the logged form.
out
)

Log a to be stored long column.

public abstract void
logRecord(int
Slot number the record is stored in.
slot
,
int
LOG_RECORD_*, the reason for logging the record.
flag
,
int
Record identifier of the record.
recordId
,
FormatableBitSet
which columns needs to be logged
validColumns
,
OutputStream
Where to write the logged form.
out
,
RecordHandle
the recordHandle of the head row piece, used for post commit cleanup for update.
headRowHandle
)

Log a currently stored record to the output stream.

public abstract int
logRow(int
Slot number the record will be stored in.
slot
,
boolean
True if the row is being logged for an insert, false for an update.
forInsert
,
int
Record identifier of the record.
recordId
,
Object[]
The row version of the record.
row
,
FormatableBitSet
FormatableBitSet of which columns in row are valid, null indicates all are valid
validColumns
,
DynamicByteArrayOutputStream
Where to write the logged form.
out
,
int
The first column that is being logged in this row. This is used when logging portion of long rows.
startColumn
,
byte
To indicate whether the insert would allow overflow.
insertFlag
,
int
This is used when a long column is detected. Portion of the row may already be logged and stored in the 'out' buffer. After we log the long column, the saved buffer was passed here, and we need to continue to log the row. realStartColumn is the starting column for the continuation of the logRow operation. Pass in (-1) if realStartColumn is not significant.
realStartColumn
,
int
Being used in conjunction with realStartColumn, to indicate the real free space left on the page.
realSpaceOnPage
,
int overflowThreshold)

Log the row that will be stored at the given slot to the given OutputStream.

public static final RecordHandle
MakeRecordHandle(PageKey pkey, int recordHandleConstant)

public final RecordHandle
makeRecordHandle(int
the special recordId
recordHandleConstant
)

Implements org.apache.derby.iapi.store.raw.Page.makeRecordHandle.

Return a record handle for the given constant record id.

Return a record handle that doesn't represent a record but rather has a special meaning.

public abstract int
newRecordId()

Create a new record identifier.

protected abstract int
newRecordId(int recordId)

Create a new record identifier, the passed in one is the last one created.

public abstract int
newRecordIdAndBump()

Create a new record identifier, and bump to next recordid.

public int
nonDeletedRecordCount()

Implements org.apache.derby.iapi.store.raw.Page.nonDeletedRecordCount.

Return the number of records on this page that are not marked as deleted.

public abstract void
preDirty()

The page or its header is about to be modified.

private void
preLatch(BaseContainerHandle
handle to the container requesting ownership
requester
)

Move page state from UNLATCHED to PRELATCH.

public void
purgeAtSlot(int
the starting slot number
slot
,
int
number of slots to purge. If <= 0, just returns as a no-op.
numpurges
,
boolean
if set to true data is logged for purges else only headers.
needDataLogged
)

Implements org.apache.derby.iapi.store.raw.Page.purgeAtSlot.

Purge one or more rows on a non-overflow page.

public abstract void
purgeRecord(LogInstant instant, int
the slot to purge
slot
,
int
the id of the record that is to be purged
recordId
)

Purge a record from the page.

protected abstract void
purgeRowPieces(RawTransaction t, int slot, RecordHandle headRowHandle, boolean needDataLogged)

Purge all the overflow columns and overflow rows of the record at slot.

public final int
recordCount()

Implements org.apache.derby.iapi.store.raw.Page.recordCount.

Return the number of records on the page.

public final boolean
recordExists(RecordHandle
handle of the record to look for.
handle
,
boolean
if true, then routine will return true even if the row is marked deleted.
ignoreDelete
)

Implements org.apache.derby.iapi.store.raw.Page.recordExists.

does the record still exist on the page?

public abstract StoredRecordHeader
protected synchronized void
releaseExclusive()

Release the exclusive latch on the page.

protected void
removeAndShiftDown(int slot)

Remove record at slot.

public abstract void
reserveSpaceForSlot(LogInstant instant, int slot, int spaceToReserve)

Reserve the required number of bytes for the record in the specified slot.

protected abstract void
restorePortionLongColumn(OverflowInputStream fetchStream)

Read portion of a log record at the given slot into the given byteHolder.

protected abstract boolean

Returns:

false if a qualifier_list is provided and the row does not qualifier (no row read in that case), else true.
restoreRecordFromSlot
(int
the slot number
slot
,
Object[]
(out) filled in sparse row
row
,
FetchDescriptor
A set of information about the fetch: what columns to fetch, any qualifiers, ...
fetchDesc
,
RecordHandle
the record handle for the row at top level, and is used in OverflowInputStream to lock the row for Blobs/Clobs.
rh
,
StoredRecordHeader recordHeader, boolean
Is the head row portion of the row, false if a long row and the 2-N'th portion of the long row.
isHeadRow
)

Read the record at the given slot into the given row.

public abstract void
restoreRecordFromStream(LimitObjectInput in, Object[] row)

Restore a storable row from a InputStream that was used to store the row after a logRecord call.

public void
public abstract void
setContainerRowCount(long count)

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.

public int
setDeleteStatus(int slot, boolean delete)

Mark the record at the passed in slot as deleted.

public abstract void
setDeleteStatus(LogInstant instant, int
the slot to delete or undelete
slot
,
boolean
set delete status to this value
delete
)

Set the delete status of a record from the page.

pack-priv void
setExclusive(BaseContainerHandle requester)

Get an exclusive latch on the page.

pack-priv boolean
setExclusiveNoWait(BaseContainerHandle requester)

Get an exclusive latch on the page, but only if I don't have to wait.

protected final void
setHeaderAtSlot(int slot, StoredRecordHeader rh)

Must be called by any non-abstract sub-class to initialise the slot table.

protected void
setPageStatus(byte status)

Set page status based on passed in status flag.

public abstract void
setPageStatus(LogInstant
the log instant of the log record
instant
,
byte
the page status
status
)

Set the page status underneath a log record MT - latched - page latch must be held

public final void
setPageVersion(long v)

set it when the page is read from disk.

public void
setRepositionNeeded()

Implements org.apache.derby.iapi.store.raw.Page.setRepositionNeeded.

Set a hint in this page to make B-tree scans positioned on it reposition before they continue.

public abstract void
setReservedSpace(LogInstant instant, int slot, int value)

Set the reserved space for this row to value.

protected StoredRecordHeader
shiftUp(int low)

Shift all records in the in-memory slot table up one slot, starting at and including the record in slot 'low' A new slot is added to accomdate the move.

public boolean

Returns:

true if a reclaim space should be scheduled post commit on this page, false otherwise.
shouldReclaimSpace
(int
threshold number of non-deleted rows to schedule reclaim space.
num_non_deleted_rows
,
int
row on page to check for long row/long column
slot_just_deleted
)

Implements org.apache.derby.iapi.store.raw.Page.shouldReclaimSpace.

Is this page/deleted row a candidate for immediate reclaim space.

public abstract void
skipField(ObjectInput in)

Skip a previously stored field written by logField or logColumn.

public abstract void
protected String
slotTableToString()

Debugging, print slot table information

public abstract boolean
spaceForCopy(int num_rows, int[] spaceNeeded)

Is there space for copying this many rows which takes this many bytes on the page MT - latched, page is latched when this methods is called.

public abstract void
storeField(LogInstant instant, int slot, int fieldId, ObjectInput in)

Read a previously stored field written by logField or logColumn and store it on the data page at thge given slot with the given record identifier and field number.

public abstract void
storeRecord(LogInstant instant, int slot, boolean forInsert, ObjectInput in)

Read a previously stored record written by logRecord or logRow and store it on the data page at the given slot with the given record identifier.

public abstract boolean
unfilled()

Returns true if an insert is allowed in the page and the page is relatively unfilled - let specific implementation decide what relatively unfilled means

public void
public void
update(DerbyObservable
The object which is being observed
obj
,
Object
Extra information being passed to the callback
arg
)

Implements org.apache.derby.iapi.services.monitor.DerbyObserver.update.

This object is set to observe the BaseContainerHandle it was obtained by, that handle will notify its observers when it is being closed.

public final RecordHandle
updateAtSlot(int
is the slot number
slot
,
Object[] row, FormatableBitSet
a bit map of which columns in the row is valid. ValidColumns will not be changed by RawStore.
validColumns
)

Implements org.apache.derby.iapi.store.raw.Page.updateAtSlot.

Update the complete record identified by the slot.

public RecordHandle
updateFieldAtSlot(int
is the slot number
slot
,
int
is the column id
fieldId
,
Object
has the new colum value to be stored in the record
newValue
,
LogicalUndo
if logical undo may be necessary, a function pointer to the access code where the logical undo logic resides. Null if logical undo is not necessary.
undo
)

Implements org.apache.derby.iapi.store.raw.Page.updateFieldAtSlot.

Update a field within the record, replacing its current value with the stored representation of newValue.

public abstract void
updateFieldOverflowDetails(RecordHandle
handle of the record for long row
handle
,
RecordHandle
the overflow (continuation) pointer for the long row
overflowHandle
)

Update the overflow pointer for a long column MT - latched - page latch must be held

protected final void
public abstract void
updateOverflowDetails(RecordHandle
handle of the record for long row
handle
,
RecordHandle
the overflow (continuation) pointer for the long row
overflowHandle
)

Update the overflow pointer for a long row MT - latched - page latch must be held

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait