DerbyObserver, ContainerHandle, RawContainerHandlepublic class BaseContainerHandle extends DerbyObservable implements RawContainerHandle, DerbyObserver
This class is a DerbyObserver to observe RawTransactions
and is also a DerbyObservable to
handle the list of pages accessed thorough this handle.
This class implements Lockable (defined to be ContainerHandle) and is
the object used to logically lock the container.
MT - Mutable - Immutable identity - Thread Aware
| Modifier and Type | Field | Description |
|---|---|---|
private PageActions |
actionsSet |
|
private boolean |
active |
Is this ContainerHandle active.
|
private AllocationActions |
allocActionsSet |
|
protected BaseContainer |
container |
The actual container we are accessing.
|
private boolean |
forUpdate |
are we going to update?
|
private ContainerKey |
identity |
Container identifier
MT - Immutable |
private LockingPolicy |
locking |
the locking policy we opened the container with.
|
private int |
mode |
mode the conainter was opened in.
|
private RawTransaction |
xact |
our transaction.
|
ADD_PAGE_BULK, ADD_PAGE_DEFAULT, DEFAULT_ASSIGN_ID, DEFAULT_PAGESIZE, DEFAULT_SPARESPACE, FIRST_PAGE_NUMBER, GET_PAGE_UNFILLED, INVALID_PAGE_NUMBER, MODE_BASEROW_INSERT_LOCKED, MODE_CREATE_UNLOGGED, MODE_DEFAULT, MODE_DROP_ON_COMMIT, MODE_FLUSH_ON_COMMIT, MODE_FORUPDATE, MODE_LOCK_NOWAIT, MODE_LOCK_ROW_NOWAIT, MODE_NO_ACTIONS_ON_COMMIT, MODE_OPEN_FOR_LOCK_ONLY, MODE_READONLY, MODE_SECONDARY_LOCKED, MODE_TEMP_IS_KEPT, MODE_TRUNCATE_ON_COMMIT, MODE_TRUNCATE_ON_ROLLBACK, MODE_UNLOGGED, MODE_USE_UPDATE_LOCKS, TEMPORARY_SEGMENTCOMMITTED_DROP, DROPPED, NORMAL| Constructor | Description |
|---|---|
BaseContainerHandle(UUID rawStoreId,
RawTransaction xact,
ContainerKey identity,
LockingPolicy locking,
int mode) |
Create an object that is only used for locking the container.
|
BaseContainerHandle(UUID rawStoreId,
RawTransaction xact,
PageActions actionsSet,
AllocationActions allocActionsSet,
LockingPolicy locking,
BaseContainer container,
int mode) |
Create a container handle that is used to actually access the container.
|
| Modifier and Type | Method | Description |
|---|---|---|
Page |
addPage() |
Add a page to the container
The page returned will be observing me.
|
Page |
addPage(int flag) |
Add a page to the container, if flag == ContainerHandle.ADD_PAGE_BULK,
tell the container about it.
|
void |
backupContainer(java.lang.String backupContainerPath) |
Backup the container to the specified path.
|
protected void |
checkOpen() |
|
private void |
checkUpdateOpen() |
|
void |
close() |
Close me.
|
void |
compactRecord(RecordHandle record) |
This record probably has shrunk considerably.
|
void |
compressContainer() |
Release free space to the OS.
|
void |
dropContainer(LogInstant instant,
boolean drop) |
If drop is true, drop the container.
|
void |
encryptOrDecryptContainer(java.lang.String newFilePath,
boolean doEncrypt) |
Creates an encrypted or decrypted version of the container.
|
void |
flushContainer() |
Flush all dirty pages of the container to disk.
|
PageActions |
getActionSet() |
|
AllocationActions |
getAllocationActionSet() |
|
Page |
getAllocPage(long pageNumber) |
|
Page |
getAnyPage(long pageNumber) |
Get this page with no check - any page type or status is fine.
|
void |
getContainerProperties(java.util.Properties prop) |
Request the system properties associated with a container.
|
int |
getContainerStatus() |
Get the container status.
|
long |
getContainerVersion() |
Get the logged container version
|
long |
getEstimatedPageCount(int flag) |
Get the total estimated number of allocated (not freed, not
deallocated) user pages in the container, including overflow pages.
|
long |
getEstimatedRowCount(int flag) |
Get the total estimated number of rows in the container, not including
overflow rows.
|
Page |
getFirstPage() |
Obtain exclusive access to the current first page of the container.
|
ContainerKey |
getId() |
Return my identifier.
|
LockingPolicy |
getLockingPolicy() |
Return my locking policy, may be different from the Transaction's
default locking policy.
|
int |
getMode() |
Get the mode I was opened with.
|
Page |
getNextPage(long pageNumber) |
Obtain exclusive access to the next valid page of the given page number
in the container.
|
Page |
getPage(long pageNumber) |
Obtain exclusive access to the page with the given page number.
|
Page |
getPageForCompress(int flag,
long pageno) |
|
Page |
getPageForInsert(int flag) |
Get a page for insert.
|
Page |
getPageNoWait(long pageNumber) |
Identical to getPage but returns null immediately if the desired page
is already latched by another Container.
|
long |
getReusableRecordIdSequenceNumber() |
Get the reusable recordId sequence number.
|
SpaceInfo |
getSpaceInfo() |
Get information about space used by the container.
|
RawTransaction |
getTransaction() |
Return the RawTransaction I was opened in.
|
java.lang.Object |
getUniqueId() |
Return my unique identifier, this identifier will be unique to each
instance of an open container handle.
|
Page |
getUserPageNoWait(long pageNumber) |
Obtain exclusive access to the page with the given page number.
|
Page |
getUserPageWait(long pageNumber) |
Obtain exclusive access to the page with the given page number.
|
protected void |
informObservers() |
|
boolean |
isReadOnly() |
Is the container opened for read only or update?
|
boolean |
isTemporaryContainer() |
Return true if this containerHandle refers to a temporary container.
|
ByteArray |
logCreateContainerInfo() |
Log all information necessary to recreate the container during a load
tran.
|
RecordHandle |
makeRecordHandle(long pageNumber,
int recordId) |
Return a record handle that is initialized to the given page number and
record id.
|
void |
preAllocate(int numPage) |
Preallocate numPage if possible.
|
void |
preDirty(boolean preDirtyOn) |
The container is about to be modified.
|
Page |
reCreatePageForRedoRecovery(int pageFormat,
long pageNumber,
long pageOffset) |
ReCreate a page for rollforward recovery.
|
void |
removeContainer(LogInstant instant) |
remove the container
|
void |
removePage(Page page) |
Remove a page from the container.
|
void |
setEstimatedRowCount(long count,
int flag) |
Set the total estimated number of rows in the container.
|
void |
setLockingPolicy(LockingPolicy newLockingPolicy) |
Set the locking policy for this open container
|
java.lang.String |
toString() |
|
void |
update(DerbyObservable obj,
java.lang.Object arg) |
Called when the transaction is about to complete.
|
boolean |
updateOK() |
Was I opened for updates?
|
boolean |
useContainer(boolean droppedOK,
boolean waitForLock) |
Attach me to a container.
|
addObserver, countObservers, deleteObserver, notifyObservers, notifyObservers, setChangedprivate ContainerKey identity
private boolean active
protected BaseContainer container
private LockingPolicy locking
private RawTransaction xact
private boolean forUpdate
private int mode
private PageActions actionsSet
private AllocationActions allocActionsSet
public BaseContainerHandle(UUID rawStoreId, RawTransaction xact, ContainerKey identity, LockingPolicy locking, int mode)
public BaseContainerHandle(UUID rawStoreId, RawTransaction xact, PageActions actionsSet, AllocationActions allocActionsSet, LockingPolicy locking, BaseContainer container, int mode)
public Page addPage() throws StandardException
addPage in interface ContainerHandleStandardException - Standard Derby error policyBaseContainer.addPage(org.apache.derby.impl.store.raw.data.BaseContainerHandle, boolean),
ContainerHandle.addPage()public void compressContainer()
throws StandardException
As is possible release any free space to the operating system. This will usually mean releasing any free pages located at the end of the file using the java truncate() interface.
compressContainer in interface ContainerHandleStandardException - Standard Derby error policypublic long getReusableRecordIdSequenceNumber()
throws StandardException
getReusableRecordIdSequenceNumber in interface ContainerHandleStandardException - Standard Derby error policyContainerHandle.getReusableRecordIdSequenceNumber()public Page addPage(int flag) throws StandardException
addPage in interface ContainerHandleStandardException - Standard Derby error policyBaseContainer.addPage(org.apache.derby.impl.store.raw.data.BaseContainerHandle, boolean),
ContainerHandle.addPage()public void preAllocate(int numPage)
preAllocate in interface ContainerHandlepublic void getContainerProperties(java.util.Properties prop)
throws StandardException
Request the value of properties that are associated with a container. The following properties can be requested: derby.storage.pageSize derby.storage.pageReservedSpace derby.storage.minimumRecordSize
To get the value of a particular property add it to the property list, and on return the value of the property will be set to it's current value. For example: get_prop(BaseContainerHandle ch) { Properties prop = new Properties(); prop.put("derby.storage.pageSize", ""); ch.getContainerProperties(prop); System.out.println( "conatainer's page size = " + prop.getProperty("derby.storage.pageSize"); }
getContainerProperties in interface ContainerHandleprop - Property list to fill in.StandardException - Standard exception policy.public void removePage(Page page) throws StandardException
removePage in interface ContainerHandleStandardException - Standard Derby error policyContainerHandle.removePage(org.apache.derby.iapi.store.raw.Page)public Page getPage(long pageNumber) throws StandardException
ContainerHandleThe Page object is guaranteed to remain in-memory and exclusive to the caller until its unlatch() method is called.
getPage in interface ContainerHandleStandardException - Standard Derby error policypublic Page getAllocPage(long pageNumber) throws StandardException
StandardExceptionpublic Page getUserPageNoWait(long pageNumber) throws StandardException
ContainerHandleThe Page object is guaranteed to remain in-memory and exclusive to the caller until its unlatch() method is called.
getUserPageNoWait in interface ContainerHandleStandardException - Standard Derby error policypublic Page getUserPageWait(long pageNumber) throws StandardException
ContainerHandleThe Page object is guaranteed to remain in-memory and exclusive to the caller until its unlatch() method is called.
getUserPageWait in interface ContainerHandleStandardException - Standard Derby error policypublic Page getPageNoWait(long pageNumber) throws StandardException
ContainerHandlegetPageNoWait in interface ContainerHandleStandardException - Standard Derby error policypublic Page getFirstPage() throws StandardException
ContainerHandle
Note that once this method returns this page may no longer be the
first page of the container. I.e, other threads may allocate pages
prior to this page number while this page is latched. It is up to
the caller of this routine to synchronize this call with addPage to
assure that this is the first page.
As long as the client provide the necessary lock to ensure
that no addPage is called, then this page is guaranteed to be the
first page of the container in some internally defined ordering of
the pages.
getFirstPage in interface ContainerHandleStandardException - Standard Derby error policyContainerHandle.getPage(long)public Page getNextPage(long pageNumber) throws StandardException
ContainerHandle
Note that once this method returns this page may no longer be the
next page of the container. I.e, other threads may allocate pages
prior to this page number while this page is latched. It is up to
the caller of this routine to synchronize this call with addPage to
assure that this is the first page.
As long as the client provide the necessary lock to ensure
that no addPage is called, then this page is guaranteed to be the
next page of the container in some internally defined ordering of
the pages.
If no pages are added or removed, then an iteration such as:
for (Page p = containerHandle.getFirstPage();
p != null;
p = containerHandle.getNextPage(p.getPageNumber()))
will guarentee to iterate thru and latched all the valid pages
in the containergetNextPage in interface ContainerHandlepageNumber - the pagenumber of the page previous to the page
that is to be gotten. The page which correspond to prevNum
may or may not be latched by the caller, but it must be gotten
via a page which was (or currently still is) latched, and the page
number must be gotten while the container must not have been closed
or dropped or removed in the interim.
In other words, if the user manufactures a page number, or remembers
the page number from a previous session or a previous openContainer,
then the behavior of this routine is undefined.StandardException - Standard Derby error policyContainerHandle.getPage(long)public Page getPageForInsert(int flag) throws StandardException
ContainerHandlegetPageForInsert in interface ContainerHandleflag - a GET_PAGE_* flag.StandardException - Standard Derby error policypublic Page getPageForCompress(int flag, long pageno) throws StandardException
getPageForCompress in interface ContainerHandleStandardExceptionpublic final boolean isReadOnly()
ContainerHandleisReadOnly in interface ContainerHandleContainerHandle.isReadOnly()public void close()
ContainerHandle
ref.close();
ref = null;
close in interface ContainerHandleContainerHandle.close()public long getEstimatedRowCount(int flag)
throws StandardException
ContainerHandlegetEstimatedRowCount in interface ContainerHandleflag - different flavors of row count (reserved for future use)StandardException - Standard Derby error policyContainerHandle.getEstimatedRowCount(int)public void setEstimatedRowCount(long count,
int flag)
throws StandardException
ContainerHandlesetEstimatedRowCount in interface ContainerHandlecount - the estimated number of rows in the container.flag - different flavors of row count (reserved for future use)StandardException - Standard Derby error policyContainerHandle.setEstimatedRowCount(long, int)public long getEstimatedPageCount(int flag)
throws StandardException
ContainerHandlegetEstimatedPageCount in interface ContainerHandleflag - different flavors of page count (reserved for future use)StandardException - Standard Derby error policyContainerHandle.getEstimatedPageCount(int)public void flushContainer()
throws StandardException
ContainerHandleflushContainer in interface ContainerHandleStandardException - Standard Derby error policyContainerHandle.flushContainer()public void compactRecord(RecordHandle record) throws StandardException
ContainerHandlecompactRecord in interface ContainerHandlerecord - The record handle, the record must have been locked execlusively already.StandardException - Standard Derby error policyContainerHandle.compactRecord(org.apache.derby.iapi.store.raw.RecordHandle)public int getContainerStatus()
throws StandardException
getContainerStatus in interface RawContainerHandleStandardException - Standard Derby error policyRawContainerHandle.getContainerStatus()public void removeContainer(LogInstant instant) throws StandardException
removeContainer in interface RawContainerHandleStandardException - Standard Derby error policyRawContainerHandle.removeContainer(org.apache.derby.iapi.store.raw.log.LogInstant)public ContainerKey getId()
ContainerHandlegetId in interface ContainerHandleContainerHandle.getId()public java.lang.Object getUniqueId()
ContainerHandlegetUniqueId in interface ContainerHandleContainerHandle.getUniqueId()public void dropContainer(LogInstant instant, boolean drop) throws StandardException
RawContainerHandledropContainer in interface RawContainerHandleStandardException - Standard Derby exception policyRawContainerHandle.dropContainer(org.apache.derby.iapi.store.raw.log.LogInstant, boolean)public long getContainerVersion()
throws StandardException
RawContainerHandlegetContainerVersion in interface RawContainerHandleStandardException - Standard Derby exception policyRawContainerHandle.getContainerVersion()public Page getAnyPage(long pageNumber) throws StandardException
getAnyPage in interface RawContainerHandleStandardException - Derby Standard error policypublic Page reCreatePageForRedoRecovery(int pageFormat, long pageNumber, long pageOffset) throws StandardException
During redo recovery it is possible for the system to try to redo the creation of a page (ie. going from non-existence to version 0). It first trys to read the page from disk, but a few different types of errors can occur: o the page does not exist at all on disk, this can happen during rollforward recovery applied to a backup where the file was copied and the page was added to the file during the time frame of the backup but after the physical file was copied. o space in the file exists, but it was never initalized. This can happen if you happen to crash at just the right moment during the allocation process. Also on some OS's it is possible to read from a part of the file that was not ever written - resulting in garbage from the store's point of view (often the result is all 0's). All these errors are easy to recover from as the system can easily create a version 0 from scratch and write it to disk. Because the system does not sync allocation of data pages, it is also possible at this point that whlie writing the version 0 to disk to create it we may encounter an out of disk space error (caught in this routine as a StandardException from the create() call. We can't recovery from this without help from outside, so the caught exception is nested and a new exception thrown which the recovery system will output to the user asking them to check their disk for space/errors.
reCreatePageForRedoRecovery in interface RawContainerHandleStandardException - Standard exception policy.public ByteArray logCreateContainerInfo() throws StandardException
logCreateContainerInfo in interface RawContainerHandleStandardException - Standard Derby error policypublic RecordHandle makeRecordHandle(long pageNumber, int recordId) throws StandardException
makeRecordHandle in interface ContainerHandlepageNumber - the page number of the RecordHandle.recordId - the record id of the RecordHandle.StandardException - Standard Derby exception policy.RecordHandlepublic void update(DerbyObservable obj, java.lang.Object arg)
update in interface DerbyObserverobj - 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 PageActions getActionSet()
public AllocationActions getAllocationActionSet()
public boolean useContainer(boolean droppedOK,
boolean waitForLock)
throws StandardException
droppedOK - if true, use this container even if it is dropped,
otherwise, return false if container is dropped.waitForLock - if true, wait on lock, otherwise, get lock no wait.StandardException - Standard Derby error policypublic final RawTransaction getTransaction()
public final LockingPolicy getLockingPolicy()
getLockingPolicy in interface ContainerHandlepublic final void setLockingPolicy(LockingPolicy newLockingPolicy)
ContainerHandlesetLockingPolicy in interface ContainerHandlepublic final boolean updateOK()
MT - thread safe
public int getMode()
public void preDirty(boolean preDirtyOn)
throws StandardException
preDirty in interface RawContainerHandleStandardException - Standard Derby error policypublic boolean isTemporaryContainer()
throws StandardException
ContainerHandleisTemporaryContainer in interface ContainerHandleStandardException - Standard Derby error policyContainerHandle.isTemporaryContainer()protected void checkOpen()
throws StandardException
StandardExceptionprivate void checkUpdateOpen()
throws StandardException
StandardExceptionprotected void informObservers()
public SpaceInfo getSpaceInfo() throws StandardException
getSpaceInfo in interface ContainerHandleStandardExceptionpublic void backupContainer(java.lang.String backupContainerPath)
throws StandardException
backupContainer in interface ContainerHandlebackupContainerPath - location of the backup container.StandardException - Standard Derby error policypublic void encryptOrDecryptContainer(java.lang.String newFilePath,
boolean doEncrypt)
throws StandardException
encryptOrDecryptContainer in interface RawContainerHandlenewFilePath - file to store the new version of the containerdoEncrypt - tells whether to encrypt or decryptStandardException - Standard Derby error policypublic java.lang.String toString()
toString in class java.lang.ObjectApache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.