Top Description Fields Methods
org.apache.derby.iapi.store.raw

public Interface ContainerHandle

Known Direct Subinterfaces
org.apache.derby.iapi.store.raw.data.RawContainerHandle
Imports
org.apache.derby.iapi.store.access.SpaceInfo, org.apache.derby.shared.common.error.StandardException, java.util.Properties

A Container contains a contigious address space of pages, the pages start at page number Container.FIRST_PAGE_NUMBER and are numbered sequentially.

The page size is set at addContainer() time.

Resolve

this style of coding is not currently enforced If the caller calls getPage (or one of its variants) more than once on the same page, the caller must call unlatch a corresponding number of times in order to ensure that the page is latched. For example:

    Container c;
	Page p1 = c.getPage(Container.FIRST_PAGE_NUMBER);
	Page p2 = c.getPage(Container.FIRST_PAGE_NUMBER);
	p1.unlatch();  -- Page is still latched.
	p2.unlatch();  -- Page is now unlatched.
	

There is no restriction on the order in which latching and unlatching is done. In the example, p1 could have been unlatched after p2 with no ill effects.

Open container modes ContainerHandle.MODE are used to open or create the container. Unlike TableProperties, MODEs are not permanantely associated with the container, it is effective only for the lifetime of the containerHandle itself.


A container may use any of these mode flags when it is opened.

If neither or both of the {MODE_READONLY, MODE_FORUPDATE} modes are specified then the behaviour of the container is unspecified.


MODE_UNLOGGED must be set for MODE_CREATE_UNLOGGED to be set.

Temporary Containers

If when creating a container the segment used is ContainerHandle.TEMPORARY_SEGMENT then the container is a temporary container. Temporary containers are not logged or locked and do not live across re-boots of the system. In addition any abort or rollback including rollbacks to savepoints truncate the container if it has been opened for update since the last commit or abort. Temporary containers are private to a transaction and must only be used a single thread within the transaction at any time, these restrictions are not currently enforced.

When opening a temporary container for update access these additional mode flags may be used

If a temporary container is opened multiple times in the same transaction with different modes then the most severe mode is used, ie. none < truncate on commit < drop on commit. The MODE_UNLOGGED, MODE_CREAT_UNLOGGED flags are ignored when opening a temporary container, not logged is always assumed.

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
DEFAULT_PAGESIZE

Used in add container.

public static final int
public static final long
FIRST_PAGE_NUMBER

The first valid page number

public static final int
public static final long
INVALID_PAGE_NUMBER

A page number that is guaranteed to be invalid.

public static final int
public static final int
public static final int
MODE_DEFAULT

See comments above for these modes.

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int

Method Summary

Modifier and TypeMethod and Description
public Page

Returns:

a reference to the page that was added.
addPage
()

Add an empty page to the container and obtain exclusive access to it.

public Page

Returns:

a reference to the page that was added.
addPage
(int flag)

Add an empty page to the container and obtain exclusive access to it.

public void
backupContainer(String backupContainerPath)

Backup the container to the specified path.

public void
close()

Close me.

public void
compactRecord(RecordHandle
The record handle, the record must have been locked execlusively already.
record
)

This record probably has shrunk considerably.

public void
compressContainer()

Release free space to the OS.

public void
flushContainer()

Flush all dirty pages of the container to disk.

public void
getContainerProperties(Properties
Property list to fill in.
prop
)

Request the system properties associated with a container.

public long
getEstimatedPageCount(int
different flavors of page count (reserved for future use)
flag
)

Get the total estimated number of allocated (not freed, not deallocated) user pages in the container, including overflow pages.

public long
getEstimatedRowCount(int
different flavors of row count (reserved for future use)
flag
)

Get the total estimated number of rows in the container, not including overflow rows.

public Page

Returns:

latched page or null if there is no page in the container
getFirstPage
()

Obtain exclusive access to the current first page of the container.

public ContainerKey
getId()

Return my identifier.

public LockingPolicy
getLockingPolicy()

Return the locking policy for this open container.

public Page

Returns:

latched page or null if there is no next page in the container
getNextPage
(long
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.
prevNum
)

