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

pack-priv Class RAFContainer

extends FileContainer
Class Inheritance
Known Direct Subclasses
org.apache.derby.impl.store.raw.data.RAFContainer4, org.apache.derby.impl.store.raw.data.TempRAFContainer
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.services.io.FormatIdUtil, .FileUtil, org.apache.derby.iapi.util.InterruptStatus, .InterruptDetectedException, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.raw.ContainerHandle, .ContainerKey, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.io.StorageFile, .StorageRandomAccessFile, java.io.IOException, .File, .FileNotFoundException, .RandomAccessFile

RAFContainer (short for RandomAccessFileContainer) is a concrete subclass of FileContainer for FileContainers which are implemented on java.io.RandomAccessFile.

Field Summary

Modifier and TypeField and Description
private int
private boolean
private StorageFile
private ContainerKey
private LogInstant
private boolean
private boolean
private static final int
protected StorageRandomAccessFile
private String
private static final int
private static final int
private boolean
private boolean
protected boolean
private static final int
private static final int
private static final int
private static final int
Inherited from org.apache.derby.impl.store.raw.data.FileContainer:
allocCachecanUpdateCHECKSUM_SIZECONTAINER_INFO_SIZEcontainerCachecontainerInfocontainerVersiondataFactoryestimatedRowCountFIRST_ALLOC_PAGE_NUMBERFIRST_ALLOC_PAGE_OFFSETfirstAllocPageNumberfirstAllocPageOffsetformatIdIntegerinitialPagesisDirtylastLogInstantminimumRecordSizepageCachepageSizepreDirtySPACE_TRACEspareSpace

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

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

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

Backup the container.

public void
clean(boolean
Is clean called because container is being removed?
forRemove
)

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

Clean the container.

private void
pack-priv void
private void
copyFile(final StorageFile
the file to copy from
from
,
final File
the file to copy to
to
)

Copy the contents of a StorageFile to a java.io.File.

pack-priv synchronized void
protected void
encryptOrDecryptContainer(BaseContainerHandle
the container handle
handle
,
String
file to store the new version of the container in
newFilePath
,
boolean
tells whether to encrypt or not
doEncrypt
)

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

Creates encrypted or decrypted version of the container.

protected void
flushAll()

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

flush the cache to ensure all of my pages are written to disk

pack-priv synchronized StorageFile
getFileName(ContainerKey identity, boolean stub, boolean errorOK, boolean tryAlternatePath)

private RandomAccessFile

Returns:

a RandomAccessFile
getRandomAccessFile
(final File
the file to access
file
)

Get a RandomAccessFile for accessing a file in read-write mode.

pack-priv synchronized StorageRandomAccessFile
public synchronized boolean
isDirty()

Overrides org.apache.derby.impl.store.raw.data.FileContainer.isDirty.

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

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

pack-priv synchronized boolean
private boolean
padFile(StorageRandomAccessFile file, long pageOffset)

Pad the file upto the passed in page offset.

protected int
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
)

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.preAllocate.

Preallocate some pages if need be

protected StorageFile
privGetFileName(ContainerKey identity, boolean stub, boolean errorOK, boolean tryAlternatePath)

private boolean
protected void
readPage(long pageNumber, byte[] pageData)

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.readPage.

Read a page into the supplied array.

protected void
removeContainer(LogInstant instant, boolean
if true, leave a stub. If false, remove everything
leaveStub
)

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

Remove the container

private void
removeFile(final File
the file to remove
file
)

Remove a file.

pack-priv synchronized boolean
protected synchronized void
reopenContainer(ContainerKey currentIdentity)

Only used by RAFContainer4 (NIO) to reopen RAF when its channel gets closed due to interrupts.

public Object
run()

private synchronized void
protected void
truncatePages(long
The page number of the last valid page of the file. All pages after this one are truncated.
lastValidPagenum
)

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

Truncate pages of a container.

protected byte[]

Returns:

