org.apache.derby.impl.store.raw.data
Class FileContainer

java.lang.Object
  extended byorg.apache.derby.impl.store.raw.data.BaseContainer
      extended byorg.apache.derby.impl.store.raw.data.FileContainer
All Implemented Interfaces:
Cacheable, Lockable, TypedFormat
Direct Known Subclasses:
InputStreamContainer, RAFContainer

public abstract class FileContainer
extends BaseContainer
implements Cacheable, TypedFormat

FileContainer is an abstract base class for containers which are based on files. This class extends BaseContainer and implements Cacheable and TypedFormat


Field Summary
protected static int ALLOC_PAGE_ARG_NUM
           
protected  AllocationCache allocCache
           
private  boolean bulkIncreaseContainerSize
           
protected  boolean canUpdate
           
private  java.util.zip.CRC32 checksum
           
protected static int CHECKSUM_SIZE
           
private static int CONTAINER_FORMAT_ID_SIZE
          the container format must fit in this many bytes
protected static int CONTAINER_INFO_SIZE
          The size of the persistently stored container info ContainerHeader contains the following information: 4 bytes int FormatId 4 bytes int status 4 bytes int pageSize 4 bytes int spareSpace 4 bytes int minimumRecordSize 2 bytes short initialPages 2 bytes short spare1 8 bytes long first Allocation page number 8 bytes long first Allocation page offset 8 bytes long container version 8 bytes long estimated number of rows 8 bytes long spare2 8 bytes long spare3 8 bytes long checksum container info size is 80 bytes, with 20 bytes of spare space
protected  CacheManager containerCache
           
(package private)  byte[] containerInfo
           
protected  long containerVersion
           
protected  BaseDataFileFactory dataFactory
           
private static int DEFAULT_PRE_ALLOC_SIZE
           
private  byte[] encryptionBuffer
           
private  long estimatedPageCount
          An estimated page count.
protected  long estimatedRowCount
           
private static int FILE_COMMITTED_DROP
           
private static int FILE_DROPPED
           
private static int FILE_REUSABLE_RECORDID
           
static long FIRST_ALLOC_PAGE_NUMBER
          where the first alloc page is located - the logical page number and the physical page offset NOTE if it is not 0 this is not going to work for Stream file which doesn't support seek
static long FIRST_ALLOC_PAGE_OFFSET
           
protected  long firstAllocPageNumber
           
protected  long firstAllocPageOffset
           
protected static int formatIdInteger
           
protected  short initialPages
           
protected  boolean isDirty
           
private  long lastAllocatedPage
          The last allocated page.
private  long[] lastInsertedPage
          The page that was last inserted into.
private  int lastInsertedPage_index
           
protected  LogInstant lastLogInstant
           
private  long lastUnfilledPage
          The last unfilled page found.
private static int MAX_PRE_ALLOC_SIZE
           
private static int MIN_PRE_ALLOC_SIZE
           
protected  int minimumRecordSize
           
protected  CacheManager pageCache
           
protected  int pageSize
           
private static int PRE_ALLOC_THRESHOLD
           
private  int PreAllocSize
           
private  int PreAllocThreshold
           
protected  boolean preDirty
           
protected static java.lang.String SPACE_TRACE
           
protected  int spareSpace
           
protected static int STORED_PAGE_ARG_NUM
          the number of arguments we need to pass to alloc page for create
 
Fields inherited from class org.apache.derby.impl.store.raw.data.BaseContainer
identity, isCommittedDrop, isDropped, isReusableRecordId
 
Constructor Summary
protected FileContainer(BaseDataFileFactory factory)
           
 
Method Summary
protected  void bumpContainerVersion(LogInstant instant)
          increment the version by one and return the new version.
protected  boolean canUpdate()
          Can the container be updated.
 void clearIdentity()
          Put the object into the No Identity state.
protected  void clearPreallocThreshold()
          The container will have no pre-allocate threshold, i.e., if the implementation supports it, page preallocation will happen the next time a new page is allocated.
protected abstract  void closeContainer()
           
protected abstract  void createContainer(ContainerKey newIdentity)
          Create a new container.
protected  Cacheable createIdent(ContainerKey newIdentity, java.lang.Object createParameter)
           
 Cacheable createIdentity(java.lang.Object key, java.lang.Object createParameter)
          Create a new item and set the identity of the object to represent it.
private  void createInfoFromLog(ByteArray byteArray)
          Set container properties from the passed in ByteArray, which is created by logCreateContainerInfo.
private  void createInfoFromProp(java.util.Properties createArgs)
          Set container properties from the passed in createArgs.
