Class RawStore
- java.lang.Object
-
- org.apache.derby.impl.store.raw.RawStore
-
- All Implemented Interfaces:
java.security.PrivilegedExceptionAction<java.lang.Object>,ModuleControl,ModuleSupportable,Corruptable,RawStoreFactory
public final class RawStore extends java.lang.Object implements RawStoreFactory, ModuleControl, ModuleSupportable, java.security.PrivilegedExceptionAction<java.lang.Object>
A Raw store that implements the RawStoreFactory module by delegating all the work to the lower modules TransactionFactory, LogFactory and DataFactory.String TransactionFactoryId=Class is final as it has methods with privilege blocks and implements PrivilegedExceptionAction.
-
-
Field Summary
-
Fields inherited from interface org.apache.derby.iapi.store.raw.RawStoreFactory
CONTAINER_CACHE_SIZE_DEFAULT, CONTAINER_CACHE_SIZE_MAXIMUM, CONTAINER_CACHE_SIZE_MINIMUM, CONTAINER_CACHE_SIZE_PARAMETER, CONTAINER_INITIAL_PAGES, CRYPTO_OLD_EXTERNAL_KEY_VERIFY_FILE, DATA_ENCRYPT_ALGORITHM_VERSION, DB_ENCRYPTION_IN_CLEANUP, DB_ENCRYPTION_IN_PROGRESS, DB_ENCRYPTION_IN_UNDO, DB_ENCRYPTION_STATUS, DEFAULT_ENCRYPTION_BLOCKSIZE, DERBY_STORE_MAJOR_VERSION_10, DERBY_STORE_MINOR_VERSION_1, DERBY_STORE_MINOR_VERSION_10, DERBY_STORE_MINOR_VERSION_2, DERBY_STORE_MINOR_VERSION_3, DERBY_STORE_MINOR_VERSION_4, ENCRYPTED_KEY, ENCRYPTION_ALIGNMENT, ENCRYPTION_BLOCKSIZE, KEEP_TRANSACTION_LOG, LOG_ENCRYPT_ALGORITHM_VERSION, MAX_CONTAINER_INITIAL_PAGES, MINIMUM_RECORD_SIZE_DEFAULT, MINIMUM_RECORD_SIZE_MINIMUM, MINIMUM_RECORD_SIZE_PARAMETER, MODULE, OLD_ENCRYPTED_KEY, PAGE_CACHE_SIZE_DEFAULT, PAGE_CACHE_SIZE_MAXIMUM, PAGE_CACHE_SIZE_MINIMUM, PAGE_CACHE_SIZE_PARAMETER, PAGE_RESERVED_SPACE_PARAMETER, PAGE_RESERVED_ZERO_SPACE_STRING, PAGE_REUSABLE_RECORD_ID, PAGE_SIZE_DEFAULT, PAGE_SIZE_MINIMUM, PAGE_SIZE_STRING, PATCH_INITPAGE_RECOVER_ERROR, PRE_ALLOCATE_PAGE, STREAM_FILE_BUFFER_SIZE_DEFAULT, STREAM_FILE_BUFFER_SIZE_MAXIMUM, STREAM_FILE_BUFFER_SIZE_MINIMUM, STREAM_FILE_BUFFER_SIZE_PARAMETER
-
-
Constructor Summary
Constructors Constructor Description RawStore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidapplyBulkCryptoOperation(java.util.Properties properties, CipherFactory newCipherFactory)voidbackup(java.lang.String backupDir, boolean wait)Backup the database to a backup directory.voidbackup(Transaction t, java.io.File backupDir)voidbackupAndEnableLogArchiveMode(java.lang.String backupDir, boolean deleteOnlineArchivedLogFiles, boolean wait)Backup the database to a backup directory and enable the log archive mode that will keep the archived log files required for roll-forward from this version backup.voidboot(boolean create, java.util.Properties properties)Boot this module with the given properties.private static java.lang.ObjectbootServiceModule(boolean create, java.lang.Object serviceModule, java.lang.String factoryInterface, java.util.Properties properties)Privileged startup.booleancanSupport(java.util.Properties startParams)We use this RawStore for all databases.java.io.SerializablechangeBootPassword(java.util.Properties properties, java.io.Serializable changePassword)Change the boot password.voidcheckpoint()Checkpoint the database.booleancheckVersion(int requiredMajorVersion, int requiredMinorVersion, java.lang.String feature)Check to see if a database has been upgraded to the required level in order to use a store feature.private voidcrashOnDebugFlag(java.lang.String debugFlag, boolean reEncrypt)when the input debug flag is set, an expception is throw when run in the debug mode.private voidcreateBackupDirectory(java.io.File dir)Create a directory for backup.voidcreateDataWarningFile()Use the available storage factory handle to create a readme file in "seg0" directory warning users to not edit/delete any files in the directory to avoid database corruption.voidcreateFinished()private voidcryptoOperationAllowed(boolean reEncrypt, boolean decrypt)checks if the database is in the right state to (re)encrypt it.intdecrypt(byte[] ciphertext, int offset, int length, byte[] cleartext, int outputOffset)Decrypt cleartext from ciphertext.voiddisableLogArchiveMode(boolean deleteOnlineArchivedLogFiles)disables the log archival process, i.e No old log files will be kept around for a roll-forward recovery.intencrypt(byte[] cleartext, int offset, int length, byte[] ciphertext, int outputOffset, boolean newEngine)Encrypt cleartext into ciphertext.voidfailover(java.lang.String dbname)Start failover for this database.private static java.lang.ObjectfindServiceModule(java.lang.Object serviceModule, java.lang.String factoryInterface)Privileged startup.TransactionfindUserTransaction(ContextManager contextMgr, java.lang.String transName)Find a user transaction in the context manager, which must be the current context manager.voidfreeze()Freeze the database temporarily so a backup can be taken.voidfreezePersistentStore()Freeze persistent store.private static ContextgetContextOrNull(java.lang.String contextID)Privileged lookup of a Context.private static ContextServicegetContextService()Privileged lookup of the ContextService.DaemonServicegetDaemon()If this raw store has a daemon that services its need, return the daemon.java.lang.StringgetDataFactoryModule()intgetEncryptionBlockSize()Returns the encryption block size used by the algorithm at time of creation of an encrypted databaseprivate java.lang.StringgetFilePath(java.io.File file)private java.lang.StringgetFilePath(StorageFile file)LockFactorygetLockFactory()Get the LockFactory to use with this store.java.lang.StringgetLogFactoryModule()java.lang.StringgetMasterFactoryModule()longgetMaxContainerId()Return an id which can be used to create a container.private static ModuleFactorygetMonitor()Privileged Monitor lookup.voidgetRawStoreProperties(PersistentSet set)Get JBMS properties relevant to raw storeprivate static java.lang.StringgetServiceName(java.lang.Object serviceModule)Privileged service name lookup.java.lang.StringgetSlaveFactoryModule()java.lang.StringgetTransactionFactoryModule()TransactionInfo[]getTransactionInfo()TransactionFactorygetXactFactory()Get the Transaction Factory to use with this store.java.lang.ObjectgetXAResourceManager()voidhandleIncompleteDbCryptoOperation(java.util.Properties properties)Engine might have crashed during encryption of un-encrypted datbase or while re-encryptin an already encrypted database with a new key after all the containers or (re) encrypted.voididle()Idle the raw store as much as possible.booleanisReadOnly()Is the store read-only.private static booleanisSet(java.util.Properties p, java.lang.String attribute)Tells if the attribute/property has been specified.private static booleanisTrue(java.util.Properties p, java.lang.String attribute)Tells if the attribute/property has been set totrue.private voidlogHistory(java.io.OutputStreamWriter historyFile, java.lang.String msg)StandardExceptionmarkCorrupt(StandardException originalError)Mark the module as corrupt.ScanHandleopenFlushedScan(DatabaseInstant start, int groupsIWant)Get a flushed scan.protected booleanprivCopyDirectory(java.io.File from, StorageFile to)private booleanprivCopyDirectory(java.io.File from, StorageFile to, byte[] buffer, java.lang.String[] filter)protected booleanprivCopyDirectory(StorageFile from, java.io.File to)private booleanprivCopyDirectory(StorageFile from, java.io.File to, byte[] buffer, java.lang.String[] filter, boolean copySubdirs)private booleanprivCopyFile(java.io.File from, StorageFile to)private booleanprivCopyFile(StorageFile from, java.io.File to)private booleanprivCopyFile(StorageFile from, StorageFile to)private booleanprivDelete(java.io.File file)private booleanprivDelete(StorageFile file)private booleanprivExists(java.io.File file)private booleanprivExists(StorageFile file)private java.io.OutputStreamWriterprivFileWriter(StorageFile fileName, boolean append)private java.lang.StringprivGetCanonicalPath(java.io.File file)private java.lang.StringprivGetCanonicalPath(StorageFile file)private java.io.OutputStreamWriterprivGetOutputStreamWriter(StorageFile file)private booleanprivIsDirectory(java.io.File file)private java.lang.String[]privList(StorageFile file)private booleanprivMkdirs(java.io.File file)private booleanprivRemoveDirectory(java.io.File file)private booleanprivRenameTo(java.io.File file1, java.io.File file2)intrandom()Returns a secure random number for this raw store - if database is not encrypted, returns 0.private voidremoveCryptoProperties(java.util.Properties properties)Removes properties related to encrypted databases.private voidrestoreRemainingFromBackup(java.lang.String backupPath)java.lang.Objectrun()voidsetUndoInsertEventHandler(UndoHandler input_undo_handle)Register a handler class for insert undo events.private booleansetupEncryptionEngines(boolean create, java.util.Properties properties)Setup encryption engines according to the user properties and the current database state.TransactionstartGlobalTransaction(ContextManager contextMgr, int format_id, byte[] global_id, byte[] branch_id)Create a global user transaction, almost all work within the raw store is performed in the context of a transaction.TransactionstartInternalTransaction(ContextManager contextMgr)Create an internal transaction.TransactionstartNestedReadOnlyUserTransaction(Transaction parentTransaction, CompatibilitySpace compatibilitySpace, ContextManager contextMgr, java.lang.String transName)Create a nested user transaction, almost all work within the raw store is performed in the context of a transaction.TransactionstartNestedUpdateUserTransaction(Transaction parentTransaction, ContextManager contextMgr, java.lang.String transName, boolean flush_log_on_xact_end)Create a nested user transaction, almost all work within the raw store is performed in the context of a transaction.voidstartReplicationMaster(java.lang.String dbmaster, java.lang.String host, int port, java.lang.String replicationMode)Start the replication master role for this databaseprivate static java.lang.ObjectstartSystemModule(java.lang.String factoryInterface)Privileged startup.TransactionstartTransaction(ContextManager contextMgr, java.lang.String transName)Create a user transaction, almost all work within the raw store is performed in the context of a transaction.voidstop()Stop the module.voidstopReplicationMaster()Stop the replication master role for this database.voidunfreeze()Unfreeze the database after a backup has been taken.voidunfreezePersistentStore()Freeze persistent store.
-
-
-
Field Detail
-
BACKUP_HISTORY
private static final java.lang.String BACKUP_HISTORY
- See Also:
- Constant Field Values
-
xactFactory
protected TransactionFactory xactFactory
-
dataFactory
protected DataFactory dataFactory
-
logFactory
protected LogFactory logFactory
-
slaveFactory
private SlaveFactory slaveFactory
-
storageFactory
private StorageFactory storageFactory
-
random
private java.security.SecureRandom random
-
isEncryptedDatabase
private boolean isEncryptedDatabase
-
encryptionEngine
private CipherProvider encryptionEngine
-
decryptionEngine
private CipherProvider decryptionEngine
-
newEncryptionEngine
private CipherProvider newEncryptionEngine
-
newDecryptionEngine
private CipherProvider newDecryptionEngine
-
currentCipherFactory
private CipherFactory currentCipherFactory
-
newCipherFactory
private CipherFactory newCipherFactory
-
counter_encrypt
private int counter_encrypt
-
counter_decrypt
private int counter_decrypt
-
encryptionBlockSize
private int encryptionBlockSize
-
rawStoreDaemon
protected DaemonService rawStoreDaemon
-
actionCode
private int actionCode
-
FILE_WRITER_ACTION
private static final int FILE_WRITER_ACTION
- See Also:
- Constant Field Values
-
actionStorageFile
private StorageFile actionStorageFile
-
actionToStorageFile
private StorageFile actionToStorageFile
-
actionAppend
private boolean actionAppend
-
REGULAR_FILE_EXISTS_ACTION
private static final int REGULAR_FILE_EXISTS_ACTION
- See Also:
- Constant Field Values
-
actionRegularFile
private java.io.File actionRegularFile
-
STORAGE_FILE_EXISTS_ACTION
private static final int STORAGE_FILE_EXISTS_ACTION
- See Also:
- Constant Field Values
-
REGULAR_FILE_DELETE_ACTION
private static final int REGULAR_FILE_DELETE_ACTION
- See Also:
- Constant Field Values
-
REGULAR_FILE_MKDIRS_ACTION
private static final int REGULAR_FILE_MKDIRS_ACTION
- See Also:
- Constant Field Values
-
REGULAR_FILE_IS_DIRECTORY_ACTION
private static final int REGULAR_FILE_IS_DIRECTORY_ACTION
- See Also:
- Constant Field Values
-
REGULAR_FILE_REMOVE_DIRECTORY_ACTION
private static final int REGULAR_FILE_REMOVE_DIRECTORY_ACTION
- See Also:
- Constant Field Values
-
REGULAR_FILE_RENAME_TO_ACTION
private static final int REGULAR_FILE_RENAME_TO_ACTION
- See Also:
- Constant Field Values
-
actionRegularFile2
private java.io.File actionRegularFile2
-
COPY_STORAGE_DIRECTORY_TO_REGULAR_ACTION
private static final int COPY_STORAGE_DIRECTORY_TO_REGULAR_ACTION
- See Also:
- Constant Field Values
-
actionBuffer
private byte[] actionBuffer
-
actionFilter
private java.lang.String[] actionFilter
-
actionCopySubDirs
private boolean actionCopySubDirs
-
COPY_REGULAR_DIRECTORY_TO_STORAGE_ACTION
private static final int COPY_REGULAR_DIRECTORY_TO_STORAGE_ACTION
- See Also:
- Constant Field Values
-
COPY_REGULAR_FILE_TO_STORAGE_ACTION
private static final int COPY_REGULAR_FILE_TO_STORAGE_ACTION
- See Also:
- Constant Field Values
-
REGULAR_FILE_LIST_DIRECTORY_ACTION
private static final int REGULAR_FILE_LIST_DIRECTORY_ACTION
- See Also:
- Constant Field Values
-
STORAGE_FILE_LIST_DIRECTORY_ACTION
private static final int STORAGE_FILE_LIST_DIRECTORY_ACTION
- See Also:
- Constant Field Values
-
COPY_STORAGE_FILE_TO_REGULAR_ACTION
private static final int COPY_STORAGE_FILE_TO_REGULAR_ACTION
- See Also:
- Constant Field Values
-
REGULAR_FILE_GET_CANONICALPATH_ACTION
private static final int REGULAR_FILE_GET_CANONICALPATH_ACTION
- See Also:
- Constant Field Values
-
STORAGE_FILE_GET_CANONICALPATH_ACTION
private static final int STORAGE_FILE_GET_CANONICALPATH_ACTION
- See Also:
- Constant Field Values
-
COPY_STORAGE_FILE_TO_STORAGE_ACTION
private static final int COPY_STORAGE_FILE_TO_STORAGE_ACTION
- See Also:
- Constant Field Values
-
STORAGE_FILE_DELETE_ACTION
private static final int STORAGE_FILE_DELETE_ACTION
- See Also:
- Constant Field Values
-
README_FILE_OUTPUTSTREAM_WRITER_ACTION
private static final int README_FILE_OUTPUTSTREAM_WRITER_ACTION
- See Also:
- Constant Field Values
-
TEST_REENCRYPT_CRASH_BEFORE_COMMT
public static final java.lang.String TEST_REENCRYPT_CRASH_BEFORE_COMMT
(re) encryption testing debug flags that are used to simulate error/crash conditions for testing purposes. When any one of the following flags are set to true in the debug mode, re-encryption will fail at that point.
-
TEST_REENCRYPT_CRASH_AFTER_COMMT
public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_COMMT
-
TEST_REENCRYPT_CRASH_AFTER_SWITCH_TO_NEWKEY
public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_SWITCH_TO_NEWKEY
-
TEST_REENCRYPT_CRASH_AFTER_CHECKPOINT
public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_CHECKPOINT
-
TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_LOGFILE_DELETE
public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_LOGFILE_DELETE
-
TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_REVERTING_KEY
public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_REVERTING_KEY
-
TEST_REENCRYPT_CRASH_BEFORE_RECOVERY_FINAL_CLEANUP
public static final java.lang.String TEST_REENCRYPT_CRASH_BEFORE_RECOVERY_FINAL_CLEANUP
-
-
Method Detail
-
canSupport
public boolean canSupport(java.util.Properties startParams)
We use this RawStore for all databases.- Specified by:
canSupportin interfaceModuleSupportable- Returns:
- true if this instance can be used, false otherwise.
-
boot
public void boot(boolean create, java.util.Properties properties) 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- See Also:
Monitor,ModuleFactory
-
isReadOnly
public boolean isReadOnly()
Is the store read-only.- Specified by:
isReadOnlyin interfaceRawStoreFactory- See Also:
RawStoreFactory.isReadOnly()
-
getLockFactory
public LockFactory getLockFactory()
Description copied from interface:RawStoreFactoryGet the LockFactory to use with this store.- Specified by:
getLockFactoryin interfaceRawStoreFactory
-
getXactFactory
public TransactionFactory getXactFactory()
Get the Transaction Factory to use with this store.- Specified by:
getXactFactoryin interfaceRawStoreFactory
-
setUndoInsertEventHandler
public void setUndoInsertEventHandler(UndoHandler input_undo_handle) throws StandardException
Register a handler class for insert undo events.Register a class to be called when an undo of an insert is executed. When an undo of an event is executed by the raw store UndoHandler.insertUndoNotify() will be called, allowing upper level callers to execute code as necessary. The initial need is for the access layer to be able to queue post commit reclaim space in the case of inserts which are aborted (including the normal case of inserts failed for duplicate key violations) (see DERBY-4057)
- Specified by:
setUndoInsertEventHandlerin interfaceRawStoreFactory- Parameters:
input_undo_handle- Class to use to notify callers of an undo of an insert.- Throws:
StandardException- Standard exception policy.
-
getXAResourceManager
public java.lang.Object getXAResourceManager() throws StandardException- Specified by:
getXAResourceManagerin interfaceRawStoreFactory- Throws:
StandardException
-
startGlobalTransaction
public Transaction startGlobalTransaction(ContextManager contextMgr, int format_id, byte[] global_id, byte[] branch_id) throws StandardException
Description copied from interface:RawStoreFactoryCreate a global user transaction, almost all work within the raw store is performed in the context of a transaction.The (format_id, global_id, branch_id) triplet is meant to come exactly from a javax.transaction.xa.Xid. We don't use Xid so that the system can be delivered on a non-1.2 vm system and not require the javax classes in the path.
Starting a transaction always performs the following steps.
- Create an raw store transaction context
- Create a new idle transaction and then link it to the context.
Only one user transaction can be active in a context at any one time.
After a commit the transaction may be re-used.
Raw Store Transaction Context Behaviour
The cleanupOnError() method of this context behaves as follows:- If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then no action is taken.
- If error is an instance of StandardException that has a severity equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, and the transaction returned to the idle state.
- If error is an instance of StandardException that has a severity greater than ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
- If error is not an instance of StandardException then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
- Specified by:
startGlobalTransactionin interfaceRawStoreFactory- Parameters:
contextMgr- is the context manager to use. An exception will be thrown if context is not the current context.format_id- the format id part of the Xid - ie. Xid.getFormatId().global_id- the global transaction identifier part of XID - ie. Xid.getGlobalTransactionId().branch_id- The branch qualifier of the Xid - ie. Xid.getBranchQaulifier()- Throws:
StandardException- Standard Derby error policy- See Also:
Transaction,Context,StandardException
-
startTransaction
public Transaction startTransaction(ContextManager contextMgr, java.lang.String transName) throws StandardException
Description copied from interface:RawStoreFactoryCreate a user transaction, almost all work within the raw store is performed in the context of a transaction.Starting a transaction always performs the following steps.
- Create an raw store transaction context
- Create a new idle transaction and then link it to the context.
Only one user transaction and one nested user transaction can be active
in a context at any one time.
After a commit the transaction may be re-used.
Raw Store Transaction Context Behaviour
The cleanupOnError() method of this context behaves as follows:- If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then no action is taken.
- If error is an instance of StandardException that has a severity equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, and the transaction returned to the idle state.
- If error is an instance of StandardException that has a severity greater than ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
- If error is not an instance of StandardException then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
- Specified by:
startTransactionin interfaceRawStoreFactory- Parameters:
contextMgr- is the context manager to use. An exception will be thrown if context is not the current context.transName- is the name of the transaction. Thsi name will be displayed by the transactiontable VTI.- Throws:
StandardException- Standard Derby error policy- See Also:
Transaction,Context,StandardException
-
startNestedReadOnlyUserTransaction
public Transaction startNestedReadOnlyUserTransaction(Transaction parentTransaction, CompatibilitySpace compatibilitySpace, ContextManager contextMgr, java.lang.String transName) throws StandardException
Description copied from interface:RawStoreFactoryCreate a nested user transaction, almost all work within the raw store is performed in the context of a transaction.A nested user transaction is exactly the same as a user transaction, except that one can specify a compatibility space to associate with the transaction. Starting a transaction always performs the following steps.
- Create an raw store transaction context
- Create a new idle transaction and then link it to the context.
Only one user transaction and one nested user transaction can be active
in a context at any one time.
After a commit the transaction may be re-used.
Raw Store Transaction Context Behaviour
The cleanupOnError() method of this context behaves as follows:- If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then no action is taken.
- If error is an instance of StandardException that has a severity equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, and the transaction returned to the idle state. If a user transaction exists on the context stack then that transaction is aborted also.
- If error is an instance of StandardException that has a severity greater than ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
- If error is not an instance of StandardException then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
- Specified by:
startNestedReadOnlyUserTransactionin interfaceRawStoreFactory- Parameters:
parentTransaction- parent transactioncompatibilitySpace- compatibility space to use for locks.contextMgr- is the context manager to use. An exception will be thrown if context is not the current context.transName- is the name of the transaction. This name will be displayed by the transactiontable VTI.- Throws:
StandardException- Standard Derby error policy- See Also:
Transaction,Context,StandardException
-
startNestedUpdateUserTransaction
public Transaction startNestedUpdateUserTransaction(Transaction parentTransaction, ContextManager contextMgr, java.lang.String transName, boolean flush_log_on_xact_end) throws StandardException
Description copied from interface:RawStoreFactoryCreate a nested user transaction, almost all work within the raw store is performed in the context of a transaction.A nested user transaction is exactly the same as a user transaction, except that one can specify a compatibility space to associate with the transaction. Starting a transaction always performs the following steps.
- Create an raw store transaction context
- Create a new idle transaction and then link it to the context.
Only one user transaction and one nested user transaction can be active
in a context at any one time.
After a commit the transaction may be re-used.
Raw Store Transaction Context Behaviour
The cleanupOnError() method of this context behaves as follows:- If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then no action is taken.
- If error is an instance of StandardException that has a severity equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, and the transaction returned to the idle state. If a user transaction exists on the context stack then that transaction is aborted also.
- If error is an instance of StandardException that has a severity greater than ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
- If error is not an instance of StandardException then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
- Specified by:
startNestedUpdateUserTransactionin interfaceRawStoreFactory- Parameters:
parentTransaction- parent transactioncontextMgr- is the context manager to use. An exception will be thrown if context is not the current context.transName- is the name of the transaction. This name will be displayed by the transactiontable VTI.flush_log_on_xact_end- By default should the transaction commit and abort be synced to the log. Normal usage should pick true, unless there is specific performance need and usage works correctly if a commit can be lost on system crash.- Throws:
StandardException- Standard Derby error policy- See Also:
Transaction,Context,StandardException
-
findUserTransaction
public Transaction findUserTransaction(ContextManager contextMgr, java.lang.String transName) throws StandardException
Description copied from interface:RawStoreFactoryFind a user transaction in the context manager, which must be the current context manager. If a user transaction does not already exist, then create one @see #startTransaction- Specified by:
findUserTransactionin interfaceRawStoreFactory- Parameters:
contextMgr- the context manager to use. An exception will be thrown if context is not the current context.transName- If a new transaction is started, it will be given this name. The name is displayed in the transactiontable VTI.- Throws:
StandardException- Standard Derby error policy- See Also:
RawStoreFactory.startTransaction(org.apache.derby.iapi.services.context.ContextManager, java.lang.String)
-
startInternalTransaction
public Transaction startInternalTransaction(ContextManager contextMgr) throws StandardException
Description copied from interface:RawStoreFactoryCreate an internal transaction.Starting an internal transaction always performs the following steps.
- Create an raw store internal transaction context
- Create a new idle internal transaction and then link it to the
context.
AN internal transaction is identical to a user transaction with the exception that
- Logical operations are not supported
- Savepoints are not supported
- Containers are not closed when commit() is called.
- Pages are not unlatched (since containers are not closed) when commit() is called.
- During recovery time internal transactions are rolled back before user transactions.
Raw Store Internal Transaction Context Behaviour
The cleanupOnError() method of this context behaves as follows:- If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then the internal transaction is aborted, the internal transaction is closed, the context is popped off the stack, and an exception of severity Transaction exception is re-thrown.
- If error is an instance of StandardException that has a severity greater than or equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's internal transaction is aborted, the internal transaction is closed and the context is popped off the stack.
- If error is not an instance of StandardException then the context's internal transaction is aborted, the internal transaction is closed and the context is popped off the stack.
- Specified by:
startInternalTransactionin interfaceRawStoreFactory- Throws:
StandardException- Standard Derby error policy- See Also:
Transaction,Context,StandardException
-
checkpoint
public void checkpoint() throws StandardExceptionDescription copied from interface:RawStoreFactoryCheckpoint the database. The raw store will wait for any current checkpoints to complete. It will start a new checkpoint and not return until that checkpoint completes.- Specified by:
checkpointin interfaceRawStoreFactory- Throws:
StandardException- Standard Derby error policy
-
startReplicationMaster
public void startReplicationMaster(java.lang.String dbmaster, java.lang.String host, int port, java.lang.String replicationMode) throws StandardExceptionStart the replication master role for this database- Specified by:
startReplicationMasterin interfaceRawStoreFactory- Parameters:
dbmaster- The master database that is being replicated.host- The hostname for the slaveport- The port the slave is listening onreplicationMode- The type of replication contract. Currently only asynchronous replication is supported, but 1-safe/2-safe/very-safe modes may be added later.- Throws:
StandardException- 1) If replication is started on a read-only database 2) If replication is started when unlogged operations are running 3) If an error occurs while trying to boot the master.
-
stopReplicationMaster
public void stopReplicationMaster() throws StandardExceptionStop the replication master role for this database.- Specified by:
stopReplicationMasterin interfaceRawStoreFactory- Throws:
StandardException- Standard Derby exception policy, thrown on error.
-
failover
public void failover(java.lang.String dbname) throws StandardExceptionDescription copied from interface:RawStoreFactoryStart failover for this database.- Specified by:
failoverin interfaceRawStoreFactory- Parameters:
dbname- the replication database that is being failed over.- Throws:
StandardException- Standard Derby exception policy, 1) If the failover succeeds, an exception is thrown to indicate that the master database was shutdown after a successful failover 2) If a failure occurs during network communication with slave.
-
freeze
public void freeze() throws StandardExceptionDescription copied from interface:RawStoreFactoryFreeze the database temporarily so a backup can be taken.Please see Derby on line documentation on backup and restore.
- Specified by:
freezein interfaceRawStoreFactory- Throws:
StandardException- Thrown on error
-
unfreeze
public void unfreeze() throws StandardExceptionDescription copied from interface:RawStoreFactoryUnfreeze the database after a backup has been taken.Please see Derby on line documentation on backup and restore.
- Specified by:
unfreezein interfaceRawStoreFactory- Throws:
StandardException- Thrown on error
-
backup
public void backup(java.lang.String backupDir, boolean wait) throws StandardExceptionBackup the database to a backup directory.- Specified by:
backupin interfaceRawStoreFactory- Parameters:
backupDir- the name of the directory where the backup should be stored. This directory will be created if it does not exist.wait- if true, waits for all the backup blocking operations in progress to finish.- Throws:
StandardException- thrown on error
-
backup
public void backup(Transaction t, java.io.File backupDir) throws StandardException
- Throws:
StandardException
-
createBackupDirectory
private void createBackupDirectory(java.io.File dir) throws StandardExceptionCreate a directory for backup.- Parameters:
dir- the directory to create- Throws:
StandardException- if the directory could not be created
-
backupAndEnableLogArchiveMode
public void backupAndEnableLogArchiveMode(java.lang.String backupDir, boolean deleteOnlineArchivedLogFiles, boolean wait) throws StandardExceptionBackup the database to a backup directory and enable the log archive mode that will keep the archived log files required for roll-forward from this version backup.- Specified by:
backupAndEnableLogArchiveModein interfaceRawStoreFactory- Parameters:
backupDir- the name of the directory where the backup should be stored. This directory will be created if it does not exist.deleteOnlineArchivedLogFiles- If true deletes online archived log files that exist before this backup, delete will occur only after the backup is complete.wait- if true, waits for all the backup blocking operations in progress to finish.- Throws:
StandardException- thrown on error.
-
disableLogArchiveMode
public void disableLogArchiveMode(boolean deleteOnlineArchivedLogFiles) throws StandardExceptionDescription copied from interface:RawStoreFactorydisables the log archival process, i.e No old log files will be kept around for a roll-forward recovery.- Specified by:
disableLogArchiveModein interfaceRawStoreFactory- Parameters:
deleteOnlineArchivedLogFiles- If true deletes all online archived log files that exist before this call immediately; Only restore that can be performed after disabling log archive mode is version recovery.- Throws:
StandardException- Thrown on error
-
restoreRemainingFromBackup
private void restoreRemainingFromBackup(java.lang.String backupPath) throws StandardException- Throws:
StandardException
-
idle
public void idle() throws StandardExceptionDescription copied from interface:RawStoreFactoryIdle the raw store as much as possible.- Specified by:
idlein interfaceRawStoreFactory- Throws:
StandardException- Standard Derby error policy
-
getTransactionInfo
public TransactionInfo[] getTransactionInfo()
- Specified by:
getTransactionInfoin interfaceRawStoreFactory- See Also:
AccessFactory.getTransactionInfo()
-
openFlushedScan
public ScanHandle openFlushedScan(DatabaseInstant start, int groupsIWant) throws StandardException
Description copied from interface:RawStoreFactoryGet a flushed scan.- Specified by:
openFlushedScanin interfaceRawStoreFactory- Parameters:
start- The instant for the beginning of the scan.groupsIWant- log record groups the caller wants to scan.- Throws:
StandardException- StandardDerby error policy
-
getDaemon
public DaemonService getDaemon()
Description copied from interface:RawStoreFactoryIf this raw store has a daemon that services its need, return the daemon. If not, return null- Specified by:
getDaemonin interfaceRawStoreFactory
-
createFinished
public void createFinished() throws StandardException- Specified by:
createFinishedin interfaceRawStoreFactory- Throws:
StandardException
-
getRawStoreProperties
public void getRawStoreProperties(PersistentSet set) throws StandardException
Get JBMS properties relevant to raw store- Specified by:
getRawStorePropertiesin interfaceRawStoreFactory- Throws:
StandardException- Standard Derby Error Policy
-
freezePersistentStore
public void freezePersistentStore() throws StandardExceptionFreeze persistent store. Reads can still happen, only cannot write.- Specified by:
freezePersistentStorein interfaceRawStoreFactory- Throws:
StandardException- Standard Derby Error Policy
-
unfreezePersistentStore
public void unfreezePersistentStore() throws StandardExceptionFreeze persistent store. Reads can still happen, only cannot write.- Specified by:
unfreezePersistentStorein interfaceRawStoreFactory- Throws:
StandardException- Standard Derby Error Policy
-
setupEncryptionEngines
private boolean setupEncryptionEngines(boolean create, java.util.Properties properties) throws StandardExceptionSetup encryption engines according to the user properties and the current database state.- Parameters:
create- whether a new database is being created, or if this is an existing databaseproperties- database properties, including connection attributes- Returns:
trueif the existing data in the database should be transformed by applying a cryptographic operation.- Throws:
StandardException- if the properties are conflicting, if the requested configuration is denied, or if something else goes wrong
-
encrypt
public int encrypt(byte[] cleartext, int offset, int length, byte[] ciphertext, int outputOffset, boolean newEngine) throws StandardExceptionEncrypt cleartext into ciphertext.- Specified by:
encryptin interfaceRawStoreFactory- 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 StandardExceptionDecrypt cleartext from ciphertext.- Specified by:
decryptin interfaceRawStoreFactory- Throws:
StandardException- Standard Derby Error Policy- See Also:
CipherProvider.decrypt(byte[], int, int, byte[], int)
-
getEncryptionBlockSize
public int getEncryptionBlockSize()
Returns the encryption block size used by the algorithm at time of creation of an encrypted database- Specified by:
getEncryptionBlockSizein interfaceRawStoreFactory
-
random
public int random()
Description copied from interface:RawStoreFactoryReturns a secure random number for this raw store - if database is not encrypted, returns 0.- Specified by:
randomin interfaceRawStoreFactory
-
changeBootPassword
public java.io.Serializable changeBootPassword(java.util.Properties properties, java.io.Serializable changePassword) throws StandardExceptionDescription copied from interface:RawStoreFactoryChange the boot password. Return the encrypted form of the secret key. The new value must be a String of the form: oldBootPassword, newBootPassword- Specified by:
changeBootPasswordin interfaceRawStoreFactory- Throws:
StandardException- Standard Derby Error Policy
-
crashOnDebugFlag
private void crashOnDebugFlag(java.lang.String debugFlag, boolean reEncrypt) throws StandardExceptionwhen the input debug flag is set, an expception is throw when run in the debug mode.- Throws:
StandardException
-
applyBulkCryptoOperation
private void applyBulkCryptoOperation(java.util.Properties properties, CipherFactory newCipherFactory) throws StandardException- Throws:
StandardException
-
handleIncompleteDbCryptoOperation
public void handleIncompleteDbCryptoOperation(java.util.Properties properties) throws StandardExceptionEngine might have crashed during encryption of un-encrypted datbase or while re-encryptin an already encrypted database with a new key after all the containers or (re) encrypted. If crash has occured before all containers are encrypted, recovery wil un-do re-encryption using the transaction log, nothing to be done here. If crash has occured after database encryption status flag (RawStoreFactory.DB_ENCRYPTION_STATUS) is set, this method will do any cleanup necessary for the recovery to correctly perform the rollback if required.- Parameters:
properties- properties related to this database.- Throws:
StandardException- Standard Derby Error Policy
-
cryptoOperationAllowed
private void cryptoOperationAllowed(boolean reEncrypt, boolean decrypt) throws StandardExceptionchecks if the database is in the right state to (re)encrypt it.- Parameters:
reEncrypt-trueif the database is getting encrypted with a new password/keydecrypt-trueif the database is getting decrypted- Throws:
StandardException- if there is global transaction in the prepared state or if the database is not at the required version or above, this feature is not supported or if the log is archived for the database.
-
markCorrupt
public StandardException markCorrupt(StandardException originalError)
Description copied from interface:CorruptableMark the module as corrupt. It is safe to call this multiple times.- Specified by:
markCorruptin interfaceCorruptable- Returns:
- Must always return its parameter.
-
getTransactionFactoryModule
public java.lang.String getTransactionFactoryModule()
- Specified by:
getTransactionFactoryModulein interfaceRawStoreFactory
-
getSlaveFactoryModule
public java.lang.String getSlaveFactoryModule()
-
getMasterFactoryModule
public java.lang.String getMasterFactoryModule()
-
getDataFactoryModule
public java.lang.String getDataFactoryModule()
- Specified by:
getDataFactoryModulein interfaceRawStoreFactory
-
getLogFactoryModule
public java.lang.String getLogFactoryModule()
- Specified by:
getLogFactoryModulein interfaceRawStoreFactory
-
logHistory
private void logHistory(java.io.OutputStreamWriter historyFile, java.lang.String msg) throws java.io.IOException- Throws:
java.io.IOException
-
getFilePath
private java.lang.String getFilePath(StorageFile file)
-
getFilePath
private java.lang.String getFilePath(java.io.File file)
-
privCopyDirectory
protected boolean privCopyDirectory(StorageFile from, java.io.File to) throws StandardException
- Throws:
StandardException
-
privCopyDirectory
protected boolean privCopyDirectory(java.io.File from, StorageFile to)
-
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 interfaceRawStoreFactory- Returns:
- The an id which can be used to create a container.
- Throws:
StandardException- Standard exception policy.
-
checkVersion
public boolean checkVersion(int requiredMajorVersion, int requiredMinorVersion, java.lang.String feature) throws StandardExceptionCheck to see if a database has been upgraded to the required level in order to use a store feature.- Specified by:
checkVersionin interfaceRawStoreFactory- Parameters:
requiredMajorVersion- required database Engine major versionrequiredMinorVersion- required database Engine minor versionfeature- Non-null to throw an exception, null to return the state of the version match.- Returns:
trueif the database has been upgraded to the required level,falseotherwise.- Throws:
StandardException- if the database is not at the require version whenfeaturefeature is notnull.
-
removeCryptoProperties
private void removeCryptoProperties(java.util.Properties properties)
Removes properties related to encrypted databases.- Parameters:
properties- property set to remove from
-
privFileWriter
private java.io.OutputStreamWriter privFileWriter(StorageFile fileName, boolean append) throws java.io.IOException
- Throws:
java.io.IOException
-
privExists
private boolean privExists(java.io.File file)
-
privExists
private boolean privExists(StorageFile file)
-
privGetOutputStreamWriter
private java.io.OutputStreamWriter privGetOutputStreamWriter(StorageFile file) throws java.io.IOException
- Throws:
java.io.IOException
-
privDelete
private boolean privDelete(java.io.File file)
-
privDelete
private boolean privDelete(StorageFile file)
-
privMkdirs
private boolean privMkdirs(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
privIsDirectory
private boolean privIsDirectory(java.io.File file)
-
privRemoveDirectory
private boolean privRemoveDirectory(java.io.File file)
-
privRenameTo
private boolean privRenameTo(java.io.File file1, java.io.File file2)
-
privCopyDirectory
private boolean privCopyDirectory(StorageFile from, java.io.File to, byte[] buffer, java.lang.String[] filter, boolean copySubdirs) throws StandardException
- Throws:
StandardException
-
privCopyDirectory
private boolean privCopyDirectory(java.io.File from, StorageFile to, byte[] buffer, java.lang.String[] filter)
-
privCopyFile
private boolean privCopyFile(java.io.File from, StorageFile to)
-
privCopyFile
private boolean privCopyFile(StorageFile from, java.io.File to) throws StandardException
- Throws:
StandardException
-
privCopyFile
private boolean privCopyFile(StorageFile from, StorageFile to)
-
privList
private java.lang.String[] privList(StorageFile file)
-
privGetCanonicalPath
private java.lang.String privGetCanonicalPath(StorageFile file)
-
privGetCanonicalPath
private java.lang.String privGetCanonicalPath(java.io.File file)
-
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
-
isSet
private static boolean isSet(java.util.Properties p, java.lang.String attribute)Tells if the attribute/property has been specified.
-
isTrue
private static boolean isTrue(java.util.Properties p, java.lang.String attribute)Tells if the attribute/property has been set totrue.
-
createDataWarningFile
public void createDataWarningFile() throws StandardExceptionDescription copied from interface:RawStoreFactoryUse the available storage factory handle to create a readme file in "seg0" directory warning users to not edit/delete any files in the directory to avoid database corruption.- Specified by:
createDataWarningFilein interfaceRawStoreFactory- Throws:
StandardException- See Also:
RawStoreFactory.createDataWarningFile()
-
getContextService
private static ContextService getContextService()
Privileged lookup of the ContextService. Private so that user code can't call this entry point.
-
getContextOrNull
private static Context getContextOrNull(java.lang.String contextID)
Privileged lookup of a Context. Must be private so that user code can't call this entry point.
-
getMonitor
private static ModuleFactory getMonitor()
Privileged Monitor lookup. Must be private so that user code can't call this entry point.
-
getServiceName
private static java.lang.String getServiceName(java.lang.Object serviceModule)
Privileged service name lookup. Must be private so that user code can't call this entry point.
-
startSystemModule
private static java.lang.Object startSystemModule(java.lang.String factoryInterface) throws StandardExceptionPrivileged startup. Must be private so that user code can't call this entry point.- Throws:
StandardException
-
bootServiceModule
private static java.lang.Object bootServiceModule(boolean create, java.lang.Object serviceModule, java.lang.String factoryInterface, java.util.Properties properties) throws StandardExceptionPrivileged startup. Must be private so that user code can't call this entry point.- Throws:
StandardException
-
findServiceModule
private static java.lang.Object findServiceModule(java.lang.Object serviceModule, java.lang.String factoryInterface) throws StandardExceptionPrivileged startup. Must be private so that user code can't call this entry point.- Throws:
StandardException
-
-