TypedFormat
, DerbyObserver
, Page
CachedPage
abstract class BasePage extends java.lang.Object implements Page, DerbyObserver, TypedFormat
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
Modifier and Type | Field | 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 |
inClean |
|
static int |
INIT_PAGE_OVERFLOW |
|
static int |
INIT_PAGE_REUSE |
Init page flag.
|
static int |
INIT_PAGE_REUSE_RECORDID |
|
static byte |
INVALID_PAGE |
|
private static RecordHandle |
InvalidRecordHandle |
|
private LogInstant |
lastLog |
Instant of last log record that updated this page.
|
static int |
LOG_RECORD_DEFAULT |
Log Record flag.
|
static int |
LOG_RECORD_FOR_PURGE |
|
static int |
LOG_RECORD_FOR_UPDATE |
|
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 |
recordCount |
|
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.
|
static 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.
|
DIAG_BYTES_FREE, DIAG_BYTES_RESERVED, DIAG_MAXROWSIZE, DIAG_MINIMUM_REC_SIZE, DIAG_MINROWSIZE, DIAG_NUMOVERFLOWED, DIAG_PAGE_SIZE, DIAG_PAGEOVERHEAD, DIAG_RESERVED_SPACE, DIAG_ROWSIZE, DIAG_SLOTTABLE_SIZE, FIRST_SLOT_NUMBER, INSERT_CONDITIONAL, INSERT_DEFAULT, INSERT_FOR_SPLIT, INSERT_INITIAL, INSERT_OVERFLOW, INSERT_UNDO_WITH_PURGE, INVALID_SLOT_NUMBER
Modifier | Constructor | Description |
---|---|---|
protected |
BasePage() |
Create a new, empty page.
|
Modifier and Type | Method | Description |
---|---|---|
abstract boolean |
allowInsert() |
Returns false if an insert is not to be allowed in the page.
|
abstract int |
appendOverflowFieldHeader(DynamicByteArrayOutputStream logBuffer,
RecordHandle overflowHandle) |
Append an overflow pointer to a partly logged row,
to point to a long column that just been logged.
|
protected long |
bumpPageVersion() |
increment the version by one and return the new version.
|
protected void |
bumpRecordCount(int number) |
|
private void |
checkSlotOnPage(int slot) |
Is the given slot number on the page?
|
protected void |
cleanPageForReuse() |
Initialized this page for reuse or first use
|
void |
clearIdentity() |
|
protected void |
clearLastLogInstant() |
|
void |
compactRecord(RecordHandle handle) |
Try to compact this record.
|
protected abstract void |
compactRecord(RawTransaction t,
int slot,
int recordId) |
Subclass implementation of compactRecord.
|
void |
copyAndPurge(Page destPage,
int src_slot,
int num_rows,
int dest_slot) |
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.
|
void |
deallocatePage() |
Mark this page as being deallocated
|
RecordHandle |
deleteAtSlot(int slot,
boolean delete,
LogicalUndo undo) |
Mark the record at slot as deleted or undeleted according to delete flag.
|
abstract void |
doUpdateAtSlot(RawTransaction t,
int slot,
int id,
java.lang.Object[] row,
FormatableBitSet validColumns) |
|
abstract boolean |
entireRecordOnPage(int slot) |
Returns true if the entire record of that slot fits inside of this
page.
|
RecordHandle |
fetchFieldFromSlot(int slot,
int fieldId,
java.lang.Object column) |
Fetch a single field from a deleted or non-deleted record.
|
RecordHandle |
fetchFromSlot(RecordHandle rh,
int slot,
java.lang.Object[] row,
FetchDescriptor fetchDesc,
boolean ignoreDelete) |
Fetch a record located in the passed in slot.
|
int |
fetchNumFields(RecordHandle handle) |
Fetch the number of fields in a record.
|
int |
fetchNumFieldsAtSlot(int slot) |
Fetch the number of fields in a record.
|
protected void |
fillInIdentity(PageKey key) |
|
private int |
findNextRecordById(int recordId) |
Find the slot for the first record on the page with an id greater than
the passed in identifier.
|
int |
findRecordById(int recordId,
int slotHint) |
Find the slot for the record with the passed in identifier.
|
AuxObject |
getAuxObject() |
Get the aux object.
|
StoredRecordHeader |
getHeaderAtSlot(int slot) |
|
java.lang.Object |
getIdentity() |
OK to hand object outside to cache..
|
RecordHandle |
getInvalidRecordHandle() |
Return an invalid record handle.
|
LogInstant |
getLastLogInstant() |
|
protected abstract BasePage |
getNewOverflowPage() |
|
int |
getNextSlotNumber(RecordHandle handle) |
Find slot for record with an id greater than the passed in identifier.
|
abstract BasePage |
getOverflowPageForInsert(int slot,
java.lang.Object[] row,
FormatableBitSet validColumns,
int startColumn) |
|
protected abstract byte[] |
getPageArray() |
|
PageKey |
getPageId() |
Get the Page identifer
MT - RESOLVE |
PageKey |
getPageKey() |
Return the page key of this page.
|
long |
getPageNumber() |
Return the page number of this page.
|
byte |
getPageStatus() |
Get the page status, one of the values in the above page status flag
|
long |
getPageVersion() |
Return the current page version.
|
RecordHandle |
getRecordHandle(int recordId) |
Get a record handle from a previously stored record id.
|
RecordHandle |
getRecordHandleAtSlot(int slot) |
Get the record handle of row at slot.
|
abstract int |
getRecordLength(int slot) |
Get the stored length of a record.
|
abstract int |
getReservedCount(int slot) |
Return the total number of bytes reserved by the
record at this slot.
|
int |
getSlotNumber(RecordHandle handle) |
Get the slot number.
|
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.
|
void |
initPage(int initFlag,
long pageOffset) |
Mark this page as being allocated and initialize it to a pristine page
|
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
|
RecordHandle |
insert(java.lang.Object[] row,
FormatableBitSet validColumns,
byte insertFlag,
int overflowThreshold) |
Insert a record anywhere on the page.
|
RecordHandle |
insertAllowOverflow(int slot,
java.lang.Object[] row,
FormatableBitSet validColumns,
int startColumn,
byte insertFlag,
int overflowThreshold,
RecordHandle nextPortionHandle) |
Insert a row allowing overflow.
|
RecordHandle |
insertAtSlot(int slot,
java.lang.Object[] row,
FormatableBitSet validColumns,
LogicalUndo undo,
byte insertFlag,
int overflowThreshold) |
Insert a record at the specified slot.
|
protected RecordHandle |
insertLongColumn(BasePage mainChainPage,
LongColumnException lce,
byte insertFlag) |
Routine to insert a long column.
|
protected RecordHandle |
insertNoOverflow(int slot,
java.lang.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
|
boolean |
isDeletedAtSlot(int slot) |
Test if a record is deleted.
|
protected boolean |
isDeletedOnPage(int slot) |
|
boolean |
isLatched() |
Check whether the page is latched.
|
abstract boolean |
isOverflowPage() |
Return true if the page is an overflow page, false if not.
|
boolean |
isRepositionNeeded(long version) |
Check if a B-tree scan positioned on this page needs to reposition.
|
abstract void |
logColumn(int slot,
int fieldId,
java.lang.Object column,
DynamicByteArrayOutputStream out,
int overflowThreshold) |
Log a to be stored column.
|
abstract void |
logField(int slot,
int fieldNumber,
java.io.OutputStream out) |
Log a currently stored field.
|
abstract int |
logLongColumn(int slot,
int recordId,
java.lang.Object column,
DynamicByteArrayOutputStream out) |
Log a to be stored long column.
|
abstract void |
logRecord(int slot,
int flag,
int recordId,
FormatableBitSet validColumns,
java.io.OutputStream out,
RecordHandle headRowHandle) |
Log a currently stored record to the output stream.
|
abstract int |
logRow(int slot,
boolean forInsert,
int recordId,
java.lang.Object[] row,
FormatableBitSet validColumns,
DynamicByteArrayOutputStream out,
int startColumn,
byte insertFlag,
int realStartColumn,
int realSpaceOnPage,
int overflowThreshold) |
Log the row that will be stored at the given slot to the given OutputStream.
|
RecordHandle |
makeRecordHandle(int recordHandleConstant) |
Return a record handle for the given constant record id.
|
static RecordHandle |
MakeRecordHandle(PageKey pkey,
int recordHandleConstant) |
|
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.
|
abstract int |
newRecordIdAndBump() |
Create a new record identifier, and bump to next recordid.
|
int |
nonDeletedRecordCount() |
Return the number of records on this page that are not marked as deleted.
|
abstract void |
preDirty() |
The page or its header is about to be modified.
|
private void |
preLatch(BaseContainerHandle requester) |
Move page state from UNLATCHED to PRELATCH. setExclusive*() routines do
the work of completing the latch - using the preLatch status.
|
void |
purgeAtSlot(int slot,
int numpurges,
boolean needDataLogged) |
Purge one or more rows on a non-overflow page.
|
abstract void |
purgeRecord(LogInstant instant,
int slot,
int 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.
|
int |
recordCount() |
Return the number of records on the page.
|
boolean |
recordExists(RecordHandle handle,
boolean ignoreDelete) |
does the record still exist on the page?
|
abstract StoredRecordHeader |
recordHeaderOnDemand(int slot) |
|
protected void |
releaseExclusive() |
Release the exclusive latch on the page.
|
protected void |
removeAndShiftDown(int slot) |
Remove record at slot.
|
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 |
restoreRecordFromSlot(int slot,
java.lang.Object[] row,
FetchDescriptor fetchDesc,
RecordHandle rh,
StoredRecordHeader recordHeader,
boolean isHeadRow) |
Read the record at the given slot into the given row.
|
abstract void |
restoreRecordFromStream(LimitObjectInput in,
java.lang.Object[] row) |
Restore a storable row from a InputStream that was used to
store the row after a logRecord call.
|
void |
setAuxObject(AuxObject obj) |
Set the aux object.
|
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.
|
int |
setDeleteStatus(int slot,
boolean delete) |
Mark the record at the passed in slot as deleted.
|
abstract void |
setDeleteStatus(LogInstant instant,
int slot,
boolean delete) |
Set the delete status of a record from the page.
|
(package private) void |
setExclusive(BaseContainerHandle requester) |
Get an exclusive latch on the page.
|
(package private) boolean |
setExclusiveNoWait(BaseContainerHandle requester) |
Get an exclusive latch on the page, but only if I don't have to wait.
|
protected 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.
|
abstract void |
setPageStatus(LogInstant instant,
byte status) |
Set the page status underneath a log record
MT - latched - page latch must be held |
void |
setPageVersion(long v) |
set it when the page is read from disk.
|
void |
setRepositionNeeded() |
Set a hint in this page to make B-tree scans positioned on it
reposition before they continue.
|
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.
|
boolean |
shouldReclaimSpace(int num_non_deleted_rows,
int slot_just_deleted) |
Is this page/deleted row a candidate for immediate reclaim space.
|
abstract void |
skipField(java.io.ObjectInput in) |
Skip a previously stored field written by logField or logColumn.
|
abstract void |
skipRecord(java.io.ObjectInput in) |
|
protected java.lang.String |
slotTableToString() |
Debugging, print slot table information
|
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. |
abstract void |
storeField(LogInstant instant,
int slot,
int fieldId,
java.io.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.
|
abstract void |
storeRecord(LogInstant instant,
int slot,
boolean forInsert,
java.io.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.
|
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
|
void |
unlatch() |
Unlatch the page.
|
void |
update(DerbyObservable obj,
java.lang.Object arg) |
This object is set to observe the BaseContainerHandle it was obtained by,
that handle will notify its observers when it is being closed.
|
RecordHandle |
updateAtSlot(int slot,
java.lang.Object[] row,
FormatableBitSet validColumns) |
Update the complete record identified by the slot.
|
RecordHandle |
updateFieldAtSlot(int slot,
int fieldId,
java.lang.Object newValue,
LogicalUndo undo) |
Update a field within the record, replacing its current value with
the stored representation of newValue.
|
abstract void |
updateFieldOverflowDetails(RecordHandle handle,
RecordHandle overflowHandle) |
Update the overflow pointer for a long column
MT - latched - page latch must be held |
protected void |
updateLastLogInstant(LogInstant instant) |
|
abstract void |
updateOverflowDetails(RecordHandle handle,
RecordHandle overflowHandle) |
Update the overflow pointer for a long row
MT - latched - page latch must be held |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
currentTimeStamp, equalTimeStamp, moveRecordForCompressAtSlot, setTimeStamp, spaceForInsert, spaceForInsert
getTypeFormatId
private AuxObject auxObj
protected PageKey identity
private StoredRecordHeader[] headers
private int recordCount
protected BaseContainerHandle owner
private int nestedLatch
protected boolean inClean
protected boolean preLatch
private LogInstant lastLog
private long repositionNeededAfterVersion
private long pageVersion
private byte pageStatus
public static final byte VALID_PAGE
public static final byte INVALID_PAGE
public static final int INIT_PAGE_REUSE
public static final int INIT_PAGE_OVERFLOW
public static final int INIT_PAGE_REUSE_RECORDID
public static final int LOG_RECORD_DEFAULT
public static final int LOG_RECORD_FOR_UPDATE
public static final int LOG_RECORD_FOR_PURGE
private static final RecordHandle InvalidRecordHandle
protected void initialize()
Initialize the object, ie. perform work normally perfomed in constructor. Called by setIdentity() and createIdentity().
protected void initializeHeaders(int numRecords)
protected void fillInIdentity(PageKey key)
public void clearIdentity()
protected void cleanPageForReuse()
public java.lang.Object getIdentity()
public final RecordHandle getInvalidRecordHandle()
Page
getInvalidRecordHandle
in interface Page
public static final RecordHandle MakeRecordHandle(PageKey pkey, int recordHandleConstant) throws StandardException
StandardException
public final RecordHandle makeRecordHandle(int recordHandleConstant) throws StandardException
Page
Return a record handle that doesn't represent a record but rather has a special meaning. Used for special cases like creating a key specific to the page, but not specific to a row on the page.
See RecordHandle interface for a list of "special record handles."
makeRecordHandle
in interface Page
recordHandleConstant
- the special recordIdStandardException
- if input is not a special record identifier.RecordHandle
public final long getPageNumber()
Page
Page numbers are unique within a container and start at ContainerHandle.FIRST_PAGE_NUMBER and increment by 1 regardless of the page size.
MT - Latched
getPageNumber
in interface Page
Page.getPageNumber()
public final PageKey getPageKey()
Page
MT - Latched
getPageKey
in interface Page
ContainerHandle
public final RecordHandle getRecordHandle(int recordId)
Page
Get a record handle from a previously stored record identifier that was obtained from a RecordHandle.
MT - Latched
getRecordHandle
in interface Page
recordId
- previously stored recordId.RecordHandle.getId()
public final RecordHandle getRecordHandleAtSlot(int slot)
Page
Get the record handle of a record on a latched page using its slot
number.
MT - latched
getRecordHandleAtSlot
in interface Page
slot
- the slot numberpublic final boolean recordExists(RecordHandle handle, boolean ignoreDelete) throws StandardException
Page
If "ignoreDelete" is true and the record handle represents a record on
the page (either marked deleted or not) return true. If "ignoreDelete"
is false return true if the record handle represents a record on the
page and the record is not marked as deleted. Return false otherwise.
MT - Latched
recordExists
in interface Page
handle
- handle of the record to look for.ignoreDelete
- if true, then routine will return true even if the
row is marked deleted.StandardException
- recordHandle is not a valid record handlePage.recordExists(org.apache.derby.iapi.store.raw.RecordHandle, boolean)
public RecordHandle fetchFromSlot(RecordHandle rh, int slot, java.lang.Object[] row, FetchDescriptor fetchDesc, boolean ignoreDelete) throws StandardException
Page
Fetch a record located in the passed in slot and fill-in the passed in
StorebleRow and the Object columns contained within. If row
is null then the record is locked but is not fetched.
This interface allows the caller to either return a deleted row or not.
If "ignoreDelete" is set to true, fetch the record regardless of whether
it is deleted or not (same as above fetchFromSlot). However, if
"ignoreDelete" is set to false and the and the slot correspond to a
deleted row, null is returned.
If a non-null Qualifier list is provided then the qualifier array will
be applied to the row and the row will only be returned if the row
qualifies, otherwise null will be returned. Values in the columns of
row may or may not be altered while trying to apply the qualifiers, if
null is returned the state of the columns is undefined. If a null
Qualifier list is provided then no qualification is applied.
If a non-null record handle is passed in, it is assumed that the record
handle corresponds to the record in the slot. If record handle is null,
a record handle will be manufactured and returned if the record is not
deleted or if "ignoreDelete" is true. This parameter is here for the
case where the caller have already manufactured the record handle for
locking or other purposes so it would make sense for the page to avoid
creating a new record handle object if possible.
fetchFromSlot
in interface Page
rh
- the record handle of the row. If non-null it must
refer to the same record as the slot.slot
- the slot numberrow
- Row to be filled in with information from record.fetchDesc
- 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.ignoreDelete
- if true, return row regardless of whether it is
deleted or not. If false, only return non-deleted
row.StandardException
- Standard Derby error policyLockingPolicy
public final RecordHandle fetchFieldFromSlot(int slot, int fieldId, java.lang.Object column) throws StandardException
Page
Locking Policy
No locks are obtained.
It is up to the caller to obtain the correct locks.
It is guaranteed that the page latch is not released by this method
fetchFieldFromSlot
in interface Page
slot
- is the slot numberfieldId
- is the column idcolumn
- is to be filled in with information from the record.StandardException
- Standard Derby error policyPage.fetchFieldFromSlot(int, int, java.lang.Object)
public final int getSlotNumber(RecordHandle handle) throws StandardException
Page
Get the slot number of a record on a latched page using its record handle.
Note
The slot number is only good for as long as the page is latched.
MT - latched
getSlotNumber
in interface Page
handle
- the record handleStandardException
- Record does not exist on this page.Page.getSlotNumber(org.apache.derby.iapi.store.raw.RecordHandle)
public final int getNextSlotNumber(RecordHandle handle) throws StandardException
Page
Find the slot for the first record on the page with an id greater than
the passed in identifier.
Returns the slot of the first record on the page with an id greater than
the one passed in. Usefulness of this functionality depends on the
client's use of the raw store interfaces. If all "new" records are
always inserted at the end of the page, and the raw store continues to
guarantee that all record id's will be allocated in increasing order on
a given page (assuming a PAGE_REUSABLE_RECORD_ID container), then a page
is always sorted in record id order. For instance current heap tables
function this way. If the client ever inserts at a particular slot
number, rather than at the "end" then the record id's will not be sorted.
In the case where all record id's are always sorted on a page, then this
routine can be used by scan's which "lose" their position because the
row they have as a position was purged. They can reposition their scan
at the "next" row after the row that is now missing from the table.
This method returns the record regardless of its deleted status.
MT - latched
getNextSlotNumber
in interface Page
handle
- record handle to find the next higher id.StandardException
- Record does not exist on this page.Page.getNextSlotNumber(org.apache.derby.iapi.store.raw.RecordHandle)
public RecordHandle insertAtSlot(int slot, java.lang.Object[] row, FormatableBitSet validColumns, LogicalUndo undo, byte insertFlag, int overflowThreshold) throws StandardException
Page
All records that occupy FIRST_SLOT_NUMBER to (slot - 1) are not moved.
All records that occupy slot to (recordCount() - 1) are moved up one
slot.
The new record is inserted at the specified slot.
If slot == FIRST_SLOT_NUMBER, then the new record will be inserted at
the first slot.
If slot == recordCount(), then the record is inserted in a new slot, no
records are moved.
If slot is > recordCount() or if slot < FIRST_SLOT_NUMBER, an exception
will be thrown.
Space Policy
If the row will not fit on a page then:
Locking Policy
Calls the lockRecordForWrite() method of the LockingPolicy object passed
to the openContainer() call before the record is inserted.
MT - latched
insertAtSlot
in interface Page
slot
- The specified slotrow
- The row version of the datavalidColumns
- a bit map of which columns in the row is valid.
ValidColumns will not be changed by RawStore.undo
- 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.insertFlag
- 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.StandardException
- Standard Derby error policyPage.insertAtSlot(int, java.lang.Object[], org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.store.access.conglomerate.LogicalUndo, byte, int)
protected RecordHandle insertNoOverflow(int slot, java.lang.Object[] row, FormatableBitSet validColumns, LogicalUndo undo, byte insertFlag, int overflowThreshold) throws StandardException
StandardException
public final RecordHandle insert(java.lang.Object[] row, FormatableBitSet validColumns, byte insertFlag, int overflowThreshold) throws StandardException
Page
Locking Policy
Calls the lockRecordForWrite() method of the LockingPolicy object
passed to the openContainer() call before the record is inserted.
MT - latched
insert
in interface Page
row
- The row version of the datavalidColumns
- a bit map of which columns in the row is valid.
ValidColumns will not be changed by RawStore.insertFlag
- see values for insertFlag below.StandardException
- Standard Derby error policyPage.insert(java.lang.Object[], org.apache.derby.iapi.services.io.FormatableBitSet, byte, int)
public RecordHandle insertAllowOverflow(int slot, java.lang.Object[] row, FormatableBitSet validColumns, int startColumn, byte insertFlag, int overflowThreshold, RecordHandle nextPortionHandle) throws StandardException
StandardException
- Standard Derby error policyprotected RecordHandle insertLongColumn(BasePage mainChainPage, LongColumnException lce, byte insertFlag) throws StandardException
This code inserts a long column as a linked list of rows on overflow pages. This list is pointed to by a small pointer in the main page row column. The operation does the following: allocate new overflow page insert single row filling overflow page while (more of column exists) allocate new overflow page insert single row with next piece of row update previous piece to point to this new piece of row Same code is called both from an initial insert of a long column and from a subsequent update that results in a long column.
mainChainPage
- The parent page with row piece containing column
that will eventually point to this long column
chain.lce
- 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.insertFlag
- flags for insert operation.StandardException
- Standard exception policy.public abstract void preDirty()
public abstract void updateOverflowDetails(RecordHandle handle, RecordHandle overflowHandle) throws StandardException
handle
- handle of the record for long rowoverflowHandle
- the overflow (continuation) pointer for the long rowStandardException
- Standard Derby error policypublic abstract void updateFieldOverflowDetails(RecordHandle handle, RecordHandle overflowHandle) throws StandardException
handle
- handle of the record for long rowoverflowHandle
- the overflow (continuation) pointer for the long rowStandardException
- Standard Derby error policypublic abstract int appendOverflowFieldHeader(DynamicByteArrayOutputStream logBuffer, RecordHandle overflowHandle) throws StandardException, java.io.IOException
logBuffer
- The buffer that contains the partially logged row.overflowHandle
- the overflow (continuation) pointer
to the beginning of the long columnStandardException
- Standard Derby error policyjava.io.IOException
public abstract BasePage getOverflowPageForInsert(int slot, java.lang.Object[] row, FormatableBitSet validColumns, int startColumn) throws StandardException
StandardException
protected abstract BasePage getNewOverflowPage() throws StandardException
StandardException
public final RecordHandle updateAtSlot(int slot, java.lang.Object[] row, FormatableBitSet validColumns) throws StandardException
Page
Locking Policy
Calls the lockRecordForWrite() method of the LockingPolicy object
passed to the openContainer() call before the record is undeleted.
If record already deleted, an exception is thrown.
It is guaranteed that the page latch is not released by this method
updateAtSlot
in interface Page
slot
- is the slot numbervalidColumns
- a bit map of which columns in the row is valid.
ValidColumns will not be changed by RawStore.StandardException
- Standard Derby error policyStandardException
- StandardException.newException(SQLState.UPDATE_DELETED_RECORD
if the record is already deletedStandardException
- StandardException.newException(SQLState.CONTAINER_READ_ONLY
if the container is read onlyPage.updateAtSlot(int, java.lang.Object[], org.apache.derby.iapi.services.io.FormatableBitSet)
public abstract void doUpdateAtSlot(RawTransaction t, int slot, int id, java.lang.Object[] row, FormatableBitSet validColumns) throws StandardException
StandardException
public RecordHandle updateFieldAtSlot(int slot, int fieldId, java.lang.Object newValue, LogicalUndo undo) throws StandardException
Page
Locking Policy
Calls the lockRecordForWrite() method of the LockingPolicy object
passed to the openContainer() call before the record is updated.
It is guaranteed that the page latch is not released by this method
updateFieldAtSlot
in interface Page
slot
- is the slot numberfieldId
- is the column idnewValue
- has the new colum value to be stored in the recordundo
- 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.StandardException
- Standard Derby error policyStandardException
- StandardException.newException(SQLState.UPDATE_DELETED_RECORD
if the record is already deletedStandardException
- StandardException.newException(SQLState.CONTAINER_READ_ONLY
if the container is read onlyPage.updateFieldAtSlot(int, int, java.lang.Object, org.apache.derby.iapi.store.access.conglomerate.LogicalUndo)
public final int fetchNumFields(RecordHandle handle) throws StandardException
Page
Locking Policy
No locks are obtained.
MT - latched
fetchNumFields
in interface Page
handle
- record handle to deleted or non-deleted recordStandardException
- Standard exception policy.Page.fetchNumFields(org.apache.derby.iapi.store.raw.RecordHandle)
public int fetchNumFieldsAtSlot(int slot) throws StandardException
Page
Locking Policy
No locks are obtained.
It is guaranteed that the page latch is not released by this method
fetchNumFieldsAtSlot
in interface Page
slot
- is the slot numberStandardException
- Standard exception policy.Page.fetchNumFieldsAtSlot(int)
public RecordHandle deleteAtSlot(int slot, boolean delete, LogicalUndo undo) throws StandardException
Page
Locking Policy
Calls the lockRecordForWrite() method of the LockingPolicy object passed
to the openContainer() call before the record is deleted. If record
already deleted, and an attempt is made to delete it, an exception is
thrown. If record not deleted, and an attempt is made to undelete it,
an exception is thrown.
MT - latched
deleteAtSlot
in interface Page
slot
- the slot numberdelete
- true if this record is to be deleted, false if this
deleted record is to be marked undeletedundo
- logical undo logic if necessaryStandardException
- Standard exception policy.StandardException
- StandardException.newException(SQLState.UPDATE_DELETED_RECORD
if an attempt to delete a record that is already deletedStandardException
- StandardException.newException(SQLState.UNDELETE_RECORD
if an attempt to undelete a record that is not deletedPage.deleteAtSlot(int, boolean, org.apache.derby.iapi.store.access.conglomerate.LogicalUndo)
public void purgeAtSlot(int slot, int numpurges, boolean needDataLogged) throws StandardException
purgeAtSlot
in interface Page
slot
- the starting slot numbernumpurges
- number of slots to purge. If <= 0,
just returns as a no-op.needDataLogged
- if set to true data is logged for purges else
only headers.StandardException
- Standard exception policy.Page.purgeAtSlot(int, int, boolean)
protected abstract void purgeRowPieces(RawTransaction t, int slot, RecordHandle headRowHandle, boolean needDataLogged) throws StandardException
StandardException
- Standard exception policy.public void copyAndPurge(Page destPage, int src_slot, int num_rows, int dest_slot) throws StandardException
Page
Move from this page slot[src_slot] to slot[src_slot+num_rows-1] to
destPage slot[dest_slot] to slot[dest_slot + num_rows - 1], in that
order. Both this page and destPage must be latched and from the same
container with the same page and record format.
Slot[src_slot] to slot[src_slot+numrows-1] will be purged from this
page. RecordId on the dest page will be brand new and not in any
particular order or range. RecordId of the purged rows in this page is
never reused. Deleted and undeleted rows are copied over just the same.
Exception will be thrown if this page does not have all the rows in the
moved over range.
RESOLVE: reserve space now not copied over because in btree, a
row never shrinks. When this routine is called by heap or by some page
which will have shrunken row, then we need to add that
DestPage must have at least dest_slot row occupying slot[0] to
slot[dest_slot-1]. DestPage must have enough space to take the copied
over data. Rows that occupied slot number > dest_slot will be moved up
the slot (I.e., slot[dest_slot] -> slot[dest_slot + num_rows]).
If this operation rolls back, this page (the src page) will get the
rows back and the dest page will purge the rows that were copied - this
is as if the rows were inserted into the dest page with
INSERT_UNDO_WITH_PURGE.
Locking Policy
Calls the lockRecordForWrite() method of the LockingPolicy object passed to the openContainer() call before the rows are copied over and bore the records are purged. I.e, for num_rows moved, there will be 2*num_rows calls to lockRecordForWrite.
Use with caution
As with a normal purge, no space is reserved on this page for
rollback of the purge, so you must commit before inserting any rows
onto this page - unless those inserts are INSERT_UNDO_WITH_PURGE.
copyAndPurge
in interface Page
destPage
- the page to copy tosrc_slot
- start copying from this slotnum_rows
- copy and purge this many rows from this pagedest_slot
- copying into this slot of destPageStandardException
- Standard exception policy.Page.copyAndPurge(org.apache.derby.iapi.store.raw.Page, int, int, int)
public void unlatch()
unlatch
in interface Page
Page.unlatch()
public final boolean isLatched()
isLatched
in interface Page
true
if the page is latched, false
otherwisePage.isLatched()
public final int recordCount()
Page
recordCount
in interface Page
Page.recordCount()
protected abstract int internalDeletedRecordCount()
protected int internalNonDeletedRecordCount()
public int nonDeletedRecordCount()
Page
nonDeletedRecordCount
in interface Page
Page.nonDeletedRecordCount()
public boolean shouldReclaimSpace(int num_non_deleted_rows, int slot_just_deleted) throws StandardException
Used by access methods after executing a delete on "slot_just_deleted" to ask whether a post commit should be queued to try to reclaim space after the delete commits.
Also used by access methods after undo of an insert.
Will return true if the number of non-deleted rows on the page is <= "num_non_deleted_rows". For instance 0 means schedule reclaim only if all rows are deleted, 1 if all rows but one are deleted.
Will return true if the row just deleted is either a long row or long column. In this case doing a reclaim space on the single row may reclaim multiple pages of free space, so better to do it now rather than wait for all rows on page to be deleted. This case is to address the worst case scenario of all rows with long columns, but very short rows otherwise. In this case there could be 1000's of rows on the main page with many gigabytes of data on overflow pages in deleted space that would not be reclaimed until all rows on the page were deleted.
shouldReclaimSpace
in interface Page
num_non_deleted_rows
- threshold number of non-deleted rows to
schedule reclaim space.slot_just_deleted
- row on page to check for long row/long columnStandardException
- Standard exception policy.protected final boolean isDeletedOnPage(int slot)
public boolean isDeletedAtSlot(int slot) throws StandardException
Page
Locking Policy
No locks are obtained.
It is guaranteed that the page latch is not released by this method
isDeletedAtSlot
in interface Page
slot
- slot of record to be tested.StandardException
- Standard exception policy.Page.isDeletedAtSlot(int)
public void setAuxObject(AuxObject obj)
setAuxObject
in interface Page
Page.setAuxObject(org.apache.derby.iapi.store.raw.AuxObject)
public AuxObject getAuxObject()
getAuxObject
in interface Page
Page.getAuxObject()
public void setRepositionNeeded()
setRepositionNeeded
in interface Page
public boolean isRepositionNeeded(long version)
isRepositionNeeded
in interface Page
version
- the last version on which the B-tree scan had a valid
position on this pagetrue
if a repositioning is needed because the row
on the current position may have been removed from this page after
the specified version; false
otherwisepublic void update(DerbyObservable obj, java.lang.Object arg)
update
in interface DerbyObserver
obj
- The object which is being observedarg
- Extra information being passed to the callbackDerbyObserver.update(org.apache.derby.iapi.services.monitor.DerbyObservable, java.lang.Object)
public final PageKey getPageId()
void setExclusive(BaseContainerHandle requester) throws StandardException
StandardException
- Standard Derby policy.boolean setExclusiveNoWait(BaseContainerHandle requester) throws StandardException
StandardException
protected void releaseExclusive()
private void preLatch(BaseContainerHandle requester)
requester
- handle to the container requesting ownershipprotected final void setHeaderAtSlot(int slot, StoredRecordHeader rh)
protected final void bumpRecordCount(int number)
public final StoredRecordHeader getHeaderAtSlot(int slot)
public abstract boolean entireRecordOnPage(int slot) throws StandardException
StandardException
- Standard Derby error policypublic abstract StoredRecordHeader recordHeaderOnDemand(int slot)
private final void checkSlotOnPage(int slot) throws StandardException
StandardException
public int setDeleteStatus(int slot, boolean delete) throws StandardException, java.io.IOException
StandardException
- Standard Derby error policyjava.io.IOException
- IO error accessing pagepublic void deallocatePage() throws StandardException
StandardException
- Derby Standard error policypublic void initPage(int initFlag, long pageOffset) throws StandardException
StandardException
- Derby Standard error policypublic int findRecordById(int recordId, int slotHint)
recordId
- record id of the record to search for.slotHint
- "hint" about which slot the record might be in.private int findNextRecordById(int recordId)
recordId
- 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.private void copyInto(BasePage srcPage, int src_slot, int num_rows, int dest_slot) throws StandardException
protected void removeAndShiftDown(int slot)
Remove the slot at the in-memory slot table, i.e.,
slots from 0 to deleteSlot-1 is untouched, deleteSlot is removed from
in memory slot table, deleteSlot+1 .. recordCount()-1 move to
down one slot.
MT - latched
protected StoredRecordHeader shiftUp(int low)
public void compactRecord(RecordHandle handle) throws StandardException
Locking Policy
No locks are obtained.
MT - latched
NOTE : CAVEAT
This operation will physically get rid of any reserved space this
record may have, or it may compact the record by merging strung out row
pieces together. Since the freed reserved space is immediately usable
by other transactions which latched the page, it is only safe to use
this operation if the caller knows that it has exclusive access to the
page for the duration of the transaction, i.e., effectively holding a
page lock on the page, AND that the record has no uncommitted
updates.
handle
- Handle to deleted or non-deleted recordStandardException
- Standard Derby error policyContainerHandle.compactRecord(org.apache.derby.iapi.store.raw.RecordHandle)
public final LogInstant getLastLogInstant()
protected final void clearLastLogInstant()
protected final void updateLastLogInstant(LogInstant instant)
public final long getPageVersion()
getPageVersion
in interface Page
protected final long bumpPageVersion()
public final void setPageVersion(long v)
protected void setPageStatus(byte status)
public byte getPageStatus()
protected abstract boolean restoreRecordFromSlot(int slot, java.lang.Object[] row, FetchDescriptor fetchDesc, RecordHandle rh, StoredRecordHeader recordHeader, boolean isHeadRow) throws StandardException
This reads and initializes the columns in the row array from the raw bytes stored in the page associated with the given slot. If validColumns is non-null then it will only read those columns indicated by the bit set, otherwise it will try to read into every column in row[].
If there are more columns than entries in row[] then it just stops after every entry in row[] is full.
If there are more entries in row[] than exist on disk, the requested excess columns will be set to null by calling the column's object's restoreToNull() routine (ie. ((Object) column).restoreToNull() ).
If a qualifier list is provided then the row will only be read from
disk if all of the qualifiers evaluate true. Some of the columns may
have been read into row[] in the process of evaluating the qualifier.
MT - latched, page is latched when this methods is called.
slot
- the slot numberrow
- (out) filled in sparse rowfetchDesc
- A set of information about the fetch: what
columns to fetch, any qualifiers, ...rh
- the record handle for the row at top level,
and is used in OverflowInputStream to lock the
row for Blobs/Clobs.isHeadRow
- Is the head row portion of the row, false if
a long row and the 2-N'th portion of the long
row.StandardException
- Standard Derby error policyprotected abstract void restorePortionLongColumn(OverflowInputStream fetchStream) throws StandardException, java.io.IOException
StandardException
- Standard Derby error policyjava.io.IOException
public abstract int newRecordId() throws StandardException
StandardException
- Standard Derby error policypublic abstract int newRecordIdAndBump() throws StandardException
StandardException
- Standard Derby error policyprotected abstract int newRecordId(int recordId) throws StandardException
StandardException
- Standard Derby error policypublic abstract boolean spaceForCopy(int num_rows, int[] spaceNeeded) throws StandardException
StandardException
- Standard Derby policy.public abstract int getTotalSpace(int slot) throws StandardException
StandardException
- Standard Derby policy.public abstract int getReservedCount(int slot) throws java.io.IOException
java.io.IOException
- Thrown by InputStream methods potential I/O errorspublic abstract int getRecordLength(int slot) throws java.io.IOException
java.io.IOException
public abstract void restoreRecordFromStream(LimitObjectInput in, java.lang.Object[] row) throws StandardException, java.io.IOException
StandardException
- Standard Derby error policyjava.io.IOException
- object exceeds the available data in the stream.public abstract void logRecord(int slot, int flag, int recordId, FormatableBitSet validColumns, java.io.OutputStream out, RecordHandle headRowHandle) throws StandardException, java.io.IOException
slot
- Slot number the record is stored in.flag
- LOG_RECORD_*, the reason for logging the record.recordId
- Record identifier of the record.validColumns
- which columns needs to be loggedout
- Where to write the logged form.headRowHandle
- the recordHandle of the head row piece, used
for post commit cleanup for update.StandardException
- Standard Derby error policyjava.io.IOException
public abstract int logRow(int slot, boolean forInsert, int recordId, java.lang.Object[] row, FormatableBitSet validColumns, DynamicByteArrayOutputStream out, int startColumn, byte insertFlag, int realStartColumn, int realSpaceOnPage, int overflowThreshold) throws StandardException, java.io.IOException
slot
- Slot number the record will be stored in.forInsert
- True if the row is being logged for an insert,
false for an update.recordId
- Record identifier of the record.row
- The row version of the record.validColumns
- FormatableBitSet of which columns in row are valid,
null indicates all are validout
- Where to write the logged form.startColumn
- The first column that is being logged in this row.
This is used when logging portion of long rows.insertFlag
- To indicate whether the insert would allow overflow.realStartColumn
- 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.realSpaceOnPage
- Being used in conjunction with realStartColumn,
to indicate the real free space left on the page.StandardException
- Standard Derby error policyjava.io.IOException
public abstract void logField(int slot, int fieldNumber, java.io.OutputStream out) throws StandardException, java.io.IOException
slot
- Slot number the record is stored in.fieldNumber
- Number of the field (starts at 0).out
- Where to write the logged form.StandardException
- Standard Derby error policyjava.io.IOException
public abstract void logColumn(int slot, int fieldId, java.lang.Object column, DynamicByteArrayOutputStream out, int overflowThreshold) throws StandardException, java.io.IOException
slot
- slot of the current recordfieldId
- field number of the column being updatedcolumn
- column version of the field.out
- Where to write the logged form.StandardException
- Standard Derby error policyjava.io.IOException
public abstract int logLongColumn(int slot, int recordId, java.lang.Object column, DynamicByteArrayOutputStream out) throws StandardException, java.io.IOException
slot
- slot of the current recordrecordId
- the id of the long column recordcolumn
- column version of the field.out
- Where to write the logged form.StandardException
- Standard Derby error policyjava.io.IOException
public abstract void storeRecord(LogInstant instant, int slot, boolean forInsert, java.io.ObjectInput in) throws StandardException, java.io.IOException
StandardException
- Standard Derby error policyjava.io.IOException
- Thrown by InputStream methods potential I/O errors
while writing the pagepublic abstract void storeField(LogInstant instant, int slot, int fieldId, java.io.ObjectInput in) throws StandardException, java.io.IOException
StandardException
- Standard Derby error policyjava.io.IOException
- Thrown by InputStream methods and potential I/O errors
while writing the page.public abstract void reserveSpaceForSlot(LogInstant instant, int slot, int spaceToReserve) throws StandardException, java.io.IOException
StandardException
- Standard Derby error policyjava.io.IOException
- Thrown by InputStream methods and potential I/O errors
while writing the page.public abstract void skipField(java.io.ObjectInput in) throws StandardException, java.io.IOException
StandardException
- Standard Derby error policyjava.io.IOException
- Thrown by InputStream methodspublic abstract void skipRecord(java.io.ObjectInput in) throws StandardException, java.io.IOException
StandardException
java.io.IOException
public abstract void setDeleteStatus(LogInstant instant, int slot, boolean delete) throws StandardException, java.io.IOException
slot
- the slot to delete or undeletedelete
- set delete status to this valueStandardException
- Standard Derby error policyjava.io.IOException
- IO error accessing pagepublic abstract void purgeRecord(LogInstant instant, int slot, int recordId) throws StandardException, java.io.IOException
slot
- the slot to purgerecordId
- the id of the record that is to be purgedStandardException
- Standard Derby error policyjava.io.IOException
- Thrown by potential I/O errors
while writing the page.protected abstract void compactRecord(RawTransaction t, int slot, int recordId) throws StandardException
StandardException
- Standard Derby error policycompactRecord(org.apache.derby.iapi.store.raw.RecordHandle)
public abstract void setPageStatus(LogInstant instant, byte status) throws StandardException
instant
- the log instant of the log recordstatus
- the page statusStandardException
- Standard Derby error policypublic abstract void initPage(LogInstant instant, byte status, int recordId, boolean overflow, boolean reuse) throws StandardException
StandardException
- Standard Derby error policypublic abstract void setReservedSpace(LogInstant instant, int slot, int value) throws StandardException, java.io.IOException
StandardException
- Standard Derby error policyjava.io.IOException
public abstract boolean isOverflowPage()
public abstract boolean allowInsert()
public abstract boolean unfilled()
public abstract void setContainerRowCount(long count)
protected abstract byte[] getPageArray() throws StandardException
StandardException
protected java.lang.String slotTableToString()
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.