|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.store.raw.data.BaseContainer
org.apache.derby.impl.store.raw.data.FileContainer
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 |
protected static final int formatIdInteger
protected final CacheManager pageCache
protected final CacheManager containerCache
protected final BaseDataFileFactory dataFactory
protected int pageSize
protected int spareSpace
protected int minimumRecordSize
protected short initialPages
protected boolean canUpdate
private int PreAllocThreshold
private int PreAllocSize
private boolean bulkIncreaseContainerSize
private static final int PRE_ALLOC_THRESHOLD
private static final int MIN_PRE_ALLOC_SIZE
private static final int DEFAULT_PRE_ALLOC_SIZE
private static final int MAX_PRE_ALLOC_SIZE
protected long firstAllocPageNumber
protected long firstAllocPageOffset
protected long containerVersion
protected long estimatedRowCount
protected LogInstant lastLogInstant
private long[] lastInsertedPage
private int lastInsertedPage_index
private long lastUnfilledPage
private long lastAllocatedPage
private long estimatedPageCount
protected boolean preDirty
protected boolean isDirty
protected AllocationCache allocCache
byte[] containerInfo
private java.util.zip.CRC32 checksum
private byte[] encryptionBuffer
private static final int CONTAINER_FORMAT_ID_SIZE
protected static final int CHECKSUM_SIZE
protected static final int CONTAINER_INFO_SIZE
protected static final int STORED_PAGE_ARG_NUM
protected static final int ALLOC_PAGE_ARG_NUM
public static final long FIRST_ALLOC_PAGE_NUMBER
public static final long FIRST_ALLOC_PAGE_OFFSET
private static final int FILE_DROPPED
private static final int FILE_COMMITTED_DROP
private static final int FILE_REUSABLE_RECORDID
protected static final java.lang.String SPACE_TRACE
Constructor Detail |
protected FileContainer(BaseDataFileFactory factory)
Method Detail |
public int getTypeFormatId()
getTypeFormatId
in interface TypedFormat
public SpaceInfo getSpaceInfo(BaseContainerHandle handle) throws StandardException
getSpaceInfo
in class BaseContainer
StandardException
public Cacheable setIdentity(java.lang.Object key) throws StandardException
setIdentity
in interface Cacheable
StandardException
- Some problem in opening a container.Cacheable.setIdentity(java.lang.Object)
protected Cacheable setIdent(ContainerKey newIdentity) throws StandardException
Open the container with key "newIdentity".
should be same name as setIdentity but seems to cause method resolution ambiguities
StandardException
- Some problem in opening a container.Cacheable.setIdentity(java.lang.Object)
public Cacheable createIdentity(java.lang.Object key, java.lang.Object createParameter) throws StandardException
Cacheable
createIdentity
in interface Cacheable
StandardException
- If forCreate is true and the object cannot be created.CacheManager.create(java.lang.Object, java.lang.Object)
protected Cacheable createIdent(ContainerKey newIdentity, java.lang.Object createParameter) throws StandardException
StandardException
public void clearIdentity()
Cacheable
clearIdentity
in interface Cacheable
clearIdentity
in class BaseContainer
public boolean isDirty()
isDirty
in interface Cacheable
Cacheable.isDirty()
public void preDirty(boolean preDirtyOn)
BaseContainer
preDirty
in class BaseContainer
protected void setDirty(boolean dirty)
protected abstract void createContainer(ContainerKey newIdentity) throws StandardException
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.
StandardException
- Cloudscape Standard error policyprotected abstract boolean openContainer(ContainerKey newIdentity) throws StandardException
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.
StandardException
- Standard exception policy.protected abstract void closeContainer()
protected void dropContainer(LogInstant instant, boolean isDropped)
dropContainer
in class BaseContainer
Transaction.dropContainer(org.apache.derby.iapi.store.raw.ContainerKey)
protected final void bumpContainerVersion(LogInstant instant)
protected long getContainerVersion()
BaseContainer
getContainerVersion
in class BaseContainer
public void getContainerProperties(java.util.Properties prop) throws StandardException
Request the value of properties that are associated with a container. The following properties can be requested: derby.storage.pageSize derby.storage.pageReservedSpace derby.storage.minimumRecordSize 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"); }
getContainerProperties
in class BaseContainer
prop
- Property list to fill in.
StandardException
- Standard exception policy.protected void readHeader(java.io.DataInput fileData) throws java.io.IOException, StandardException
StandardException
- Cloudscape Standard error policy
java.io.IOException
- error in reading the header from fileprivate void initContainerHeader(boolean changeContainer)
private void readHeaderFromArray(byte[] a) throws StandardException, java.io.IOException
StandardException
- Cloudscape Standard error policy
java.io.IOException
- error in reading the header from fileprotected void writeHeader(byte[] pageData) throws StandardException, java.io.IOException
StandardException
- Cloudscape Standard error policy
java.io.IOException
- error in writing the header to fileprotected void writeHeader(java.io.DataOutput fileData, boolean create, byte[] epage) throws java.io.IOException, StandardException
StandardException
- Cloudscape Standard error policy
java.io.IOException
- error in writing the header to fileprotected byte[] getEmbryonicPage(java.io.DataInput fileData) throws java.io.IOException
java.io.IOException
- error in read the embryonic page from fileprivate void writeHeaderToArray(byte[] a) throws java.io.IOException
java.io.IOException
- error in writing the headerprotected ByteArray logCreateContainerInfo() throws StandardException
logCreateContainerInfo
in class BaseContainer
StandardException
- Cloudscape Standard error policyprivate void createInfoFromLog(ByteArray byteArray) throws StandardException
StandardException
private void createInfoFromProp(java.util.Properties createArgs) throws StandardException
StandardException
protected boolean canUpdate()
BaseContainer
canUpdate
in class BaseContainer
protected void deallocatePage(BaseContainerHandle handle, BasePage page) throws StandardException
deallocatePage
in class BaseContainer
handle
- the container handle doing the deallocationpage
- the page to be deallocated. It is latched upon entry and
will be unlatched by the caller of this function
StandardException
- Cloudscape Standard error policyprivate void deallocatePagenum(BaseContainerHandle handle, long pnum) throws StandardException
StandardException
protected BasePage newPage(BaseContainerHandle userHandle, RawTransaction ntt, BaseContainerHandle allocHandle, boolean isOverflow) throws StandardException
newPage
in class BaseContainer
userHandle
- - the container handle opened by the user transaction,
use this to latch the new user pagentt
- - 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
StandardException
- Standard Cloudscape error policyprotected void clearPreallocThreshold()
BaseContainer
clearPreallocThreshold
in class BaseContainer
protected void prepareForBulkLoad(BaseContainerHandle handle, int numPage)
BaseContainer
prepareForBulkLoad
in class BaseContainer
private boolean pageValid(BaseContainerHandle handle, long pagenum) throws StandardException
StandardException
private long getLastPageNumber(BaseContainerHandle handle) throws StandardException
StandardException
private AllocPage findAllocPageForAdd(BaseContainerHandle allocHandle, RawTransaction ntt, long lastAllocatedPage) throws StandardException
StandardException
private AllocPage findLastAllocPage(BaseContainerHandle handle, RawTransaction tran)
private AllocPage makeAllocPage(RawTransaction ntt, BaseContainerHandle handle, long pageNumber, long pageOffset, int containerInfoSize) throws StandardException
StandardException
protected BasePage initPage(BaseContainerHandle allochandle, PageKey pkey, int[] createArgs, long pageOffset, boolean reuse, boolean overflow) throws StandardException
allochandle
- the contianer handle to initialize the page with - the nttpkey
- the page number of the page to be initializedreuse
- is true if we are reusing a page that has
already been initialized once
StandardException
- Cloudscape Standard error policyprivate BasePage getUserPage(BaseContainerHandle handle, long pageNumber, boolean overflowOK, boolean wait) throws StandardException
handle
- the container handlepageNumber
- the page number of the page to getoverflowOK
- if true then an overflow page is OK,
if false, then only non-overflow page is OKwait
- if true then wait for a latch
StandardException
- Standard Cloudscape error policyprotected void trackUnfilledPage(long pagenumber, boolean unfilled)
protected BasePage getPage(BaseContainerHandle handle, long pageNumber, boolean wait) throws StandardException
getPage
in class BaseContainer
StandardException
- Standard Cloudscape error policyprotected BasePage getAnyPage(BaseContainerHandle handle, long pageNumber) throws StandardException
getAnyPage
in class BaseContainer
StandardException
- Cloudscape Standard error policyprotected BasePage reCreatePageForLoadTran(BaseContainerHandle handle, int pageFormat, long pageNumber, long pageOffset) throws StandardException
reCreatePageForLoadTran
in class BaseContainer
StandardException
- Cloudscape Standard error policyprotected BasePage getAllocPage(long pageNumber) throws StandardException
getAllocPage
in class BaseContainer
StandardException
- Cloudscape Standard error policyprotected BasePage getHeadPage(BaseContainerHandle handle, long pageNumber, boolean wait) throws StandardException
getHeadPage
in class BaseContainer
StandardException
- Cloudscape Standard error policyprotected BasePage getFirstHeadPage(BaseContainerHandle handle, boolean wait) throws StandardException
getFirstHeadPage
in class BaseContainer
StandardException
- Cloudscape Standard error policyprotected BasePage getNextHeadPage(BaseContainerHandle handle, long pageNumber, boolean wait) throws StandardException
getNextHeadPage
in class BaseContainer
StandardException
- Standard Cloudscape error policyprivate BasePage getInsertablePage(BaseContainerHandle handle, long pageNumber, boolean wait, boolean overflowOK) throws StandardException
StandardException
protected BasePage getPageForInsert(BaseContainerHandle handle, int flag) throws StandardException
getPageForInsert
in class BaseContainer
StandardException
- Standard Cloudscape error policyprivate long getUnfilledPageNumber(BaseContainerHandle handle, long pagenum) throws StandardException
StandardException
public long getEstimatedRowCount(int flag)
getEstimatedRowCount
in class BaseContainer
ContainerHandle.getEstimatedRowCount(int)
public void setEstimatedRowCount(long count, int flag)
setEstimatedRowCount
in class BaseContainer
ContainerHandle.setEstimatedRowCount(long, int)
protected void updateEstimatedRowCount(int delta)
public long getEstimatedPageCount(BaseContainerHandle handle, int flag) throws StandardException
getEstimatedPageCount
in class BaseContainer
StandardException
- Standard Cloudscape error policyContainerHandle.getEstimatedPageCount(int)
protected abstract void readPage(long pageNumber, byte[] pageData) throws java.io.IOException, StandardException
java.io.IOException
- error reading page
StandardException
- standard cloudscape error messageprotected abstract void writePage(long pageNumber, byte[] pageData, boolean syncPage) throws java.io.IOException, StandardException
java.io.IOException
- error writing page
StandardException
- Standard Cloudscape error policyprotected void decryptPage(byte[] pageData, int pageSize) throws StandardException
StandardException
- Standard Cloudscape error policyprotected byte[] encryptPage(byte[] pageData, int pageSize) throws StandardException
StandardException
- Standard Cloudscape error policyprotected abstract int preAllocate(long lastPreallocPagenum, int preAllocSize)
lastPreallocPagenum
- the last preallocated page number as known
by the allocation pagepreAllocSize
- 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.
protected int doPreAllocatePages(long lastPreallocPagenum, int preAllocSize)
protected int getPageSize()
protected int getSpareSpace()
protected int getMinimumRecordSize()
private void switchToMultiInsertPageMode(BaseContainerHandle handle) throws StandardException
StandardException
private long getLastInsertedPage()
private long getLastUnfilledPage()
private void initializeLastInsertedPage(int size)
private void setLastInsertedPage(long val)
private void setLastUnfilledPage(long val)
protected void letGo(BaseContainerHandle handle)
letGo
in class BaseContainer
protected BasePage latchPage(BaseContainerHandle handle, BasePage foundPage, boolean wait) throws StandardException
latchPage
in class BaseContainer
StandardException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |