Class BaseDataFileFactory
- java.lang.Object
-
- org.apache.derby.impl.store.raw.data.BaseDataFileFactory
-
- All Implemented Interfaces:
- java.security.PrivilegedExceptionAction<java.lang.Object>, CacheableFactory, ModuleControl, ModuleSupportable, Corruptable, DataFactory
- Direct Known Subclasses:
- BaseDataFileFactoryJ4
public class BaseDataFileFactory extends java.lang.Object implements DataFactory, CacheableFactory, ModuleControl, ModuleSupportable, java.security.PrivilegedExceptionAction<java.lang.Object>
Provides the abstract class with most of the implementation of DataFactory and ModuleControl shared by all the different filesystem implementations.RESOLVE (mikem - 2/19/98) - Currently only getContainerClass() is abstract, there are probably more routines which should be abstract. Also the other implementations should probably inherit from the abstract class, rather than from the DataFileFactory class. Also there probably should be a generic directory and the rest of the filesystem implementations parallel to it. I wanted to limit the changes going into the branch and then fix inheritance stuff in main.
The code in this class was moved over from DataFileFactory.java and then that file was made to inherit from this one.
-
-
Field Summary
-
Fields inherited from interface org.apache.derby.iapi.store.raw.data.DataFactory
DB_EX_LOCKFILE_NAME, DB_LOCKFILE_NAME, MODULE, TEMP_SEGMENT_NAME
-
-
Constructor Summary
Constructors Constructor and Description BaseDataFileFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description longaddAndLoadStreamContainer(RawTransaction t, long segmentId, java.util.Properties tableProperties, RowSource rowSource)Add and load a stream containerlongaddContainer(RawTransaction t, long segmentId, long input_containerid, int mode, java.util.Properties tableProperties, int temporaryFlag)Add a container with a specified page size to a segment.voidbackupDataFiles(Transaction rt, java.io.File backupDir)Back up the data segment of the database.voidboot(boolean create, java.util.Properties startParams)Boot this module with the given properties.booleancanSupport(java.util.Properties startParams)See if this implementation can support any attributes that are listed in properties.voidcheckpoint()Implement checkpoint operation, write/sync all pages in cache.voidcreateFinished()Database creation finishedbooleandatabaseEncrypted()Returns if data base is in encrypted mode.intdecrypt(byte[] ciphertext, int offset, int length, byte[] cleartext, int outputOffset)Decrypt cleartext from ciphertext.voiddecryptAllContainers(RawTransaction t)Decrypts all the containers in the data segment.voiddropContainer(RawTransaction t, ContainerKey ckey)Drop a container.voiddropStreamContainer(RawTransaction t, long segmentId, long containerId)Drop a stream container.intencrypt(byte[] cleartext, int offset, int length, byte[] ciphertext, int outputOffset, boolean newEngine)Encrypt cleartext into ciphertext.voidencryptAllContainers(RawTransaction t)Encrypt all the containers in the data segment.voidfreezePersistentStore()Backup restore - stop writing dirty pages or container to diskStorageFilegetAlternateContainerPath(ContainerKey containerId, boolean stub)Return an alternate path to container file relative to the root directory.StorageFilegetContainerPath(ContainerKey containerId, boolean stub)Return the path to a container file.intgetEncryptionBlockSize()Returns the encryption block size used by the algorithm at time of creation of an encrypted databaseFileResourcegetFileHandler()Get an object to handle non-transactional files.UUIDgetIdentifier()Return my unique identifierintgetIntParameter(java.lang.String parameterName, java.util.Properties properties, int defaultValue, int minimumValue, int maximumValue)longgetMaxContainerId()Return an id which can be used to create a container.java.lang.StringgetRootDirectory()Get the root directory of the data storage area.StorageFactorygetStorageFactory()java.lang.StringgetVersionedName(java.lang.String name, long generationId)voididle()booleanisReadOnly()Is the store read-only.booleanluceneLoaded()Return true if the Lucene plugin is loadedStandardExceptionmarkCorrupt(StandardException originalError)Really this is just a convience routine for callers that might not have access to a log factory.CacheablenewCacheable(CacheManager cm)ContainerHandleopenContainer(RawTransaction t, ContainerKey containerId, LockingPolicy locking, int mode)Open a container that is not droped.RawContainerHandleopenDroppedContainer(RawTransaction t, ContainerKey containerId, LockingPolicy locking, int mode)Open a container that may have been dropped.StreamContainerHandleopenStreamContainer(RawTransaction t, long segmentId, long containerId, boolean hold)open an exsisting streamContainervoidpostRecovery()Called after recovery is performed.intreclaimSpace(Serviceable work, ContextManager contextMgr)Reclaim space used by this factory.voidreCreateContainerForRedoRecovery(RawTransaction t, long segmentId, long containerId, ByteArray containerInfo)re-Create a container during redo recovery.voidremoveDroppedContainerFileStubs(LogInstant redoLWM)Delete the stub files that are not required for recovery.voidremoveOldVersionOfContainers()Removes old versions of the containers after a cryptographic operation on the database.voidremoveStubsOK()Tell the data factory it is OK to remove committed deleted containers when the data factory shuts down.java.lang.Objectrun()voidsetDatabaseEncrypted(boolean isEncrypted)Sets whether the database is encrypted.voidsetRawStoreFactory(RawStoreFactory rsf, boolean create, java.util.Properties startParams)make data factory aware of which raw store factory it belongs to Also need to boot the LogFactoryvoidsetupCacheCleaner(DaemonService daemon)Set up the cache cleaner for the container cache and the page cache.voidstop()Stop the module.voidstubFileToRemoveAfterCheckPoint(StorageFile file, LogInstant logInstant, java.lang.Object identity)keeps track of information about the stub files of the committed deleted containers.voidunfreezePersistentStore()Backup restore - start writing dirty pages or container to diskvoidwriteFinished()Backup restore - write finished, if this is the last writer, allow the persistent store to proceed.voidwriteInProgress()Backup restore - don't allow the persistent store to be frozen - or if it is already frozen, block.
-
-
-
Method Detail
-
canSupport
public boolean canSupport(java.util.Properties startParams)
Description copied from interface:ModuleSupportableSee if this implementation can support any attributes that are listed in properties. This call may be made on a newly created instance before the boot() method has been called, or after the boot method has been called for a running module.The module can check for attributes in the properties to see if it can fulfill the required behaviour. E.g. the raw store may define an attribute called RawStore.Recoverable. If a temporary raw store is required the property RawStore.recoverable=false would be added to the properties before calling bootServiceModule. If a raw store cannot support this attribute its canSupport method would return null. Also see the Monitor class's prologue to see how the identifier is used in looking up properties.
Actually a better way maybe to have properties of the form RawStore.Attributes.mandatory=recoverable,smallfootprint and RawStore.Attributes.requested=oltp,fast- Specified by:
canSupportin interfaceModuleSupportable- Returns:
- true if this instance can be used, false otherwise.
-
boot
public void boot(boolean create, java.util.Properties startParams) throws StandardExceptionDescription copied from interface:ModuleControlBoot this module with the given properties. Creates a module instance that can be found using the findModule() methods of Monitor. The module can only be found using one of these findModule() methods once this method has returned.An implementation's boot method can throw StandardException. If it is thrown the module is not registered by the monitor and therefore cannot be found through a findModule(). In this case the module's stop() method is not called, thus throwing this exception must free up any resources.
When create is true the contents of the properties object will be written to the service.properties of the persistent service. Thus any code that requires an entry in service.properties must explicitly place the value in this properties set using the put method.
Typically the properties object contains one or more default properties sets, which are not written out to service.properties. These default sets are how callers modify the create process. In a JDBC connection database create the first set of defaults is a properties object that contains the attributes that were set on the jdbc:derby: URL. This attributes properties set has the second default properties set as its default. This set (which could be null) contains the properties that the user set on their DriverManager.getConnection() call, and are thus not owned by Derby code, and thus must not be modified by Derby code.When create is false the properties object contains all the properties set in the service.properties file plus a limited number of attributes from the JDBC URL attributes or connection properties set. This avoids properties set by the user compromising the boot process. An example of a property passed in from the JDBC world is the bootPassword for encrypted databases.
Code should not hold onto the passed in properties reference after boot time as its contents may change underneath it. At least after the complete boot is completed, the links to all the default sets will be removed.
- Specified by:
bootin interfaceModuleControl- Throws:
StandardException- Module cannot be started.- See Also:
Monitor,ModuleFactory
-
stop
public void stop()
Description copied from interface:ModuleControlStop the module. The module may be found via a findModule() method until some time after this method returns. Therefore the factory must be prepared to reject requests to it once it has been stopped. In addition other modules may cache a reference to the module and make requests of it after it has been stopped, these requests should be rejected as well.- Specified by:
stopin interfaceModuleControl- Specified by:
stopin interfaceDataFactory- See Also:
Monitor,ModuleFactory
-
newCacheable
public Cacheable newCacheable(CacheManager cm)
- Specified by:
newCacheablein interfaceCacheableFactory
-
createFinished
public void createFinished() throws StandardExceptionDatabase creation finished- Specified by:
createFinishedin interfaceDataFactory- Throws:
StandardException- Standard Derby exception policy.
-
openContainer
public ContainerHandle openContainer(RawTransaction t, ContainerKey containerId, LockingPolicy locking, int mode) throws StandardException
Description copied from interface:DataFactoryOpen a container that is not droped.- Specified by:
openContainerin interfaceDataFactory- Parameters:
t- the raw transaction that is opening the containercontainerId- the container's identitylocking- the locking policymode- see the different mode in @see ContainerHandle then will return a null handle if the container is dropped.- Returns:
- the handle to the opened container
- Throws:
StandardException- Standard Derby error policy
-
openDroppedContainer
public RawContainerHandle openDroppedContainer(RawTransaction t, ContainerKey containerId, LockingPolicy locking, int mode) throws StandardException
Description copied from interface:DataFactoryOpen a container that may have been dropped. Only internal raw store code should call this, e.g. recovery.- Specified by:
openDroppedContainerin interfaceDataFactory- Throws:
StandardException- Standard Derby error policy- See Also:
DataFactory.openDroppedContainer(org.apache.derby.iapi.store.raw.xact.RawTransaction, org.apache.derby.iapi.store.raw.ContainerKey, org.apache.derby.iapi.store.raw.LockingPolicy, int)
-
addContainer
public long addContainer(RawTransaction t, long segmentId, long input_containerid, int mode, java.util.Properties tableProperties, int temporaryFlag) throws StandardException
Add a container with a specified page size to a segment.- Specified by:
addContainerin interfaceDataFactory- Parameters:
t- the transaction that is creating the containersegmentId- the segment where the container is to gomode- whether or not to LOGGED or not. The effect of this mode is only for this addContainer call, not persisently stored throughout the lifetime of the containertableProperties- properties of the container that is persistently stored throughout the lifetime of the container- Returns:
- the containerId of the newly created container
- Throws:
StandardException- Standard Derby error policy
-
addAndLoadStreamContainer
public long addAndLoadStreamContainer(RawTransaction t, long segmentId, java.util.Properties tableProperties, RowSource rowSource) throws StandardException
Add and load a stream container- Specified by:
addAndLoadStreamContainerin interfaceDataFactory- Parameters:
t- the transaction that is creating the containersegmentId- the segment where the container is to gotableProperties- properties of the container that is persistently stored throughout the lifetime of the containerrowSource- the data to load the container with- Returns:
- the containerId of the newly created stream container
- Throws:
StandardException- Standard Derby error policy
-
openStreamContainer
public StreamContainerHandle openStreamContainer(RawTransaction t, long segmentId, long containerId, boolean hold) throws StandardException
open an exsisting streamContainer- Specified by:
openStreamContainerin interfaceDataFactory- Returns:
- a valid StreamContainerHandle or null if the container does not exist.
- Throws:
StandardException- Standard Derby error policy- See Also:
DataFactory.openStreamContainer(org.apache.derby.iapi.store.raw.xact.RawTransaction, long, long, boolean)
-
dropStreamContainer
public void dropStreamContainer(RawTransaction t, long segmentId, long containerId) throws StandardException
Drop a stream container.Synchronisation
This call will remove the container.
- Specified by:
dropStreamContainerin interfaceDataFactory- Throws:
StandardException- Standard Derby error policy
-
reCreateContainerForRedoRecovery
public void reCreateContainerForRedoRecovery(RawTransaction t, long segmentId, long containerId, ByteArray containerInfo) throws StandardException
re-Create a container during redo recovery. called ONLY during recovery load tran.- Specified by:
reCreateContainerForRedoRecoveryin interfaceDataFactory- Throws:
StandardException- Standard Derby Error policy
-
dropContainer
public void dropContainer(RawTransaction t, ContainerKey ckey) throws StandardException
Drop a container.Synchronisation
This call will mark the container as dropped and then obtain an CX lock (table level exclusive lock) on the container. Once a container has been marked as dropped it cannot be retrieved by an openContainer() call unless explicitly with droppedOK.
Once the exclusive lock has been obtained the container is removed and all its pages deallocated. The container will be fully removed at the commit time of the transaction.
- Specified by:
dropContainerin interfaceDataFactory- Throws:
StandardException- Standard Derby error policy
-
checkpoint
public void checkpoint() throws StandardExceptionImplement checkpoint operation, write/sync all pages in cache.The derby write ahead log algorithm uses checkpoint of the data cache to determine points of the log no longer required by restart recovery.
This implementation uses the 2 cache interfaces to force all dirty pages to disk: WRITE DIRTY PAGES TO OS: In the first step all pages in the page cache are written, but not synced (pagecache.cleanAll). The cachemanager cleanAll() interface guarantees that every dirty page that exists when this call is first made will have it's clean() method called. The data cache (CachedPage.clean()), will call writePage but not sync the page. By using the java write then sync, the checkpoint is usually doing async I/O, allowing the OS to schedule multiple I/O's to the file as efficiently as it can. Note that it has been observed that checkpoints can flood the I/O system because these writes are not synced, see DERBY-799 - checkpoint should probably somehow restrict the rate it sends out those I/O's - it was observed a simple sleep every N writes fixed most of the problem. FORCE THOSE DIRTY WRITES TO DISK: To force the I/O's to disk, the system calls each open dirty file and uses the java interface to sync any outstanding dirty pages to disk (containerCache.cleanAll()). The open container cache does this work in RAFContainer.clean() by writing it's header out and syncing the file. (Note if any change is made to checkpoint to sync the writes vs. syncing the file, one probably still needs to write the container header out and sync it).
- Specified by:
checkpointin interfaceDataFactory- Throws:
StandardException- Standard exception policy.
-
idle
public void idle() throws StandardException- Specified by:
idlein interfaceDataFactory- Throws:
StandardException
-
setRawStoreFactory
public void setRawStoreFactory(RawStoreFactory rsf, boolean create, java.util.Properties startParams) throws StandardException
Description copied from interface:DataFactorymake data factory aware of which raw store factory it belongs to Also need to boot the LogFactory- Specified by:
setRawStoreFactoryin interfaceDataFactory- Throws:
StandardException- cannot boot the log factory
-
getIdentifier
public UUID getIdentifier()
Return my unique identifier- Specified by:
getIdentifierin interfaceDataFactory- See Also:
DataFactory.getIdentifier()
-
reclaimSpace
public int reclaimSpace(Serviceable work, ContextManager contextMgr) throws StandardException
Description copied from interface:DataFactoryReclaim space used by this factory. Called by post commit daemon.- Specified by:
reclaimSpacein interfaceDataFactory- Throws:
StandardException- Standard Derby exception policy
-
markCorrupt
public StandardException markCorrupt(StandardException originalError)
Really this is just a convience routine for callers that might not have access to a log factory.- Specified by:
markCorruptin interfaceCorruptable- Returns:
- Must always return its parameter.
-
getFileHandler
public FileResource getFileHandler()
Description copied from interface:DataFactoryGet an object to handle non-transactional files.- Specified by:
getFileHandlerin interfaceDataFactory
-
removeStubsOK
public void removeStubsOK()
Description copied from interface:DataFactoryTell the data factory it is OK to remove committed deleted containers when the data factory shuts down.- Specified by:
removeStubsOKin interfaceDataFactory
-
getIntParameter
public int getIntParameter(java.lang.String parameterName, java.util.Properties properties, int defaultValue, int minimumValue, int maximumValue)
-
getRootDirectory
public java.lang.String getRootDirectory()
Get the root directory of the data storage area. Is always guaranteed to be an absolute path.
-
getContainerPath
public StorageFile getContainerPath(ContainerKey containerId, boolean stub)
Return the path to a container file.Return the path to a container file that is relative to the root directory.
The format of the name of an existing container file is: segNNN/cXXX.dat The format of the name of a stub describing a dropped container file is: segNNN/dXXX.dat NNN = segment number, currently 0 is where normal db files are found. XXX = The hex representation of the container number The store will always create containers with this format name, but the store will also recognize the following two formats when attempting to open files - as some copy tools have uppercased our filesnames when moving across operating systems: The format of the name of an existing container file is: segNNN/CXXX.DAT The format of the name of a stub describing a dropped container file is: segNNN/DXXX.DAT
- Parameters:
containerId- The container being opened/createdstub- True if the file name for the stub is requested, otherwise the file name for the data file- Returns:
- The StorageFile representing path to container relative to root.
-
getAlternateContainerPath
public StorageFile getAlternateContainerPath(ContainerKey containerId, boolean stub)
Return an alternate path to container file relative to the root directory. The alternate path uses upper case 'C','D', and 'DAT' instead of lower case - there have been cases of people copying the database and somehow upper casing all the file names. The intended use is as a bug fix for track 3444.- Parameters:
containerId- The container being opened/createdstub- True if the file name for the stub is requested, otherwise the file name for the data file
-
stubFileToRemoveAfterCheckPoint
public void stubFileToRemoveAfterCheckPoint(StorageFile file, LogInstant logInstant, java.lang.Object identity)
keeps track of information about the stub files of the committed deleted containers. We use the info to delete them at checkpoints. In addition to the file info , we also keep track of the identity of the container; which helps to remove entry in the cache and the log instant when the stub was created, which helps us to figure out whether we require the stub file for the crash recovery. We maintain the information in a hashtable: key(LOG INSTANT) Values: File handle , and ContainerIdentity.
-
removeDroppedContainerFileStubs
public void removeDroppedContainerFileStubs(LogInstant redoLWM) throws StandardException
Delete the stub files that are not required for recovery. A stub file is not required to be around if the recovery is not going to see any log record that belongs to that container. Since the stub files are created as a post commit operation, they are not necessary during undo operation of the recovery. To remove a stub file we have to be sure that it was created before the redoLWM in the check point record. We can be sure that the stub is not required if the log instant when it was created is less than the redoLWM.- Specified by:
removeDroppedContainerFileStubsin interfaceDataFactory- Throws:
StandardException- Standard Derby error policy
-
databaseEncrypted
public final boolean databaseEncrypted()
Description copied from interface:DataFactoryReturns if data base is in encrypted mode.- Specified by:
databaseEncryptedin interfaceDataFactory- Returns:
- true if database encrypted false otherwise
-
setDatabaseEncrypted
public void setDatabaseEncrypted(boolean isEncrypted)
Sets whether the database is encrypted.- Specified by:
setDatabaseEncryptedin interfaceDataFactory- Parameters:
isEncrypted-trueif the database is encrypted,falseotherwise
-
encrypt
public int encrypt(byte[] cleartext, int offset, int length, byte[] ciphertext, int outputOffset, boolean newEngine) throws StandardExceptionDescription copied from interface:DataFactoryEncrypt cleartext into ciphertext.- Specified by:
encryptin interfaceDataFactory- Throws:
StandardException- Standard Derby Error Policy- See Also:
CipherProvider.encrypt(byte[], int, int, byte[], int)
-
decrypt
public int decrypt(byte[] ciphertext, int offset, int length, byte[] cleartext, int outputOffset) throws StandardExceptionDescription copied from interface:DataFactoryDecrypt cleartext from ciphertext.- Specified by:
decryptin interfaceDataFactory- Throws:
StandardException- Standard Derby Error Policy- See Also:
CipherProvider.decrypt(byte[], int, int, byte[], int)
-
decryptAllContainers
public void decryptAllContainers(RawTransaction t) throws StandardException
Decrypts all the containers in the data segment.- Specified by:
decryptAllContainersin interfaceDataFactory- Parameters:
t- the transaction that is decrypting the container- Throws:
StandardException- Standard Derby Error Policy
-
encryptAllContainers
public void encryptAllContainers(RawTransaction t) throws StandardException
Encrypt all the containers in the data segment.- Specified by:
encryptAllContainersin interfaceDataFactory- Parameters:
t- the transaction that is encrypting the containers.- Throws:
StandardException- Standard Derby Error Policy
-
removeOldVersionOfContainers
public void removeOldVersionOfContainers() throws StandardExceptionRemoves old versions of the containers after a cryptographic operation on the database.- Specified by:
removeOldVersionOfContainersin interfaceDataFactory- Throws:
StandardException
-
getEncryptionBlockSize
public int getEncryptionBlockSize()
Returns the encryption block size used by the algorithm at time of creation of an encrypted database- Specified by:
getEncryptionBlockSizein interfaceDataFactory
-
getVersionedName
public java.lang.String getVersionedName(java.lang.String name, long generationId)
-
getMaxContainerId
public long getMaxContainerId() throws StandardExceptionReturn an id which can be used to create a container.Return an id number with is greater than any existing container in the current database. Caller will use this to allocate future container numbers - most likely caching the value and then incrementing it as it is used.
- Specified by:
getMaxContainerIdin interfaceDataFactory- Returns:
- The an id which can be used to create a container.
- Throws:
StandardException- Standard exception policy.
-
postRecovery
public void postRecovery() throws StandardExceptionCalled after recovery is performed.- Specified by:
postRecoveryin interfaceDataFactory- Throws:
StandardException- Standard Derby Error Policy
-
setupCacheCleaner
public void setupCacheCleaner(DaemonService daemon)
Set up the cache cleaner for the container cache and the page cache.- Specified by:
setupCacheCleanerin interfaceDataFactory- Parameters:
daemon- daemon service to use for background cleaning
-
freezePersistentStore
public void freezePersistentStore() throws StandardExceptionDescription copied from interface:DataFactoryBackup restore - stop writing dirty pages or container to disk- Specified by:
freezePersistentStorein interfaceDataFactory- Throws:
StandardException- Standard Derby error policy
-
unfreezePersistentStore
public void unfreezePersistentStore()
Description copied from interface:DataFactoryBackup restore - start writing dirty pages or container to disk- Specified by:
unfreezePersistentStorein interfaceDataFactory
-
writeInProgress
public void writeInProgress() throws StandardExceptionDescription copied from interface:DataFactoryBackup restore - don't allow the persistent store to be frozen - or if it is already frozen, block. A write is about to commence.- Specified by:
writeInProgressin interfaceDataFactory- Throws:
StandardException- Standard Derby error policy
-
writeFinished
public void writeFinished()
Description copied from interface:DataFactoryBackup restore - write finished, if this is the last writer, allow the persistent store to proceed.- Specified by:
writeFinishedin interfaceDataFactory
-
backupDataFiles
public void backupDataFiles(Transaction rt, java.io.File backupDir) throws StandardException
Description copied from interface:DataFactoryBack up the data segment of the database.- Specified by:
backupDataFilesin interfaceDataFactory- Throws:
StandardException
-
isReadOnly
public boolean isReadOnly()
Is the store read-only.- Specified by:
isReadOnlyin interfaceDataFactory
-
luceneLoaded
public boolean luceneLoaded() throws StandardExceptionReturn true if the Lucene plugin is loaded- Throws:
StandardException
-
getStorageFactory
public StorageFactory getStorageFactory()
- Specified by:
getStorageFactoryin interfaceDataFactory- Returns:
- The StorageFactory used by this dataFactory
-
run
public final java.lang.Object run() throws java.io.IOException, StandardException- Specified by:
runin interfacejava.security.PrivilegedExceptionAction<java.lang.Object>- Throws:
java.io.IOExceptionStandardException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG