Class BaseContainerHandle
- All Implemented Interfaces:
DerbyObserver, ContainerHandle, RawContainerHandle
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PageActionsprivate booleanIs this ContainerHandle active.private AllocationActionsprotected BaseContainerThe actual container we are accessing.private booleanare we going to update?private ContainerKeyContainer identifier
MT - Immutableprivate LockingPolicythe locking policy we opened the container with.private intmode the conainter was opened in.private RawTransactionour transaction.Fields inherited from interface ContainerHandle
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_SEGMENTFields inherited from interface RawContainerHandle
COMMITTED_DROP, DROPPED, NORMAL -
Constructor Summary
ConstructorsConstructorDescriptionBaseContainerHandle(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. -
Method Summary
Modifier and TypeMethodDescriptionaddPage()Add a page to the container The page returned will be observing me.addPage(int flag) Add a page to the container, if flag == ContainerHandle.ADD_PAGE_BULK, tell the container about it.voidbackupContainer(String backupContainerPath) Backup the container to the specified path.protected voidprivate voidvoidclose()Close me.voidcompactRecord(RecordHandle record) This record probably has shrunk considerably.voidRelease free space to the OS.voiddropContainer(LogInstant instant, boolean drop) If drop is true, drop the container.voidencryptOrDecryptContainer(String newFilePath, boolean doEncrypt) Creates an encrypted or decrypted version of the container.voidFlush all dirty pages of the container to disk.getAllocPage(long pageNumber) getAnyPage(long pageNumber) Get this page with no check - any page type or status is fine.voidRequest the system properties associated with a container.intGet the container status.longGet the logged container versionlonggetEstimatedPageCount(int flag) Get the total estimated number of allocated (not freed, not deallocated) user pages in the container, including overflow pages. this number is a rough estimate and may be grossly off.longgetEstimatedRowCount(int flag) Get the total estimated number of rows in the container, not including overflow rows.Obtain exclusive access to the current first page of the container.getId()Return my identifier.final LockingPolicyReturn my locking policy, may be different from the Transaction's default locking policy.intgetMode()Get the mode I was opened with.getNextPage(long pageNumber) Obtain exclusive access to the next valid page of the given page number in the container.getPage(long pageNumber) Obtain exclusive access to the page with the given page number.getPageForCompress(int flag, long pageno) getPageForInsert(int flag) Get a page for insert.getPageNoWait(long pageNumber) Identical to getPage but returns null immediately if the desired page is already latched by another Container.longGet the reusable recordId sequence number.Get information about space used by the container.final RawTransactionReturn the RawTransaction I was opened in.Return my unique identifier, this identifier will be unique to each instance of an open container handle.getUserPageNoWait(long pageNumber) Obtain exclusive access to the page with the given page number.getUserPageWait(long pageNumber) Obtain exclusive access to the page with the given page number.protected voidfinal booleanIs the container opened for read only or update?booleanReturn true if this containerHandle refers to a temporary container.Log all information necessary to recreate the container during a load tran.makeRecordHandle(long pageNumber, int recordId) Return a record handle that is initialized to the given page number and record id.voidpreAllocate(int numPage) Preallocate numPage if possible.voidpreDirty(boolean preDirtyOn) The container is about to be modified.reCreatePageForRedoRecovery(int pageFormat, long pageNumber, long pageOffset) ReCreate a page for rollforward recovery.voidremoveContainer(LogInstant instant) remove the containervoidremovePage(Page page) Remove a page from the container.voidsetEstimatedRowCount(long count, int flag) Set the total estimated number of rows in the container.final voidsetLockingPolicy(LockingPolicy newLockingPolicy) Set the locking policy for this open containertoString()voidupdate(DerbyObservable obj, Object arg) Called when the transaction is about to complete.final booleanupdateOK()Was I opened for updates?booleanuseContainer(boolean droppedOK, boolean waitForLock) Attach me to a container.Methods inherited from class DerbyObservable
addObserver, countObservers, deleteObserver, notifyObservers, notifyObservers, setChanged
-
Field Details
-
identity
Container identifier
MT - Immutable -
active
private boolean activeIs this ContainerHandle active.
MT - Mutable : scoped -
container
The actual container we are accessing. Only valid when active is true.
MT - Mutable : scoped -
locking
the locking policy we opened the container with. Only valid when active is true.
MT - Mutable : scoped -
xact
our transaction. Only valid when active is true.
MT - Mutable : scoped -
forUpdate
private boolean forUpdateare we going to update?
MT - Immutable after container handle becomes active -
mode
private int modemode the conainter was opened in. -
actionsSet
-
allocActionsSet
-
-
Constructor Details
-
BaseContainerHandle
public BaseContainerHandle(UUID rawStoreId, RawTransaction xact, ContainerKey identity, LockingPolicy locking, int mode) Create an object that is only used for locking the container. -
BaseContainerHandle
public 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.
-
-
Method Details
-
addPage
Add a page to the container The page returned will be observing me.- Specified by:
addPagein interfaceContainerHandle- Returns:
- a reference to the page that was added.
- Throws:
StandardException- Standard Derby error policy- See Also:
-
compressContainer
Release free space to the OS.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.
- Specified by:
compressContainerin interfaceContainerHandle- Throws:
StandardException- Standard Derby error policy
-
getReusableRecordIdSequenceNumber
Get the reusable recordId sequence number.- Specified by:
getReusableRecordIdSequenceNumberin interfaceContainerHandle- Returns:
- version sequence number
- Throws:
StandardException- Standard Derby error policy- See Also:
-
addPage
Add a page to the container, if flag == ContainerHandle.ADD_PAGE_BULK, tell the container about it. The page returned will be observing me.- Specified by:
addPagein interfaceContainerHandle- Returns:
- a reference to the page that was added.
- Throws:
StandardException- Standard Derby error policy- See Also:
-
preAllocate
public void preAllocate(int numPage) Preallocate numPage if possible.- Specified by:
preAllocatein interfaceContainerHandle
-
getContainerProperties
Request the system properties associated with a container.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"); }
- Specified by:
getContainerPropertiesin interfaceContainerHandle- Parameters:
prop- Property list to fill in.- Throws:
StandardException- Standard exception policy.
-
removePage
Remove a page from the container.- Specified by:
removePagein interfaceContainerHandle- Throws:
StandardException- Standard Derby error policy- See Also:
-
getPage
Description copied from interface:ContainerHandleObtain exclusive access to the page with the given page number. Once the Page is no longer required the Page's unlatch() method must be called.The Page object is guaranteed to remain in-memory and exclusive to the caller until its unlatch() method is called.
- Specified by:
getPagein interfaceContainerHandle- Returns:
- the required Page or null if the page does not exist or is not valid (i.e, it has been deallocated or freed or never initialized) Note that an overflow page will be returned since it is a valid page.
- Throws:
StandardException- Standard Derby error policy
-
getAllocPage
- Throws:
StandardException
-
getUserPageNoWait
Description copied from interface:ContainerHandleObtain exclusive access to the page with the given page number. Will only return a valid, non-overflow user page - so can be used by routines in post commit to get pages to attempt deleted row space reclamation. If for some reason a request is made for an overflow page a null will be returned. Once the Page is no longer required the Page's unlatch() method must be called.The Page object is guaranteed to remain in-memory and exclusive to the caller until its unlatch() method is called.
- Specified by:
getUserPageNoWaitin interfaceContainerHandle- Returns:
- the required Page or null if the page does not exist or is not valid (i.e, it has been deallocated, freed, never initialized, or is an allocation page or overflow page)
- Throws:
StandardException- Standard Derby error policy
-
getUserPageWait
Description copied from interface:ContainerHandleObtain exclusive access to the page with the given page number. Will only return a valid, non-overflow user page - so can be used by routines in post commit to get pages to attempt deleted row space reclamation. If for some reason a request is made for an overflow page a null will be returned. Once the Page is no longer required the Page's unlatch() method must be called.The Page object is guaranteed to remain in-memory and exclusive to the caller until its unlatch() method is called.
- Specified by:
getUserPageWaitin interfaceContainerHandle- Returns:
- the required Page or null if the page does not exist or is not valid (i.e, it has been deallocated, freed, never initialized, or is an allocation page or overflow page)
- Throws:
StandardException- Standard Derby error policy
-
getPageNoWait
Description copied from interface:ContainerHandleIdentical to getPage but returns null immediately if the desired page is already latched by another Container.- Specified by:
getPageNoWaitin interfaceContainerHandle- Returns:
- the required Page or null if the page does not exist or the page is already latched.
- Throws:
StandardException- Standard Derby error policy
-
getFirstPage
Description copied from interface:ContainerHandleObtain exclusive access to the current first page of the container. Only a valid, non overflow page will be returned. Pages in the container are ordered in an internally defined ordering.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.- Specified by:
getFirstPagein interfaceContainerHandle- Returns:
- latched page or null if there is no page in the container
- Throws:
StandardException- Standard Derby error policy- See Also:
-
getNextPage
Description copied from interface:ContainerHandleObtain exclusive access to the next valid page of the given page number in the container. Only a valid, non overflow page will be returned. Pages in the container are ordered in an internally defined ordering.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 container
- Specified by:
getNextPagein interfaceContainerHandle- Parameters:
pageNumber- 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.- Returns:
- latched page or null if there is no next page in the container
- Throws:
StandardException- Standard Derby error policy- See Also:
-
getPageForInsert
Description copied from interface:ContainerHandleGet a page for insert. If RawStore thinks it knows where a potentially suitable page is for insert, it will return it. If RawStore doesn't know where a suitable page for insert is, or if there are no allocated page, then null is returned. If a page is returned, it will be a valid, non-overflow page. A potentially suitable page is one which has enough space for a minium sized record.- Specified by:
getPageForInsertin interfaceContainerHandle- Parameters:
flag- a GET_PAGE_* flag.- Returns:
- a valid, non-overflow page. Or null if RawStore doesn't know where to find a good valid, non-overflow page.
- Throws:
StandardException- Standard Derby error policy
-
getPageForCompress
- Specified by:
getPageForCompressin interfaceContainerHandle- Throws:
StandardException
-
isReadOnly
public final boolean isReadOnly()Description copied from interface:ContainerHandleIs the container opened for read only or update?- Specified by:
isReadOnlyin interfaceContainerHandle- Returns:
- true if container is opened for read only, else false.
- See Also:
-
close
public void close()Description copied from interface:ContainerHandleClose me. After using this method the caller must throw away the reference to the Container object, e.g.ref.close(); ref = null;
The container will be closed automatically at the commit or abort of the transaction if this method is not called explictly.
Any pages that were obtained using me and have not been released using Page's unlatch method are released, and references to them must be thrown away.- Specified by:
closein interfaceContainerHandle- See Also:
-
getEstimatedRowCount
Description copied from interface:ContainerHandleGet the total estimated number of rows in the container, not including overflow rows. This number is a rough estimate and may be grossly off.- Specified by:
getEstimatedRowCountin interfaceContainerHandle- Parameters:
flag- different flavors of row count (reserved for future use)- Throws:
StandardException- Standard Derby error policy- See Also:
-
setEstimatedRowCount
Description copied from interface:ContainerHandleSet the total estimated number of rows in the container. Often, after a scan, the client of RawStore has a much better estimate of the number of rows in the container then what RawStore has. Use this better number for future reference.
It is OK for a ReadOnly ContainerHandle to set the estimated row count.- Specified by:
setEstimatedRowCountin interfaceContainerHandle- Parameters:
count- the estimated number of rows in the container.flag- different flavors of row count (reserved for future use)- Throws:
StandardException- Standard Derby error policy- See Also:
-
getEstimatedPageCount
Description copied from interface:ContainerHandleGet the total estimated number of allocated (not freed, not deallocated) user pages in the container, including overflow pages. this number is a rough estimate and may be grossly off.- Specified by:
getEstimatedPageCountin interfaceContainerHandle- Parameters:
flag- different flavors of page count (reserved for future use)- Throws:
StandardException- Standard Derby error policy- See Also:
-
flushContainer
Description copied from interface:ContainerHandleFlush all dirty pages of the container to disk. Used mainly for UNLOGGED or CREATE_UNLOGGED operation.- Specified by:
flushContainerin interfaceContainerHandle- Throws:
StandardException- Standard Derby error policy- See Also:
-
compactRecord
Description copied from interface:ContainerHandleThis record probably has shrunk considerably. Free its reserved space or compact it.- Specified by:
compactRecordin interfaceContainerHandle- Parameters:
record- The record handle, the record must have been locked execlusively already.- Throws:
StandardException- Standard Derby error policy- See Also:
-
getContainerStatus
Get the container status.- Specified by:
getContainerStatusin interfaceRawContainerHandle- Throws:
StandardException- Standard Derby error policy- See Also:
-
removeContainer
remove the container- Specified by:
removeContainerin interfaceRawContainerHandle- Throws:
StandardException- Standard Derby error policy- See Also:
-
getId
Description copied from interface:ContainerHandleReturn my identifier.- Specified by:
getIdin interfaceContainerHandle- See Also:
-
getUniqueId
Description copied from interface:ContainerHandleReturn my unique identifier, this identifier will be unique to each instance of an open container handle. This id is used by the locking system to group locks to an open container handle.- Specified by:
getUniqueIdin interfaceContainerHandle- See Also:
-
dropContainer
Description copied from interface:RawContainerHandleIf drop is true, drop the container. if drop is false, un-drop the container- Specified by:
dropContainerin interfaceRawContainerHandle- Throws:
StandardException- Standard Derby exception policy- See Also:
-
getContainerVersion
Description copied from interface:RawContainerHandleGet the logged container version- Specified by:
getContainerVersionin interfaceRawContainerHandle- Throws:
StandardException- Standard Derby exception policy- See Also:
-
getAnyPage
Get this page with no check - any page type or status is fine. Caller must be prepared to handle freed, deallocated,or alloc page Called by recovery ONLY.- Specified by:
getAnyPagein interfaceRawContainerHandle- Throws:
StandardException- Derby Standard error policy
-
reCreatePageForRedoRecovery
public Page reCreatePageForRedoRecovery(int pageFormat, long pageNumber, long pageOffset) throws StandardException ReCreate a page for rollforward recovery.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.
- Specified by:
reCreatePageForRedoRecoveryin interfaceRawContainerHandle- Throws:
StandardException- Standard exception policy.
-
logCreateContainerInfo
Log all information necessary to recreate the container during a load tran.- Specified by:
logCreateContainerInfoin interfaceRawContainerHandle- Throws:
StandardException- Standard Derby error policy
-
makeRecordHandle
Return a record handle that is initialized to the given page number and record id.- Specified by:
makeRecordHandlein interfaceContainerHandle- Parameters:
pageNumber- the page number of the RecordHandle.recordId- the record id of the RecordHandle.- Throws:
StandardException- Standard Derby exception policy.- See Also:
-
update
Called when the transaction is about to complete.- Specified by:
updatein interfaceDerbyObserver- Parameters:
obj- The object which is being observedarg- Extra information being passed to the callback- See Also:
-
getActionSet
-
getAllocationActionSet
-
useContainer
Attach me to a container. If this method returns false then I cannot be used anymore, and any reference to me must be discarded.- Parameters:
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.- Throws:
StandardException- Standard Derby error policy
-
getTransaction
Return the RawTransaction I was opened in. -
getLockingPolicy
Return my locking policy, may be different from the Transaction's default locking policy.- Specified by:
getLockingPolicyin interfaceContainerHandle
-
setLockingPolicy
Description copied from interface:ContainerHandleSet the locking policy for this open container- Specified by:
setLockingPolicyin interfaceContainerHandle
-
updateOK
public final boolean updateOK()Was I opened for updates?
MT - thread safe -
getMode
public int getMode()Get the mode I was opened with. -
preDirty
The container is about to be modified. Loggable actions use this to make sure the container gets cleaned if a checkpoint is taken after any log record is sent to the log stream but before the container is actually dirtied.- Specified by:
preDirtyin interfaceRawContainerHandle- Throws:
StandardException- Standard Derby error policy
-
isTemporaryContainer
Description copied from interface:ContainerHandleReturn true if this containerHandle refers to a temporary container.- Specified by:
isTemporaryContainerin interfaceContainerHandle- Throws:
StandardException- Standard Derby error policy- See Also:
-
checkOpen
- Throws:
StandardException
-
checkUpdateOpen
- Throws:
StandardException
-
informObservers
protected void informObservers() -
getSpaceInfo
Get information about space used by the container.- Specified by:
getSpaceInfoin interfaceContainerHandle- Throws:
StandardException
-
backupContainer
Backup the container to the specified path.- Specified by:
backupContainerin interfaceContainerHandle- Parameters:
backupContainerPath- location of the backup container.- Throws:
StandardException- Standard Derby error policy
-
encryptOrDecryptContainer
public void encryptOrDecryptContainer(String newFilePath, boolean doEncrypt) throws StandardException Creates an encrypted or decrypted version of the container.- Specified by:
encryptOrDecryptContainerin interfaceRawContainerHandle- Parameters:
newFilePath- file to store the new version of the containerdoEncrypt- tells whether to encrypt or decrypt- Throws:
StandardException- Standard Derby error policy
-
toString
-