Interface Undoable
-
- All Superinterfaces:
java.io.Externalizable
,Formatable
,Loggable
,java.io.Serializable
,TypedFormat
- All Known Subinterfaces:
LogicalUndoable
- All Known Implementing Classes:
AllocPageOperation
,ChainAllocPageOperation
,CompressSpacePageOperation
,CompressSpacePageOperation10_2
,ContainerOperation
,CopyRowsOperation
,DeleteOperation
,EncryptContainerOperation
,InitPageOperation
,InsertOperation
,InvalidatePageOperation
,LogicalPageOperation
,PhysicalPageOperation
,PurgeOperation
,RemoveFileOperation
,UpdateFieldOperation
,UpdateOperation
public interface Undoable extends Loggable
An Undoable operation is an operation that changed the state of the RawStore in the context of a transaction and this change can be rolled back.
-
-
Field Summary
-
Fields inherited from interface org.apache.derby.iapi.store.raw.Loggable
ABORT, BI_LOG, CHECKSUM, COMMIT, COMPENSATION, FILE_RESOURCE, FIRST, LAST, PREPARE, RAWSTORE, XA_NEEDLOCK
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Compensation
generateUndo(Transaction xact, LimitObjectInput in)
Generate a loggable which will undo this change, using the optional input if necessary.-
Methods inherited from interface org.apache.derby.iapi.store.raw.Loggable
doMe, getPreparedLog, group, needsRedo, releaseResource
-
Methods inherited from interface org.apache.derby.iapi.services.io.TypedFormat
getTypeFormatId
-
-
-
-
Method Detail
-
generateUndo
Compensation generateUndo(Transaction xact, LimitObjectInput in) throws StandardException, java.io.IOException
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.
- Parameters:
xact
- the transaction doing the rollback- Returns:
- the compensation operation that will rollback this change, or null if nothing to undo.
- Throws:
java.io.IOException
- Can be thrown by any of the methods of ObjectInput.StandardException
- Standard Derby policy.- See Also:
Loggable.releaseResource(org.apache.derby.iapi.store.raw.Transaction)
,Loggable.needsRedo(org.apache.derby.iapi.store.raw.Transaction)
-
-