protected  void deallocatePage(BaseContainerHandle handle, BasePage page)
          Deallocate a page from the container.
private  void deallocatePagenum(BaseContainerHandle handle, long pnum)
          deallocate the page from the alloc page
protected  void decryptPage(byte[] pageData, int pageSize)
          Decrypts a page
MT - MT safe.
protected  int doPreAllocatePages(long lastPreallocPagenum, int preAllocSize)
          Preallocate the pages - actually doing it, called by subclass only
protected  void dropContainer(LogInstant instant, boolean isDropped)
          Drop Container.
protected  byte[] encryptPage(byte[] pageData, int pageSize)
          Encrypts a page.
private  AllocPage findAllocPageForAdd(BaseContainerHandle allocHandle, RawTransaction ntt, long lastAllocatedPage)
           
private  AllocPage findLastAllocPage(BaseContainerHandle handle, RawTransaction tran)
          Find the last alloc page, returns null if no alloc page is found
protected  BasePage getAllocPage(long pageNumber)
          Get an alloc page - only accessible to the raw store (container and recovery)
protected  BasePage getAnyPage(BaseContainerHandle handle, long pageNumber)
          Get any old page - turn off all validation
 void getContainerProperties(java.util.Properties prop)
          Request the system properties associated with a container.
protected  long getContainerVersion()
          Get the logged container version.
protected  byte[] getEmbryonicPage(java.io.DataInput fileData)
          Get an embryonic page from the dataInput stream.
 long getEstimatedPageCount(BaseContainerHandle handle, int flag)
           
 long getEstimatedRowCount(int flag)
          
MT - this routine is NOT MT-safe and clients don't need to provide synchronization.
protected  BasePage getFirstHeadPage(BaseContainerHandle handle, boolean wait)
          Get the first valid page in the container
protected  BasePage getHeadPage(BaseContainerHandle handle, long pageNumber, boolean wait)
          Get only a valid, non-overflow page.
private  BasePage getInsertablePage(BaseContainerHandle handle, long pageNumber, boolean wait, boolean overflowOK)
           
private  long getLastInsertedPage()
           
private  long getLastPageNumber(BaseContainerHandle handle)
           
private  long getLastUnfilledPage()
           
protected  int getMinimumRecordSize()
           
protected  BasePage getNextHeadPage(BaseContainerHandle handle, long pageNumber, boolean wait)
          Get the next page in the container.
protected  BasePage getPage(BaseContainerHandle handle, long pageNumber, boolean wait)
          Get a valid (non-deallocated or free) page in the container.
protected  BasePage getPageForInsert(BaseContainerHandle handle, int flag)
          Get a potentially suitable page for insert and latch it.
protected  int getPageSize()
           
 SpaceInfo getSpaceInfo(BaseContainerHandle handle)
          Get information about space used by the container.
protected  int getSpareSpace()
           
 int getTypeFormatId()
          Return my format identifier.
private  long getUnfilledPageNumber(BaseContainerHandle handle, long pagenum)
           
private  BasePage getUserPage(BaseContainerHandle handle, long pageNumber, boolean overflowOK, boolean wait)
          Get a page in the container.
private  void initContainerHeader(boolean changeContainer)
           
private  void initializeLastInsertedPage(int size)
           
protected  BasePage initPage(BaseContainerHandle allochandle, PageKey pkey, int[] createArgs, long pageOffset, boolean reuse, boolean overflow)
          Initialize a page
 boolean isDirty()
          We treat this container as dirty if it has the container file open.
protected  BasePage latchPage(BaseContainerHandle handle, BasePage foundPage, boolean wait)
           
protected  void letGo(BaseContainerHandle handle)
          The container is kept by the find() in File.openContainer.
protected  ByteArray logCreateContainerInfo()
          Log all information on the container creation necessary to recreate the container during a load tran.
private  AllocPage makeAllocPage(RawTransaction ntt, BaseContainerHandle handle, long pageNumber, long pageOffset, int containerInfoSize)
           
protected  BasePage newPage(BaseContainerHandle userHandle, RawTransaction ntt, BaseContainerHandle allocHandle, boolean isOverflow)
          Create a new page in the container.
protected abstract  boolean openContainer(ContainerKey newIdentity)
          Open a container.
private  boolean pageValid(BaseContainerHandle handle, long pagenum)
           
protected abstract  int preAllocate(long lastPreallocPagenum, int preAllocSize)
          preAllocate writes out the preallocated pages to disk if necessary.
 void preDirty(boolean preDirtyOn)
          The container is about to be modified.
protected  void prepareForBulkLoad(BaseContainerHandle handle, int numPage)
          The container will be grown vastly, prepare for it.