byte array of the the page data as it should be on the disk.
updatePageArray
(long
the page number of the page
pageNumber
,
byte[]
byte array that has the actual page data.
pageData
,
byte[]
buffer that is used to store encrypted version of the page, or null if encryption is to be skipped
encryptionBuf
,
boolean
whether to use the new encryption engine for encryption (only considered if encryptionBuf != null)
encryptWithNewEngine
)

Updates the page array with container header if the page is a first allocation page and encrypts the page data if the database is encrypted.

protected void
writePage(long pageNumber, byte[] pageData, boolean syncPage)

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.writePage.

Write a page from the supplied array.

private void
writeRAFHeader(Object identity, StorageRandomAccessFile file, boolean
if true, the container is being created if false, the container already exist
create
,
boolean
if true, sync the file
syncFile
)

Write the header of a random access file and sync it

Inherited from org.apache.derby.impl.store.raw.data.FileContainer:
bumpContainerVersioncanUpdateclearIdentityclearPreallocThresholdcompressContainercreateIdentcreateIdentitydeallocatePagedecryptPagedoPreAllocatePagesdropContainerencryptPagegetAllocPagegetAnyPagegetContainerPropertiesgetContainerVersiongetContextServicegetEmbryonicPagegetEmbryonicPagegetEncryptionBuffergetEstimatedPageCountgetEstimatedRowCountgetFirstHeadPagegetHeadPagegetLastPageNumbergetLatchedPagegetMinimumRecordSizegetNextHeadPagegetPagegetPageForCompressgetPageForInsertgetPageSizegetReusableRecordIdSequenceNumbergetSpaceInfogetSpareSpacegetTypeFormatIdincrementReusableRecordIdSequenceNumberinitPagelatchPageletGologCreateContainerInfonewPagepreDirtyprepareForBulkLoadreadHeaderreCreatePageForRedoRecoverysetDirtysetEstimatedRowCountsetIdentsetIdentitytrackUnfilledPageupdateEstimatedRowCountwriteAtOffsetwriteHeaderwriteHeader

Field Detail

actionCodeback to summary
private int actionCode
actionErrorOKback to summary
private boolean actionErrorOK
actionFileback to summary
private StorageFile actionFile
actionIdentityback to summary
private ContainerKey actionIdentity
actionInstantback to summary
private LogInstant actionInstant
actionStubback to summary
private boolean actionStub
actionTryAlternatePathback to summary
private boolean actionTryAlternatePath
CREATE_CONTAINER_ACTIONback to summary
private static final int CREATE_CONTAINER_ACTION
fileDataback to summary
protected StorageRandomAccessFile fileData
fileNameback to summary
private String fileName
GET_FILE_NAME_ACTIONback to summary
private static final int GET_FILE_NAME_ACTION
GET_RANDOM_ACCESS_FILE_ACTIONback to summary
private static final int GET_RANDOM_ACCESS_FILE_ACTION
inBackupback to summary
private boolean inBackup
inRemoveback to summary
private boolean inRemove
needsSyncback to summary
protected boolean needsSync
OPEN_CONTAINER_ACTIONback to summary
private static final int OPEN_CONTAINER_ACTION
REMOVE_FILE_ACTIONback to summary
private static final int REMOVE_FILE_ACTION
REOPEN_CONTAINER_ACTIONback to summary
private static final int REOPEN_CONTAINER_ACTION
STUBBIFY_ACTIONback to summary
private static final int STUBBIFY_ACTION

Constructor Detail

RAFContainerback to summary
pack-priv RAFContainer(BaseDataFileFactory factory)

Method Detail

backupContainerback to summary
protected void backupContainer(BaseContainerHandle handle, String backupLocation) throws StandardException

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

Backup the container. The container is written to the backup by reading the pages through the page cache, and then writing into the backup container. If the container is dropped(commitetd drop), only container stub is copied to the backup using simple file copy. MT - At any given time only one backup thread is allowed, but when backup in progress DML/DDL operations can run in parallel. Pages are latched while writing them to the backup to avoid copying partial changes to the pages. Online backup does not acquire any user level locks , so users can drop tables when backup is in progress. So it is possible that Container Removal request can come in when container backup is in progress. This case is handled by using the synchronization on this object monitor and using inRemove and inBackup flags. Conatiner removal checks if backup is in progress and wait for the backup to yield to continue the removal. Basic idea is to give preference to remove by stopping the backup of the container temporarily, when the remove container is requested by another thread. Generally, it takes more time to backup a regular container than the stub becuase stub is just one page. After each page copy, a check is made to find if a remove is requested and if it is then backup of the container is aborted and the backup thread puts itself into the wait state until remove request thread notifies that the remove is complete. When remove request compeletes stub is copied into the backup. Compress is blocked when backup is in progesss, so truncation of the container can not happen when backup is in progess. No need to synchronize backup of the container with truncation.