Obtain exclusive access to the next valid page of the given page number in the container.

public Page

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.
getPage
(long pageNumber)

Obtain exclusive access to the page with the given page number.

public Page
getPageForCompress(int flag, long pageno)

public Page

Returns:

a valid, non-overflow page. Or null if RawStore doesn't know where to find a good valid, non-overflow page.
getPageForInsert
(int
a GET_PAGE_* flag.
flag
)

Get a page for insert.

public Page

Returns:

the required Page or null if the page does not exist or the page is already latched.
getPageNoWait
(long pageNumber)

Identical to getPage but returns null immediately if the desired page is already latched by another Container.

public long

Returns:

version sequence number
getReusableRecordIdSequenceNumber
()

Get the reusable recordId sequence number.

public SpaceInfo
getSpaceInfo()

Get information about space used by the container.

public Object
getUniqueId()

Return my unique identifier, this identifier will be unique to each instance of an open container handle.

public Page

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)
getUserPageNoWait
(long pageNumber)

Obtain exclusive access to the page with the given page number.

public Page

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)
getUserPageWait
(long pageNumber)

Obtain exclusive access to the page with the given page number.

public boolean

Returns:

true if container is opened for read only, else false.
isReadOnly
()

Is the container opened for read only or update?

public boolean
isTemporaryContainer()

Return true if this containerHandle refers to a temporary container.

public RecordHandle
makeRecordHandle(long
the page number of the RecordHandle.
pageNumber
,
int
the record id of the RecordHandle.
recordId
)

Return a record handle that is initialized to the given segment id, container id, page number and record id.

public void
preAllocate(int numPage)

Try to preallocate numPage new pages if possible.

public void
removePage(Page page)

Remove this page from the container and unlatch the page.

public void
setEstimatedRowCount(long
the estimated number of rows in the container.
count
,
int
different flavors of row count (reserved for future use)
flag
)

Set the total estimated number of rows in the container.

public void
setLockingPolicy(LockingPolicy newLockingPolicy)

Set the locking policy for this open container

Field Detail

ADD_PAGE_BULKback to summary
public static final int ADD_PAGE_BULK
ADD_PAGE_DEFAULTback to summary
public static final int ADD_PAGE_DEFAULT
DEFAULT_ASSIGN_IDback to summary
public static final int DEFAULT_ASSIGN_ID
DEFAULT_PAGESIZEback to summary
public static final int DEFAULT_PAGESIZE

Used in add container.

DEFAULT_SPARESPACEback to summary
public static final int DEFAULT_SPARESPACE
FIRST_PAGE_NUMBERback to summary
public static final long FIRST_PAGE_NUMBER

The first valid page number

GET_PAGE_UNFILLEDback to summary
public static final int GET_PAGE_UNFILLED
INVALID_PAGE_NUMBERback to summary
public static final long INVALID_PAGE_NUMBER

A page number that is guaranteed to be invalid.

MODE_BASEROW_INSERT_LOCKEDback to summary
public static final int MODE_BASEROW_INSERT_LOCKED
MODE_CREATE_UNLOGGEDback to summary
public static final int MODE_CREATE_UNLOGGED
MODE_DEFAULTback to summary
public static final int MODE_DEFAULT

See comments above for these modes.

MODE_DROP_ON_COMMITback to summary
public static final int MODE_DROP_ON_COMMIT
MODE_FLUSH_ON_COMMITback to summary
public static final int MODE_FLUSH_ON_COMMIT
MODE_FORUPDATEback to summary
public static final int MODE_FORUPDATE
MODE_LOCK_NOWAITback to summary
public static final int MODE_LOCK_NOWAIT
MODE_LOCK_ROW_NOWAITback to summary
public static final int MODE_LOCK_ROW_NOWAIT
MODE_NO_ACTIONS_ON_COMMITback to summary
public static final int MODE_NO_ACTIONS_ON_COMMIT
MODE_OPEN_FOR_LOCK_ONLYback to summary
public static final int MODE_OPEN_FOR_LOCK_ONLY
MODE_READONLYback to summary
public static final int MODE_READONLY
MODE_SECONDARY_LOCKEDback to summary
public static final int MODE_SECONDARY_LOCKED
MODE_TEMP_IS_KEPTback to summary
public static final int MODE_TEMP_IS_KEPT
MODE_TRUNCATE_ON_COMMITback to summary
public static final int MODE_TRUNCATE_ON_COMMIT
MODE_TRUNCATE_ON_ROLLBACKback to summary
public static final int MODE_TRUNCATE_ON_ROLLBACK
MODE_UNLOGGEDback to summary
public static final int MODE_UNLOGGED
MODE_USE_UPDATE_LOCKSback to summary
public static final int MODE_USE_UPDATE_LOCKS
TEMPORARY_SEGMENTback to summary
public static final int TEMPORARY_SEGMENT