protected  void readHeader(java.io.DataInput fileData)
          Read the container's header.
private  void readHeaderFromArray(byte[] a)
          Read containerInfo from a byte array The container Header array must be written by or of the same format as put together by writeHeaderFromArray.
protected abstract  void readPage(long pageNumber, byte[] pageData)
          Read a page into the supplied array.
protected  BasePage reCreatePageForLoadTran(BaseContainerHandle handle, int pageFormat, long pageNumber, long pageOffset)
          ReCreate a page for load tran/rollforward recovery.
protected  void setDirty(boolean dirty)
           
 void setEstimatedRowCount(long count, int flag)
           
protected  Cacheable setIdent(ContainerKey newIdentity)
          Open the container.
 Cacheable setIdentity(java.lang.Object key)
          Open the container.
private  void setLastInsertedPage(long val)
           
private  void setLastUnfilledPage(long val)
           
private  void switchToMultiInsertPageMode(BaseContainerHandle handle)
           
protected  void trackUnfilledPage(long pagenumber, boolean unfilled)
           
protected  void updateEstimatedRowCount(int delta)
          Update estimated row count by page as it leaves the cache.
protected  void writeHeader(byte[] pageData)
          Write the container header to a page array (the first allocation page)
protected  void writeHeader(java.io.DataOutput fileData, boolean create, byte[] epage)
          Write the container header directly to output stream (fileData).
private  void writeHeaderToArray(byte[] a)
          Write containerInfo into a byte array The container Header thus put together can be read by readHeaderFromArray.
protected abstract  void writePage(long pageNumber, byte[] pageData, boolean syncPage)
          Write a page from the supplied array.
 
Methods inherited from class org.apache.derby.impl.store.raw.data.BaseContainer
addPage, fillInIdentity, flushAll, getAllocPage, getAnyPage, getCommittedDropState, getContainerId, getContainerStatus, getDeallocLock, getDroppedState, getFirstPage, getIdentity, getNextPage, getSegmentId, isReusableRecordId, lockAttributes, lockerAlwaysCompatible, lockEvent, removeContainer, removePage, requestCompatible, setCommittedDropState, setDroppedState, setReusableRecordIdState, truncate, unlockEvent, use
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.services.cache.Cacheable
clean, getIdentity
 

Field Detail

formatIdInteger

protected static final int formatIdInteger
See Also:
Constant Field Values

pageCache

protected final CacheManager pageCache

containerCache

protected final CacheManager containerCache

dataFactory

protected final BaseDataFileFactory dataFactory

pageSize

protected int pageSize

spareSpace

protected int spareSpace

minimumRecordSize

protected int minimumRecordSize

initialPages

protected short initialPages

canUpdate

protected boolean canUpdate

PreAllocThreshold

private int PreAllocThreshold

PreAllocSize

private int PreAllocSize

bulkIncreaseContainerSize

private boolean bulkIncreaseContainerSize

PRE_ALLOC_THRESHOLD

private static final int PRE_ALLOC_THRESHOLD
See Also:
Constant Field Values

MIN_PRE_ALLOC_SIZE

private static final int MIN_PRE_ALLOC_SIZE
See Also:
Constant Field Values

DEFAULT_PRE_ALLOC_SIZE

private static final int DEFAULT_PRE_ALLOC_SIZE
See Also:
Constant Field Values

MAX_PRE_ALLOC_SIZE

private static final int MAX_PRE_ALLOC_SIZE
See Also:
Constant Field Values

firstAllocPageNumber

protected long firstAllocPageNumber

firstAllocPageOffset

protected long firstAllocPageOffset

containerVersion

protected long containerVersion

estimatedRowCount

protected long estimatedRowCount

lastLogInstant

protected LogInstant lastLogInstant

lastInsertedPage

private long[] lastInsertedPage
The page that was last inserted into. Use this for getPageForInsert. Remember the last allocated non-overflow page, and remember it in memory only. Use Get/Set method to access this field except when we know it is being single thread access.


lastInsertedPage_index

private int lastInsertedPage_index

lastUnfilledPage

private long lastUnfilledPage
The last unfilled page found. Use this for getPageForInsert. Remember the last unfilled page found, and remember it in memory only. Use Get/Set method to access this field except when we know it is being single thread access.


lastAllocatedPage

private long lastAllocatedPage
The last allocated page. This global var is access *without* synchronization. It is used as a hint for page allocation to find the next reusable page.


estimatedPageCount

private long estimatedPageCount
An estimated page count. Use this for getEstimatedPagecount. Remember it in memory only.


preDirty

protected boolean preDirty

isDirty

protected boolean isDirty

allocCache