Parameters
handle:BaseContainerHandle

the container handle.

backupLocation:String

location of the backup container.

Exceptions
StandardException:
Derby Standard error policy
cleanback to summary
public void clean(boolean forRemove) throws StandardException

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

Clean the container.

Write out the container header and sync all dirty pages of this container to disk before returning.

checkpoint calls this interface through callbacks by telling the cache manager to clean all containers in the open container cache. This sync of the file happens as part of writing and then syncing the container header in writeRAFHeader().

Parameters
forRemove:boolean

Is clean called because container is being removed?

Exceptions
StandardException:
Standard exception policy.
clearDirtyback to summary
private void clearDirty()
closeContainerback to summary
pack-priv void closeContainer()

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.closeContainer.

copyFileback to summary
private void copyFile(final StorageFile from, final File to) throws StandardException

Copy the contents of a StorageFile to a java.io.File.

Parameters
from:StorageFile

the file to copy from

to:File

the file to copy to

Exceptions
StandardException:
if the copying failed
createContainerback to summary
pack-priv synchronized void createContainer(ContainerKey newIdentity) throws StandardException

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.createContainer.

Doc from org.apache.derby.impl.store.raw.data.FileContainer.createContainer.

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.

Exceptions
StandardException:
Derby Standard error policy
encryptOrDecryptContainerback to summary
protected void encryptOrDecryptContainer(BaseContainerHandle handle, String newFilePath, boolean doEncrypt) throws StandardException

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

Creates encrypted or decrypted version of the container. Reads all the pages of the container from the original container through the page cache, then either encrypts page data with the new encryption mechanism or leaves the page data un-encrypted, and finally writes the data to the specified new container file.

The encryption and decryption engines used to carry out the cryptographic operation(s) are configured through the raw store, and accessed via the data factory. Note that the pages have already been decrypted before being put into the page cache.

Parameters
handle:BaseContainerHandle

the container handle

newFilePath:String

file to store the new version of the container in

doEncrypt:boolean

tells whether to encrypt or not

Exceptions
StandardException:
Derby Standard error policy
flushAllback to summary
protected void flushAll() throws StandardException

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

flush the cache to ensure all of my pages are written to disk

Exceptions
StandardException:
Standard Derby error policy
getFileNameback to summary
pack-priv synchronized StorageFile getFileName(ContainerKey identity, boolean stub, boolean errorOK, boolean tryAlternatePath) throws StandardException
getRandomAccessFileback to summary
private RandomAccessFile getRandomAccessFile(final File file) throws IOException

Get a RandomAccessFile for accessing a file in read-write mode.

Parameters
file:File

the file to access

Returns:RandomAccessFile

a RandomAccessFile

Exceptions
IOException:
if some other I/O error happens
FileNotFoundException:
if file cannot be opened in read-write mode
getRandomAccessFileback to summary
pack-priv synchronized StorageRandomAccessFile getRandomAccessFile(StorageFile file) throws StandardException
isDirtyback to summary
public synchronized boolean isDirty()

Overrides org.apache.derby.impl.store.raw.data.FileContainer.isDirty.

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

Doc from org.apache.derby.impl.store.raw.data.FileContainer.isDirty.

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

Returns:boolean

Doc from org.apache.derby.iapi.services.cache.Cacheable.isDirty.

true if the object is dirty

openContainerback to summary
pack-priv synchronized boolean openContainer(ContainerKey newIdentity) throws StandardException

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.openContainer.

Doc from org.apache.derby.impl.store.raw.data.FileContainer.openContainer.

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.

