Class RemoveFileOperation
- All Implemented Interfaces:
Externalizable
,Serializable
,Formatable
,TypedFormat
,Loggable
,Undoable
- See Also:
-
Field Summary
FieldsFields inherited from interface org.apache.derby.iapi.store.raw.Loggable
ABORT, BI_LOG, CHECKSUM, COMMIT, COMPENSATION, FILE_RESOURCE, FIRST, LAST, PREPARE, RAWSTORE, XA_NEEDLOCK
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
doMe
(Transaction xact, LogInstant instant, LimitObjectInput in) Apply the change indicated by this operation and optional data.generateUndo
(Transaction xact, LimitObjectInput in) Generate a loggable which will undo this change, using the optional input if necessary.the default for prepared log is always null for all the operations that don't have optionalData.int
Return my format identifier.int
group()
A space operation is a RAWSTORE log recordboolean
needsRedo
(Transaction xact) Determine if the operation should be reapplied in recovery redo.void
void
releaseResource
(Transaction tran) Release any resource that was acquired for doMe for rollback or recovery redo.void
-
Field Details
-
name
-
generationId
private long generationId -
removeAtOnce
private boolean removeAtOnce -
fileToGo
-
-
Constructor Details
-
RemoveFileOperation
public RemoveFileOperation() -
RemoveFileOperation
RemoveFileOperation(String name, long generationId, boolean removeAtOnce)
-
-
Method Details
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
getTypeFormatId
public int getTypeFormatId()Return my format identifier.- Specified by:
getTypeFormatId
in interfaceTypedFormat
- Returns:
- The identifier. (A UUID stuffed in an array of 16 bytes).
-
getPreparedLog
the default for prepared log is always null for all the operations that don't have optionalData. If an operation has optional data, the operation need to prepare the optional data for this method. Space Operation has no optional data to write out- Specified by:
getPreparedLog
in interfaceLoggable
-
releaseResource
Description copied from interface:Loggable
Release any resource that was acquired for doMe for rollback or recovery redo. This resource is acquired in either generateUndo (if this is a compensation operation during run time rollback or recovery rollback) or in needsRedo (if this is during recovery redo). The run time transaction context should have all the resource already acquird for run time roll forward, so there is no need to releaseResource during run time roll forward. This method must be safe to be called multiple times.- Specified by:
releaseResource
in interfaceLoggable
-
group
public int group()A space operation is a RAWSTORE log record -
doMe
public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in) throws StandardException Description copied from interface:Loggable
Apply the change indicated by this operation and optional data. If this method fail, the system will be shut down because the log record has already been written to disk. Moreover, the log record will be replayed during recovery and this doMe method will be called on the same page again, so if it fails again, recovery will fail and the database cannot be started. So it is very important to make sure that every resource you need, such as disk space, has been acquired before the logAndDo method is called!
This method cannot acquire any resource (like latching of a page) since it is called underneath the logging system, ie., the log record has already been written to the log stream.The available() method of in indicates how much data can be read, i.e. how much was originally written.
- Specified by:
doMe
in interfaceLoggable
- Parameters:
xact
- the Transactioninstant
- the log instant of this operationin
- optional data- Throws:
StandardException
- Standard Derby policy.
-
needsRedo
Description copied from interface:Loggable
Determine if the operation should be reapplied in recovery redo. If redo is needed, acquire any resource that is necessary for the loggable's doMe method. These need to be released in the releaseResource method.The sequence of events in recovery redo of a Loggable operation is:
- Get the loggable operation. If loggable.needsRedo is false, then no need to redo this operation.
- If loggable.needsRedo is true, all the resources necessary for applying the doMe is acquired in needsRedo.
- If the loggable is actually a compensation operation, then the logging system will find the undoable operation that needs to be undone, call compensation.setUndoOp with the undoable operation.
- The recovery system then calls loggable.doMe, which re-applies the loggable operation, or re-applies the compensation operation
- The recovery system then calls loggable.releaseResource.
- Specified by:
needsRedo
in interfaceLoggable
- Parameters:
xact
- The transaction trying to redo this operation- Returns:
- true if operation needs redoing, false if not.
- Throws:
StandardException
- Standard Derby error policy- See Also:
-
generateUndo
public Compensation generateUndo(Transaction xact, LimitObjectInput in) throws StandardException, IOException Description copied from interface:Undoable
Generate a loggable which will undo this change, using the optional input if necessary.NOTE
Any logical undo logic must be hidden behind generateUndo. During recovery redo, it should not depend on any logical undo logic.There are 3 ways to implement a redo-only log record:
- Make the log record a Loggable instead of an Undoable, this is the cleanest method.
- If you want to extend a log operation class that is an Undoable, you can then either have generateUndo return null - this is preferred - (the log operation's undoMe should never be called, so you can put a null body there if the super class you are extending does not implement a undoMe).
- Or, have undoMe do nothing - this is least preferred.
Any resource (e.g., latched page) that is needed for the undoable.undoMe() must be acquired in undoable.generateUndo(). Moreover, that resource must be identified in the compensation operation, and reacquired in the compensation.needsRedo() method during recovery redo.
If you do write your own generateUndo or needsRedo, any resource you latch or acquire, you must release them in Compensation.doMe() or in Compensation.releaseResource().To write a generateUndo operation, find the object that needs to be rolled back. Assuming that it is a page, latch it, put together a Compensation operation with the undoOp set to this operation, and save the page number in the compensation operation, then return the Compensation operation to the logging system.
The sequence of events in a rollback of a undoable operation is
- The logging system calls undoable.generateUndo. If this returns null, then there is nothing to undo.
- If generateUndo returns a Compensation operation, then the logging system will log the Compensation log record and call Compenstation.doMe(). (Hopefully, this just calls the undoable's undoMe)
- After the Compensation operation has been applied, the logging system will call compensation.releaseResource(). If you do overwrite a super class's releaseResource(), it would be prudent to call super.releaseResource() first.
The available() method of in indicates how much data can be read, i.e. how much was originally written.
- Specified by:
generateUndo
in interfaceUndoable
- Parameters:
xact
- the transaction doing the rollback- Returns:
- the compensation operation that will rollback this change, or null if nothing to undo.
- Throws:
StandardException
- Standard Derby policy.IOException
- Can be thrown by any of the methods of ObjectInput.- See Also:
-