protected AllocationCache allocCache

containerInfo

byte[] containerInfo

checksum

private java.util.zip.CRC32 checksum

encryptionBuffer

private byte[] encryptionBuffer

CONTAINER_FORMAT_ID_SIZE

private static final int CONTAINER_FORMAT_ID_SIZE
the container format must fit in this many bytes

See Also:
Constant Field Values

CHECKSUM_SIZE

protected static final int CHECKSUM_SIZE
See Also:
Constant Field Values

CONTAINER_INFO_SIZE

protected static final int CONTAINER_INFO_SIZE
The size of the persistently stored container info ContainerHeader contains the following information: 4 bytes int FormatId 4 bytes int status 4 bytes int pageSize 4 bytes int spareSpace 4 bytes int minimumRecordSize 2 bytes short initialPages 2 bytes short spare1 8 bytes long first Allocation page number 8 bytes long first Allocation page offset 8 bytes long container version 8 bytes long estimated number of rows 8 bytes long spare2 8 bytes long spare3 8 bytes long checksum container info size is 80 bytes, with 20 bytes of spare space

See Also:
Constant Field Values

STORED_PAGE_ARG_NUM

protected static final int STORED_PAGE_ARG_NUM
the number of arguments we need to pass to alloc page for create

See Also:
Constant Field Values

ALLOC_PAGE_ARG_NUM

protected static final int ALLOC_PAGE_ARG_NUM
See Also:
Constant Field Values

FIRST_ALLOC_PAGE_NUMBER

public static final long FIRST_ALLOC_PAGE_NUMBER
where the first alloc page is located - the logical page number and the physical page offset NOTE if it is not 0 this is not going to work for Stream file which doesn't support seek

See Also:
Constant Field Values

FIRST_ALLOC_PAGE_OFFSET

public static final long FIRST_ALLOC_PAGE_OFFSET
See Also:
Constant Field Values

FILE_DROPPED

private static final int FILE_DROPPED
See Also:
Constant Field Values

FILE_COMMITTED_DROP

private static final int FILE_COMMITTED_DROP
See Also:
Constant Field Values

FILE_REUSABLE_RECORDID

private static final int FILE_REUSABLE_RECORDID
See Also:
Constant Field Values

SPACE_TRACE

protected static final java.lang.String SPACE_TRACE
Constructor Detail

FileContainer

protected FileContainer(BaseDataFileFactory factory)
Method Detail

getTypeFormatId

public int getTypeFormatId()
Return my format identifier.

Specified by:
getTypeFormatId in interface TypedFormat
Returns:
The identifier. (A UUID stuffed in an array of 16 bytes).

getSpaceInfo

public SpaceInfo getSpaceInfo(BaseContainerHandle handle)
                       throws StandardException
Get information about space used by the container.

Specified by:
getSpaceInfo in class BaseContainer
Throws:
StandardException

setIdentity

public Cacheable setIdentity(java.lang.Object key)
                      throws StandardException
Open the container.

Specified by:
setIdentity in interface Cacheable
Returns:
a valid object if the container was successfully opened, null if it does not exist.
Throws:
StandardException - Some problem in opening a container.
See Also:
Cacheable.setIdentity(java.lang.Object)

setIdent

protected Cacheable setIdent(ContainerKey newIdentity)
                      throws StandardException
Open the container.

Open the container with key "newIdentity".

should be same name as setIdentity but seems to cause method resolution ambiguities

Throws:
StandardException - Some problem in opening a container.
See Also:
Cacheable.setIdentity(java.lang.Object)

createIdentity

public Cacheable createIdentity(java.lang.Object key,
                                java.lang.Object createParameter)
                         throws StandardException
Description copied from interface: Cacheable
Create a new item and set the identity of the object to represent it. The object will be in the No Identity state, ie. it will have just been created or clearIdentity() was just called.
The object must copy the information out of key, not just store a reference to key if the key is not immutable. After this call the expression getIdentity().equals(key) must return true.

If the class of the object needs to change (e.g. to support a different format) then the object should create a new object, call its initParameter() with the parameters the original object was called with, set its identity and return a reference to it. The cache manager will discard the reference to the old object.
If an exception is thrown the object must be left in the no-identity state.
MT - single thread required - Method must only be called be cache manager and the cache manager will guarantee only one thread can be calling it.

Specified by:
createIdentity in interface Cacheable
Returns:
an object reference if the object can take on the identity, null otherwise.
Throws:
StandardException - If forCreate is true and the object cannot be created.
See Also:
CacheManager.create(java.lang.Object, java.lang.Object)

createIdent