Method Detail

addPageback to summary
public Page addPage() throws StandardException

Add an empty page to the container and obtain exclusive access to it.

Note that the added page may not be the last page in the Container. Once the Page is no longer required the Page's unlatch() method must be called.

Returns:Page

a reference to the page that was added.

Exceptions
StandardException:
If a page could not be allocated.
See Also
Page#unlatch
addPageback to summary
public Page addPage(int flag) throws StandardException

Add an empty page to the container and obtain exclusive access to it.

If flag == ADD_PAGE_DEFAULT, this call is identical to addPage().
If flag == ADD_PAGE_BULK, then this call signifies to the container that this addPage is part of a large number of additional pages and it is desirable to do whatever possible to facilitate adding many subsequent pages. The actual container implementation will decide whether or not to heed this hint and what to do about it.

Returns:Page

a reference to the page that was added.

Exceptions
StandardException:
  • Standard Derby error policy
  • If a page could not be allocated.
See Also
Page#unlatch
backupContainerback to summary
public void backupContainer(String backupContainerPath) throws StandardException

Backup the container to the specified path.

Exceptions
StandardException:
Standard Derby error policy
closeback to summary
public void close()

Close 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.
See Also
Page#unlatch
compactRecordback to summary
public void compactRecord(RecordHandle record) throws StandardException

This record probably has shrunk considerably. Free its reserved space or compact it.

Parameters
record:RecordHandle

The record handle, the record must have been locked execlusively already.

Exceptions
StandardException:
Standard Derby exception policy.
compressContainerback to summary
public void compressContainer() throws StandardException

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.

Exceptions
StandardException:
Standard Derby error policy
flushContainerback to summary
public void flushContainer() throws StandardException

Flush all dirty pages of the container to disk. Used mainly for UNLOGGED or CREATE_UNLOGGED operation.

Exceptions
StandardException:
Standard Derby error policy
getContainerPropertiesback to summary
public void getContainerProperties(Properties prop) throws StandardException

Request the system properties associated with a container.

