Top Description Fields Constructors Methods
org.apache.derby.impl.store.raw.data

pack-priv abstract Class FileContainer

extends BaseContainer
implements Cacheable, TypedFormat
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.io.TypedFormat, org.apache.derby.iapi.services.cache.Cacheable
Known Direct Subclasses
org.apache.derby.impl.store.raw.data.InputStreamContainer, org.apache.derby.impl.store.raw.data.RAFContainer
Imports
org.apache.derby.shared.common.reference.Property, .Limits, .SQLState, org.apache.derby.iapi.services.cache.Cacheable, .CacheManager, org.apache.derby.iapi.services.context.ContextService, org.apache.derby.iapi.services.monitor.Monitor, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.services.io.FormatIdOutputStream, .StoredFormatIds, .TypedFormat, .ArrayInputStream, .ArrayOutputStream, org.apache.derby.iapi.util.InterruptStatus, .InterruptDetectedException, .ByteArray, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.raw.ContainerHandle, .ContainerKey, .Page, .PageKey, .RecordHandle, .RawStoreFactory, .Transaction, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.store.raw.xact.RawTransaction, org.apache.derby.iapi.store.access.TransactionController, .AccessFactory, .SpaceInfo, org.apache.derby.iapi.services.property.PropertyUtil, java.io.IOException, .DataInput, java.util.Properties, java.util.zip.CRC32, org.apache.derby.io.StorageRandomAccessFile

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

Field Summary

Modifier and TypeField and Description
protected AllocationCache
private boolean
protected boolean
private CRC32
protected static final int
private static final int
CONTAINER_FORMAT_ID_SIZE

the container format must fit in this many bytes

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 reusable recordId sequence number 8 bytes long spare3 8 bytes long checksum container info size is 80 bytes, with 10 bytes of spare space

protected final CacheManager
pack-priv byte[]
protected long
protected final BaseDataFileFactory
private static final int
private byte[]
private long
estimatedPageCount

An estimated page count.

protected long
private static final int
private static final int
private static final int
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

public static final long
protected long
protected long
protected static final int
protected short
protected boolean
private long
lastAllocatedPage

The last allocated page.

private long[]
lastInsertedPage

The page that was last inserted into.

private int
protected LogInstant
private long
lastUnfilledPage

The last unfilled page found.

private static final int
private static final int
protected int
protected final CacheManager
protected int
private static final int
private int
private int
protected boolean
private long
reusableRecordIdSequenceNumber

The sequence number for reusable recordIds .

protected static final String
protected int
Inherited from org.apache.derby.impl.store.raw.data.BaseContainer:
identityisCommittedDropisDroppedisReusableRecordId

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected abstract void
backupContainer(BaseContainerHandle
the container handle.
handle
,
String
location of the backup container.
backupLocation
)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.backupContainer.

backup the container.

protected final void
bumpContainerVersion(LogInstant instant)

increment the version by one and return the new version.

protected boolean
canUpdate()

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.canUpdate.

Can the container be updated.

public void
protected void
clearPreallocThreshold()

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.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.

pack-priv abstract void
protected void
compressContainer(RawTransaction
- the nested top transaction for the purpose of freeing space. 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
ntt
,
BaseContainerHandle allocHandle)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.compressContainer.

Compress free space from container.

pack-priv abstract void
createContainer(ContainerKey newIdentity)

Create a new container.

protected Cacheable
createIdent(ContainerKey newIdentity, Object createParameter)

public Cacheable
createIdentity(Object
The handle on the cacheable
key
,
Object
Creation details
createParameter
)

Implements org.apache.derby.iapi.services.cache.Cacheable.createIdentity.

Create a new item.

private void
createInfoFromLog(ByteArray byteArray)

Set container properties from the passed in ByteArray, which is created by logCreateContainerInfo.

private void
createInfoFromProp(Properties createArgs)

Set container properties from the passed in createArgs.

protected void
deallocatePage(BaseContainerHandle
the container handle doing the deallocation
handle
,
BasePage
the page to be deallocated. It is latched upon entry and will be unlatched by the caller of this function
page
)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.deallocatePage.

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)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.dropContainer.

Drop Container.

protected byte[]
encryptPage(byte[] pageData, int pageSize, byte[] encryptionBuffer, boolean newEngine)

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)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getAllocPage.

Get an alloc page - only accessible to the raw store (container and recovery)

protected BasePage
getAnyPage(BaseContainerHandle handle, long pageNumber)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getAnyPage.

Get any old page - turn off all validation

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

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getContainerProperties.

Request the system properties associated with a container.

protected long
pack-priv static ContextService
getContextService()

Must be limited to package visibility so that user code can't call this entry point.

protected byte[]
getEmbryonicPage(DataInput fileData)

Get an embryonic page from the dataInput stream.

pack-priv byte[]

Returns:

a byte array containing the embryonic page
getEmbryonicPage
(StorageRandomAccessFile
the file to read from
file
,
long
where to start reading (normally FileContainer.FIRST_ALLOC_PAGE_OFFSET)
offset
)

Read an embryonic page (that is, a section of the first alloc page that is so large that we know all the borrowed space is included in it) from the specified offset in a StorageRandomAccessFile.

protected byte[]

Returns:

byte array to be used for encryping a page.
getEncryptionBuffer
()

Get encryption buffer.

public long
public long
getEstimatedRowCount(int flag)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getEstimatedRowCount.

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

protected BasePage
getFirstHeadPage(BaseContainerHandle handle, boolean wait)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getFirstHeadPage.

Get the first valid page in the container

protected BasePage
getHeadPage(BaseContainerHandle handle, long pageNumber, boolean wait)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getHeadPage.

Get only a valid, non-overflow page.