protected Cacheable createIdent(ContainerKey newIdentity,
                                java.lang.Object createParameter)
                         throws StandardException
Throws:
StandardException

clearIdentity

public void clearIdentity()
Description copied from interface: Cacheable
Put the object into the No Identity state.
MT - single thread required - Method must only be called be cache manager and the cache manager will guarantee only one thread can be calling it.

Specified by:
clearIdentity in interface Cacheable
Overrides:
clearIdentity in class BaseContainer

isDirty

public boolean isDirty()
We treat this container as dirty if it has the container file open.

Specified by:
isDirty in interface Cacheable
See Also:
Cacheable.isDirty()

preDirty

public void preDirty(boolean preDirtyOn)
Description copied from class: BaseContainer
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:
preDirty in class BaseContainer

setDirty

protected void setDirty(boolean dirty)

createContainer

protected abstract void createContainer(ContainerKey newIdentity)
                                 throws StandardException
Create a new container.

Create a new container, all references to identity must be through the passed in identity, this object will no identity until after this method returns.

Throws:
StandardException - Cloudscape Standard error policy

openContainer

protected abstract boolean openContainer(ContainerKey newIdentity)
                                  throws StandardException
Open a container.

Longer descrption of routine.

Open a container. Open the file that maps to this container, if the file does not exist then we assume the container was never created. If the file exists but we have trouble opening it then we throw some exception.
MT - single thread required - Enforced by cache manager.

Throws:
StandardException - Standard exception policy.

closeContainer

protected abstract void closeContainer()

dropContainer

protected void dropContainer(LogInstant instant,
                             boolean isDropped)
Drop Container.

Specified by:
dropContainer in class BaseContainer
See Also:
Transaction.dropContainer(org.apache.derby.iapi.store.raw.ContainerKey)

bumpContainerVersion

protected final void bumpContainerVersion(LogInstant instant)
increment the version by one and return the new version.
MT - caller must synchronized this in the same sync block that modifies the container header.


getContainerVersion

protected long getContainerVersion()
Description copied from class: BaseContainer
Get the logged container version.

Specified by:
getContainerVersion in class BaseContainer

getContainerProperties

public void getContainerProperties(java.util.Properties prop)
                            throws StandardException
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 derby.storage.reusableRecordId cloudsacpe.storage.initialPages

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.getContainerProperties(prop); System.out.println( "table's page size = " + prop.getProperty("derby.storage.pageSize"); }

Specified by:
getContainerProperties in class BaseContainer
Parameters:
prop - Property list to fill in.
Throws:
StandardException - Standard exception policy.

readHeader

protected void readHeader(java.io.DataInput fileData)
                   throws java.io.IOException,
                          StandardException
Read the container's header. Assumes the input stream (fileData) is positioned at the beginning of the file. Subclass that implements openContainer is expected to manufacture a DataInput stream which is used here to read the header.
MT - single thread required - Enforced by caller.

Throws:
StandardException - Cloudscape Standard error policy
java.io.IOException - error in reading the header from file

initContainerHeader

private void initContainerHeader(boolean changeContainer)

readHeaderFromArray

private void readHeaderFromArray(byte[] a)
                          throws StandardException,
                                 java.io.IOException
Read containerInfo from a byte array The container Header array must be written by or of the same format as put together by writeHeaderFromArray.

Throws:
StandardException - Cloudscape Standard error policy
java.io.IOException - error in reading the header from file

writeHeader

protected void writeHeader(byte[] pageData)
                    throws StandardException,
                           java.io.IOException
Write the container header to a page array (the first allocation page)

Throws:
StandardException - Cloudscape Standard error policy
java.io.IOException - error in writing the header to file

writeHeader

protected void writeHeader(java.io.DataOutput fileData,
                           boolean create,
                           byte[] epage)
                    throws java.io.IOException,
                           StandardException
Write the container header directly to output stream (fileData). Assumes the output stream is positioned at the beginning of the file. Subclasses that can writes the container header is expected to manufacture a DataOutput stream which is used here.
MT - single thread required - Enforced by caller

Throws:
StandardException - Cloudscape Standard error policy
java.io.IOException - error in writing the header to file

getEmbryonicPage

protected byte[] getEmbryonicPage(java.io.DataInput fileData)
                           throws java.io.IOException
Get an embryonic page from the dataInput stream. If fileData is not null, then the embyronic page will be read in from the input stream (fileData), which is assumed to be positioned at the beginning of the first allocation page. if fileData is null, then just manufacture an array which is the size of an embryonic page.

Throws:
java.io.IOException - error in read the embryonic page from file

writeHeaderToArray

private void writeHeaderToArray(byte[] a)
                         throws java.io.IOException
Write containerInfo into a byte array The container Header thus put together can be read by readHeaderFromArray.

Throws:
java.io.IOException - error in writing the header

logCreateContainerInfo

protected ByteArray logCreateContainerInfo()
                                    throws StandardException
Log all information on the container creation necessary to recreate the container during a load tran.

Specified by:
logCreateContainerInfo in class BaseContainer
Throws:
StandardException - Cloudscape Standard error policy

createInfoFromLog

private void createInfoFromLog(ByteArray byteArray)
                        throws StandardException
Set container properties from the passed in ByteArray, which is created by logCreateContainerInfo. This information is used to recreate the container during recovery load tran. The following container properties are set: pageSize spareSpace minimumRecordSize isReusableRecordId initialPages

Throws:
StandardException

createInfoFromProp

private void createInfoFromProp(java.util.Properties createArgs)
                         throws StandardException
Set container properties from the passed in createArgs. The following container properties are set: pageSize spareSpace minimumRecordSize isReusableRecordId initialPages RESOLVE - in the future setting parameters should be overridable by sub-class, e.g. one implementation of Container may require a minimum page size of 4k.

Throws:
StandardException

canUpdate

protected boolean canUpdate()
Description copied from class: BaseContainer
Can the container be updated.

Specified by:
canUpdate in class BaseContainer
Returns:
true if the container can be updated, false otherwise.

deallocatePage

protected void deallocatePage(BaseContainerHandle handle,
                              BasePage page)
                       throws StandardException
Deallocate a page from the container.

Specified by:
deallocatePage in class BaseContainer
Parameters:
handle - the container handle doing the deallocation
page - the page to be deallocated. It is latched upon entry and will be unlatched by the caller of this function
Throws:
StandardException - Cloudscape Standard error policy

deallocatePagenum

private void deallocatePagenum(BaseContainerHandle handle,
                               long pnum)
                        throws StandardException
deallocate the page from the alloc page

Throws:
StandardException

newPage

protected BasePage newPage(BaseContainerHandle userHandle,
                           RawTransaction ntt,
                           BaseContainerHandle allocHandle,
                           boolean isOverflow)
                    throws StandardException
Create a new page in the container.
MT - thread aware - It is assumed that our caller (our super class) has already arranged a logical lock on page allocation to only allow a single thread through here. Adding a new page involves 2 transactions and 2 pages. The User Transaction (UT) initiated the addPage call and expects a latched page (owns by the UT) to be returned. The Nested Top Transaction (NTT) is the transaction started by RawStore inside an addPage call. This NTT is committed before the page is returned. The NTT is used to accessed high traffic data structure such as the AllocPage. This is outline of the algorithm used in adding a page: 1) find or make an allocPage which can handle the addding of a new page. Latch the allocPage with the NTT. 2) invalidate the allocation information cached by the container. Without the cache no page can be gotten from the container. Pages already in the page cache is not affected. Thus by latching the allocPage and invalidating the allocation cache, this NTT blocks out all page gets from this container until it commits. 3) the allocPage determines which page can be allocated, mark that in its data structure (the alloc extent) and returns the page number of the new page. This change is associated with the NTT. 4) the NTT gets or creates the new page in the page cache (bypassing the lookup of the allocPage since that is already latched by the NTT and will deadlock). 5) the NTT initializes the page (mark it is being a VALID page). 6) the page latch is transfered to the UT from the NTT. 7) the new page is returned, latched by UT If we use an NTT, the caller has to commit the NTT to release the allocPage latch. If we don't use an NTT, the allocPage latch is released as this routine returns.

Specified by:
newPage in class BaseContainer
Parameters:
userHandle - - the container handle opened by the user transaction, use this to latch the new user page
ntt - - the nested top transaction for the purpose of allocating the new page If ntt is null, use the user transaction for allocation. #param allocHandle - the container handle opened by the ntt, use this to latch the alloc page
Throws:
StandardException - Standard Cloudscape error policy

clearPreallocThreshold

protected void clearPreallocThreshold()
Description copied from class: BaseContainer
The container will have no pre-allocate threshold, i.e., if the implementation supports it, page preallocation will happen the next time a new page is allocated.

Specified by:
clearPreallocThreshold in class BaseContainer

prepareForBulkLoad

protected void prepareForBulkLoad(BaseContainerHandle handle,
                                  int numPage)
Description copied from class: BaseContainer
The container will be grown vastly, prepare for it.

Specified by:
prepareForBulkLoad in class BaseContainer

pageValid

private boolean pageValid(BaseContainerHandle handle,
                          long pagenum)
                   throws StandardException
Throws:
StandardException