Request the value of properties that are associated with a table. 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(ConglomerateController cc) { Properties prop = new Properties(); prop.put("derby.storage.pageSize", ""); cc.getTableProperties(prop); System.out.println( "table's page size = " + prop.getProperty("derby.storage.pageSize"); }

Parameters
prop:Properties

Property list to fill in.

Exceptions
StandardException:
Standard exception policy.
getEstimatedPageCountback to summary
public long getEstimatedPageCount(int flag) throws StandardException

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.

Parameters
flag:int

different flavors of page count (reserved for future use)

Exceptions
StandardException:
Standard Derby error policy
getEstimatedRowCountback to summary
public long getEstimatedRowCount(int flag) throws StandardException

Get the total estimated number of rows in the container, not including overflow rows. This number is a rough estimate and may be grossly off.

Parameters
flag:int

different flavors of row count (reserved for future use)

Exceptions
StandardException:
Standard Derby error policy
getFirstPageback to summary
public Page getFirstPage() throws StandardException

Obtain 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.

Returns:Page

latched page or null if there is no page in the container

Exceptions
StandardException:
Standard Derby error policy
See Also
ContainerHandle#getPage
getIdback to summary
public ContainerKey getId()

Return my identifier.

getLockingPolicyback to summary
public LockingPolicy getLockingPolicy()

Return the locking policy for this open container.

getNextPageback to summary
public Page getNextPage(long prevNum) throws StandardException

Obtain 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
Parameters
prevNum:long

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:Page

latched page or null if there is no next page in the container

Exceptions
StandardException:
Standard Derby error policy
See Also
ContainerHandle#getPage
getPageback to summary
public Page getPage(long pageNumber) throws StandardException

Obtain 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.

Returns:Page

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.

Exceptions
StandardException:
Standard Derby error policy
getPageForCompressback to summary
public Page getPageForCompress(int flag, long pageno) throws StandardException
getPageForInsertback to summary
public Page getPageForInsert(int flag) throws StandardException

Get 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.

Parameters
flag:int

a GET_PAGE_* flag.

Returns:Page

a valid, non-overflow page. Or null if RawStore doesn't know where to find a good valid, non-overflow page.

Exceptions
StandardException:
Standard Derby error policy
getPageNoWaitback to summary
public Page getPageNoWait(long pageNumber) throws StandardException

Identical to getPage but returns null immediately if the desired page is already latched by another Container.

Returns:Page

the required Page or null if the page does not exist or the page is already latched.

Exceptions
StandardException:
Standard Derby error policy
getReusableRecordIdSequenceNumberback to summary
public long getReusableRecordIdSequenceNumber() throws StandardException

Get the reusable recordId sequence number.

Returns:long

version sequence number

Exceptions
StandardException:
Standard Derby error policy
getSpaceInfoback to summary
public SpaceInfo getSpaceInfo() throws StandardException

Get information about space used by the container.

getUniqueIdback to summary
public Object getUniqueId()

Return 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.

getUserPageNoWaitback to summary
public Page getUserPageNoWait(long pageNumber) throws StandardException

Obtain 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.

Returns:Page

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)

Exceptions
StandardException:
Standard Derby error policy
getUserPageWaitback to summary
public Page getUserPageWait(long pageNumber) throws StandardException

Obtain 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.

Returns:Page

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)

Exceptions
StandardException:
Standard Derby error policy
isReadOnlyback to summary
public boolean isReadOnly()

Is the container opened for read only or update?

Returns:boolean

true if container is opened for read only, else false.

isTemporaryContainerback to summary
public boolean isTemporaryContainer() throws StandardException

Return true if this containerHandle refers to a temporary container.

Exceptions
StandardException:
Standard Derby exception policy.
makeRecordHandleback to summary
public RecordHandle makeRecordHandle(long pageNumber, int recordId) throws StandardException

Return a record handle that is initialized to the given segment id, container id, page number and record id.

Parameters
pageNumber:long

the page number of the RecordHandle.

recordId:int

the record id of the RecordHandle.

Exceptions
StandardException:
Standard Derby exception policy.
See Also
RecordHandle
preAllocateback to summary
public void preAllocate(int numPage)

Try to preallocate numPage new pages if possible.

removePageback to summary
public void removePage(Page page) throws StandardException

Remove this page from the container and unlatch the page. Caller should commit or abort this transaction ASAP because failure to do so will slow down page allocation of this container.
The page to be removed must be latched and gotten (or added) by this ContainerHandle. The page should not be used again after this call as if it has been unlatched. If the call to removePage is successful, this page is invalid should not be gotten again with getPage.
RemovePage will guarantee to unlatch the page even if a StandardException is thrown.

Locking Policy
The page will not be freed until the transaction that removed the page commits. A special RecordHandle.DEALLOC_PROTECTION_HANDLE lock will be gotten for the transaction and which is used to prevent the page from being freed. This lock will be held regardless of the default locking policy of the transaction that called removedPage.

Exceptions
StandardException:
Standard Derby error policy
See Also
LockingPolicy, RecordHandle
setEstimatedRowCountback to summary
public void setEstimatedRowCount(long count, int flag) throws StandardException

Set 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.

Parameters
count:long

the estimated number of rows in the container.

flag:int

different flavors of row count (reserved for future use)

Exceptions
StandardException:
Standard Derby error policy
setLockingPolicyback to summary
public void setLockingPolicy(LockingPolicy newLockingPolicy)

Set the locking policy for this open container