private BasePage
getInsertablePage(BaseContainerHandle handle, long pageNumber, boolean wait, boolean overflowOK)

private synchronized long
protected long
private synchronized long
protected BasePage

Returns:

the latched page
getLatchedPage
(BaseContainerHandle
the container handle used to latch the page
handle
,
long
the page number of the page to get
pageNumber
)

Get a latched page.

protected int
protected BasePage
getNextHeadPage(BaseContainerHandle handle, long pageNumber, boolean wait)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getNextHeadPage.

Get the next page in the container.

protected BasePage
getPage(BaseContainerHandle handle, long pageNumber, boolean wait)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getPage.

Get a valid (non-deallocated or free) page in the container.

protected BasePage
getPageForCompress(BaseContainerHandle handle, int flag, long pageno)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getPageForCompress.

Get candidate page to move a row for compressing the table.

protected BasePage
getPageForInsert(BaseContainerHandle handle, int flag)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getPageForInsert.

Get a potentially suitable page for insert and latch it.

protected int
public final long

Returns:

reusable RecordId sequence number for the container.
getReusableRecordIdSequenceNumber
()

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getReusableRecordIdSequenceNumber.

Get the reusable RecordId sequence number for the container.

private static Object
getServiceModule(final Object serviceModule, final String factoryInterface)

Must be private so that user code can't call this entry point.

public SpaceInfo
getSpaceInfo(BaseContainerHandle handle)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.getSpaceInfo.

Get information about space used by the container.

protected int
public int
private long
private BasePage

Returns:

the latched page
MT - thread safe
getUserPage
(BaseContainerHandle
the container handle
handle
,
long
the page number of the page to get
pageNumber
,
boolean
if true then an overflow page is OK, if false, then only non-overflow page is OK
overflowOK
,
boolean
if true then wait for a latch
wait
)

Get a page in the container.

protected final void
private void
initContainerHeader(boolean changeContainer)

private synchronized void
protected BasePage

Returns:

a latched page that has been initialized.
initPage
(BaseContainerHandle
the contianer handle to initialize the page with - the ntt
allochandle
,
PageKey
the page number of the page to be initialized
pkey
,
PageCreationArgs
the arguments for page creation
createArgs
,
long pageOffset, boolean
is true if we are reusing a page that has already been initialized once
reuse
,
boolean overflow)

Initialize a page

public boolean
isDirty()

Implements org.apache.derby.iapi.services.cache.Cacheable.isDirty.

We treat this container as dirty if it has the container file open.

protected BasePage
protected void
letGo(BaseContainerHandle handle)

Overrides org.apache.derby.impl.store.raw.data.BaseContainer.letGo.

The container is kept by the find() in File.openContainer.

protected ByteArray
logCreateContainerInfo()

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.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
- the container handle opened by the user transaction, use this to latch the new user page
userHandle
,
RawTransaction
- 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
ntt
,
BaseContainerHandle allocHandle, boolean isOverflow)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.newPage.

Create a new page in the container.

pack-priv abstract boolean
openContainer(ContainerKey newIdentity)

Open a container.

private boolean
pageValid(BaseContainerHandle handle, long pagenum)

protected abstract int

Returns:

number of successfully preallocated page, or 0 if no page has been preallocated
preAllocate
(long
the last preallocated page number as known by the allocation page
lastPreallocPagenum
,
int
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.
preAllocSize
)

preAllocate writes out the preallocated pages to disk if necessary.

public void
preDirty(boolean preDirtyOn)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.preDirty.

The container is about to be modified.

protected void
prepareForBulkLoad(BaseContainerHandle handle, int numPage)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.prepareForBulkLoad.

The container will be grown vastly, prepare for it.

protected void
readHeader(byte[]
the embryonic page to read the header from
epage
)

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
reCreatePageForRedoRecovery(BaseContainerHandle handle, int pageFormat, long pageNumber, long pageOffset)

Implements abstract org.apache.derby.impl.store.raw.data.BaseContainer.reCreatePageForRedoRecovery.

ReCreate a page for rollforward recovery.

protected void
setDirty(boolean dirty)

public void
protected Cacheable
setIdent(ContainerKey newIdentity)

Open the container.

public Cacheable

Returns:

a valid object if the container was successfully opened, null if it does not exist.
setIdentity
(Object
The handle on the cacheable
key
)

Implements org.apache.derby.iapi.services.cache.Cacheable.setIdentity.

Open the container.

private synchronized void
private synchronized void
private synchronized void
protected void
trackUnfilledPage(long pagenumber, boolean unfilled)

protected void
updateEstimatedRowCount(int delta)

Update estimated row count by page as it leaves the cache.

pack-priv void
writeAtOffset(StorageRandomAccessFile
the file to write to
file
,
byte[]
the bytes to write
bytes
,
long
the offset to start writing at
offset
)

Write a sequence of bytes at the given offset in a file.

protected void
writeHeader(Object identity, byte[] pageData)

Write the container header to a page array (the first allocation page)

protected void
writeHeader(Object identity, StorageRandomAccessFile file, boolean create, byte[] epage)

Write the container header directly to file.

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.

Inherited from org.apache.derby.impl.store.raw.data.BaseContainer:
addPagecompressContainerencryptOrDecryptContainerfillInIdentityflushAllgetAllocPagegetAnyPagegetCommittedDropStategetContainerIdgetContainerStatusgetDeallocLockgetDroppedStategetFirstPagegetIdentitygetNextPagegetSegmentIdisReusableRecordIdlockAttributeslockerAlwaysCompatiblelockEventremoveContainerremovePagerequestCompatiblesetCommittedDropStatesetDroppedStatesetReusableRecordIdStatetruncatetruncatePagesunlockEventuse