getLastPageNumber

private long getLastPageNumber(BaseContainerHandle handle)
                        throws StandardException
Throws:
StandardException

findAllocPageForAdd

private AllocPage findAllocPageForAdd(BaseContainerHandle allocHandle,
                                      RawTransaction ntt,
                                      long lastAllocatedPage)
                               throws StandardException
Throws:
StandardException

findLastAllocPage

private AllocPage findLastAllocPage(BaseContainerHandle handle,
                                    RawTransaction tran)
Find the last alloc page, returns null if no alloc page is found


makeAllocPage

private AllocPage makeAllocPage(RawTransaction ntt,
                                BaseContainerHandle handle,
                                long pageNumber,
                                long pageOffset,
                                int containerInfoSize)
                         throws StandardException
Throws:
StandardException

initPage

protected BasePage initPage(BaseContainerHandle allochandle,
                            PageKey pkey,
                            int[] createArgs,
                            long pageOffset,
                            boolean reuse,
                            boolean overflow)
                     throws StandardException
Initialize a page

Parameters:
allochandle - the contianer handle to initialize the page with - the ntt
pkey - the page number of the page to be initialized
reuse - is true if we are reusing a page that has already been initialized once
Returns:
a latched page that has been initialized.
Throws:
StandardException - Cloudscape Standard error policy

getUserPage

private BasePage getUserPage(BaseContainerHandle handle,
                             long pageNumber,
                             boolean overflowOK,
                             boolean wait)
                      throws StandardException
Get a page in the container. Get User page is the generic base routine for all user (client to raw store) getPage. This routine coordinate with allocation/deallocation to ensure that no page can be gotten from the container while page is in the middle of being allocated or deallocated. This routine latches the page.

Parameters:
handle - the container handle
pageNumber - the page number of the page to get
overflowOK - if true then an overflow page is OK, if false, then only non-overflow page is OK
wait - if true then wait for a latch
Returns:
the latched page
MT - thread safe
Throws:
StandardException - Standard Cloudscape error policy

trackUnfilledPage

protected void trackUnfilledPage(long pagenumber,
                                 boolean unfilled)

getPage

protected BasePage getPage(BaseContainerHandle handle,
                           long pageNumber,
                           boolean wait)
                    throws StandardException
Get a valid (non-deallocated or free) page in the container. Overflow page is OK. Resulting page is latched.
MT - thread safe

Specified by:
getPage in class BaseContainer
Throws:
StandardException - Standard Cloudscape error policy

getAnyPage

protected BasePage getAnyPage(BaseContainerHandle handle,
                              long pageNumber)
                       throws StandardException
Get any old page - turn off all validation

Specified by:
getAnyPage in class BaseContainer
Throws:
StandardException - Cloudscape Standard error policy

reCreatePageForLoadTran

protected BasePage reCreatePageForLoadTran(BaseContainerHandle handle,
                                           int pageFormat,
                                           long pageNumber,
                                           long pageOffset)
                                    throws StandardException
ReCreate a page for load tran/rollforward recovery. Only called during recovery redo

Specified by:
reCreatePageForLoadTran in class BaseContainer
Throws:
StandardException - Cloudscape Standard error policy

getAllocPage

protected BasePage getAllocPage(long pageNumber)
                         throws StandardException
Get an alloc page - only accessible to the raw store (container and recovery)

Specified by:
getAllocPage in class BaseContainer
Throws:
StandardException - Cloudscape Standard error policy

getHeadPage

protected BasePage getHeadPage(BaseContainerHandle handle,
                               long pageNumber,
                               boolean wait)
                        throws StandardException
Get only a valid, non-overflow page. If page number is either invalid or overflow, returns null

Specified by:
getHeadPage in class BaseContainer
Throws:
StandardException - Cloudscape Standard error policy

getFirstHeadPage

protected BasePage getFirstHeadPage(BaseContainerHandle handle,
                                    boolean wait)
                             throws StandardException
Get the first valid page in the container

Specified by:
getFirstHeadPage in class BaseContainer
Throws:
StandardException - Cloudscape Standard error policy

getNextHeadPage

protected BasePage getNextHeadPage(BaseContainerHandle handle,
                                   long pageNumber,
                                   boolean wait)
                            throws StandardException
Get the next page in the container.

Specified by:
getNextHeadPage in class BaseContainer
Throws:
StandardException - Standard Cloudscape error policy

getInsertablePage

private BasePage getInsertablePage(BaseContainerHandle handle,
                                   long pageNumber,
                                   boolean wait,
                                   boolean overflowOK)
                            throws StandardException
Throws:
StandardException

getPageForInsert