Exceptions
StandardException:
Standard exception policy.
padFileback to summary
private boolean padFile(StorageRandomAccessFile file, long pageOffset) throws IOException, StandardException

Pad the file upto the passed in page offset. Returns true if the file needed padding.

preAllocateback to summary
protected int preAllocate(long lastPreallocPagenum, int preAllocSize)

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.preAllocate.

Preallocate some pages if need be

Parameters
lastPreallocPagenum:long

Doc from org.apache.derby.impl.store.raw.data.FileContainer.preAllocate.

the last preallocated page number as known by the allocation page

preAllocSize:int

Doc from org.apache.derby.impl.store.raw.data.FileContainer.preAllocate.

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

Doc from org.apache.derby.impl.store.raw.data.FileContainer.preAllocate.

number of successfully preallocated page, or 0 if no page has been preallocated

privGetFileNameback to summary
protected StorageFile privGetFileName(ContainerKey identity, boolean stub, boolean errorOK, boolean tryAlternatePath) throws StandardException
privRemoveFileback to summary
private boolean privRemoveFile(StorageFile file) throws StandardException
readPageback to summary
protected void readPage(long pageNumber, byte[] pageData) throws IOException, StandardException

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.readPage.

Read a page into the supplied array.
MT - thread safe

Exceptions
IOException:
exception reading page
StandardException:
Standard Derby error policy
removeContainerback to summary
protected void removeContainer(LogInstant instant, boolean leaveStub) throws StandardException

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

Remove the container

Parameters
leaveStub:boolean

Doc from org.apache.derby.impl.store.raw.data.BaseContainer.removeContainer.

if true, leave a stub. If false, remove everything

Exceptions
StandardException:
Standard Derby error policy
removeFileback to summary
private void removeFile(final File file) throws StandardException

Remove a file.

Parameters
file:File

the file to remove

Exceptions
StandardException:
if the file could not be removed
removeFileback to summary
pack-priv synchronized boolean removeFile(StorageFile file) throws StandardException
reopenContainerback to summary
protected synchronized void reopenContainer(ContainerKey currentIdentity) throws StandardException

Only used by RAFContainer4 (NIO) to reopen RAF when its channel gets closed due to interrupts.

Exceptions
StandardException:
standard exception policy
runback to summary
public Object run() throws StandardException
stubbifyback to summary
private synchronized void stubbify(LogInstant instant) throws StandardException
truncatePagesback to summary
protected void truncatePages(long lastValidPagenum) throws StandardException

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

Truncate pages of a container.

Truncate all pages from lastValidPagenum+1 through the end of the file.

Parameters
lastValidPagenum:long

The page number of the last valid page of the file. All pages after this one are truncated.

Exceptions
StandardException:
Standard exception policy.
updatePageArrayback to summary
protected byte[] updatePageArray(long pageNumber, byte[] pageData, byte[] encryptionBuf, boolean encryptWithNewEngine) throws StandardException, IOException

Updates the page array with container header if the page is a first allocation page and encrypts the page data if the database is encrypted.

Parameters
pageNumber:long

the page number of the page

pageData:byte[]

byte array that has the actual page data.

encryptionBuf:byte[]

buffer that is used to store encrypted version of the page, or null if encryption is to be skipped

encryptWithNewEngine:boolean

whether to use the new encryption engine for encryption (only considered if encryptionBuf != null)

Returns:byte[]

byte array of the the page data as it should be on the disk.

writePageback to summary
protected void writePage(long pageNumber, byte[] pageData, boolean syncPage) throws IOException, StandardException

Implements abstract org.apache.derby.impl.store.raw.data.FileContainer.writePage.

Write a page from the supplied array.
MT - thread safe

Exceptions
IOException:
IO error accessing page
StandardException:
Standard Derby error policy
writeRAFHeaderback to summary
private void writeRAFHeader(Object identity, StorageRandomAccessFile file, boolean create, boolean syncFile) throws IOException, StandardException

Write the header of a random access file and sync it

Parameters
create:boolean

if true, the container is being created if false, the container already exist

syncFile:boolean

if true, sync the file