protected BasePage getPageForInsert(BaseContainerHandle handle,
                                    int flag)
                             throws StandardException
Get a potentially suitable page for insert and latch it.

Specified by:
getPageForInsert in class BaseContainer
Throws:
StandardException - Standard Cloudscape error policy

getUnfilledPageNumber

private long getUnfilledPageNumber(BaseContainerHandle handle,
                                   long pagenum)
                            throws StandardException
Throws:
StandardException

getEstimatedRowCount

public long getEstimatedRowCount(int flag)

MT - this routine is NOT MT-safe and clients don't need to provide synchronization.

Specified by:
getEstimatedRowCount in class BaseContainer
See Also:
ContainerHandle.getEstimatedRowCount(int)

setEstimatedRowCount

public void setEstimatedRowCount(long count,
                                 int flag)
Specified by:
setEstimatedRowCount in class BaseContainer
See Also:
ContainerHandle.setEstimatedRowCount(long, int)

updateEstimatedRowCount

protected void updateEstimatedRowCount(int delta)
Update estimated row count by page as it leaves the cache. The estimated row count is updated without logging!


getEstimatedPageCount

public long getEstimatedPageCount(BaseContainerHandle handle,
                                  int flag)
                           throws StandardException
Specified by:
getEstimatedPageCount in class BaseContainer
Throws:
StandardException - Standard Cloudscape error policy
See Also:
ContainerHandle.getEstimatedPageCount(int)

readPage

protected abstract void readPage(long pageNumber,
                                 byte[] pageData)
                          throws java.io.IOException,
                                 StandardException
Read a page into the supplied array.
MT - thread safe

Throws:
java.io.IOException - error reading page
StandardException - standard cloudscape error message

writePage

protected abstract void writePage(long pageNumber,
                                  byte[] pageData,
                                  boolean syncPage)
                           throws java.io.IOException,
                                  StandardException
Write a page from the supplied array.
MT - thread safe

Throws:
java.io.IOException - error writing page
StandardException - Standard Cloudscape error policy

decryptPage

protected void decryptPage(byte[] pageData,
                           int pageSize)
                    throws StandardException
Decrypts a page
MT - MT safe.

Throws:
StandardException - Standard Cloudscape error policy

encryptPage

protected byte[] encryptPage(byte[] pageData,
                             int pageSize)
                      throws StandardException
Encrypts a page.
MT - not safe, call within synchronized block and only use the returned byte array withing synchronized block.

Throws:
StandardException - Standard Cloudscape error policy

preAllocate

protected abstract int preAllocate(long lastPreallocPagenum,
                                   int preAllocSize)
preAllocate writes out the preallocated pages to disk if necessary.
Make sure the container is large enough and the pages are well formatted. The only reason to do this is to save some I/O during page initialization. Once the initPage log record is written, it is expected that the page really do exist and is well formed or recovery will fail. However, we can gain some performance by writing a bunch of pages at a time rather than one at a time.
If it doesn't make sense for the the implementation to have pre-allocation, just return 0.
If the container is not being logged, don't actually do anything, just return 0.

Parameters:
lastPreallocPagenum - the last preallocated page number as known by the allocation page
preAllocSize - try to preallocate this page number of pages. Since only the container knows how many pages are actually on disk, it may determine that certain number of pages that the allocation page thinks need to be preallocated is already allocated, in those case, act as if the preallocation is successful.
Returns:
number of successfully preallocated page, or 0 if no page has been preallocated

doPreAllocatePages

protected int doPreAllocatePages(long lastPreallocPagenum,
                                 int preAllocSize)
Preallocate the pages - actually doing it, called by subclass only


getPageSize

protected int getPageSize()

getSpareSpace

protected int getSpareSpace()

getMinimumRecordSize

protected int getMinimumRecordSize()

switchToMultiInsertPageMode

private void switchToMultiInsertPageMode(BaseContainerHandle handle)
                                  throws StandardException
Throws:
StandardException

getLastInsertedPage

private long getLastInsertedPage()

getLastUnfilledPage

private long getLastUnfilledPage()

initializeLastInsertedPage

private void initializeLastInsertedPage(int size)

setLastInsertedPage

private void setLastInsertedPage(long val)

setLastUnfilledPage

private void setLastUnfilledPage(long val)

letGo

protected void letGo(BaseContainerHandle handle)
The container is kept by the find() in File.openContainer.

Overrides:
letGo in class BaseContainer

latchPage

protected BasePage latchPage(BaseContainerHandle handle,
                             BasePage foundPage,
                             boolean wait)
                      throws StandardException
Overrides:
latchPage in class BaseContainer
Throws:
StandardException


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.