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

public Class ContainerOperation

extends ContainerBasicOperation
implements Undoable
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.store.raw.Undoable, org.apache.derby.iapi.store.raw.Loggable, org.apache.derby.iapi.services.io.Formatable, org.apache.derby.iapi.services.io.TypedFormat, java.io.Externalizable, java.io.Serializable
Imports
org.apache.derby.iapi.services.io.FormatIdUtil, .StoredFormatIds, .LimitObjectInput, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.store.raw.Compensation, .ContainerHandle, .LockingPolicy, .Transaction, .Undoable, org.apache.derby.iapi.store.raw.xact.RawTransaction, org.apache.derby.iapi.store.raw.data.RawContainerHandle, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.util.ByteArray, java.io.ObjectOutput, .InputStream, .ObjectInput, .IOException

Log operation to create, drop or remove a container. Both the doMe or the undoMe of a create actually caused the container header to be modified and flushed before the log record is flushed. This is necessary for 2 reasons, one is that of ensuring enough disk space, and the other is because unlike any other operation, the log record create container is in the log stream before the container is in the container cache. What this mean is that if a checkpoint started after the container operation but before the container is kept or is dirtied in the container cache, then checkpoint will not know to wait for the container to be kept or cleaned. The checkpoint will erroneous assume that the operation does not need to be redone since its log instant is before the checkpoint but in fact the change has not been flushed to disk. A drop or remove container does not have this problem. The container exist and is in kept state when the operation is logged so the checkpoint will not overlook it and it doesn't need to flush the container header. In the case of remove, the stub is flushed for a different reason - that of ensuring disk space.

Field Summary

Modifier and TypeField and Description
protected static final byte
protected ByteArray
protected static final byte
protected transient boolean
protected byte
protected static final byte
Inherited from org.apache.derby.impl.store.raw.data.ContainerBasicOperation:
containerHdlcontainerId

Constructor Summary

AccessConstructor and Description
protected
public

Method Summary

Modifier and TypeMethod and Description
public final void
doMe(Transaction
the Transaction
tran
,
LogInstant
the log instant of this operation
instant
,
LimitObjectInput
optional data
in
)

Implements org.apache.derby.iapi.store.raw.Loggable.doMe.

Apply the change indicated by this operation and optional data.

protected RawContainerHandle
public Compensation
generateUndo(Transaction
the transaction doing the rollback
tran
,
LimitObjectInput in)

Implements org.apache.derby.iapi.store.raw.Undoable.generateUndo.

Generate a loggable which will undo this change, using the optional input if necessary.

public int
public void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Overrides org.apache.derby.impl.store.raw.data.ContainerBasicOperation.readExternal.

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

public String
public void
undoMe(Transaction
the transaction that is undoing this operation
tran
,
RawContainerHandle
the container handle. This is found here during runtime undo - in which case we made the CLR and passed in the containerHdl found in generateUndo and it is passed back to this; or it is found in the CLR's needsRedo and is passed in and this operation never found the container. Either case, release resource at the end is safe
hdl
,
LogInstant
the log instant of the CLR
CLRInstant
,
LimitObjectInput
optional data
in
)

Undo of create, drop or remove

public void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Overrides org.apache.derby.impl.store.raw.data.ContainerBasicOperation.writeExternal.

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Inherited from org.apache.derby.impl.store.raw.data.ContainerBasicOperation:
findContainergetPreparedLoggroupneedsRedoreleaseResource

Field Detail

CREATEback to summary
protected static final byte CREATE
createByteArrayback to summary
protected ByteArray createByteArray
DROPback to summary
protected static final byte DROP
hasCreateByteArrayback to summary
protected transient boolean hasCreateByteArray
operationback to summary
protected byte operation
REMOVEback to summary
protected static final byte REMOVE

Constructor Detail

ContainerOperationback to summary
protected ContainerOperation(RawContainerHandle hdl, byte operation) throws StandardException
ContainerOperationback to summary
public ContainerOperation()

Method Detail

doMeback to summary
public final void doMe(Transaction tran, LogInstant instant, LimitObjectInput in) throws StandardException

Implements org.apache.derby.iapi.store.raw.Loggable.doMe.

Doc from org.apache.derby.iapi.store.raw.Loggable.doMe.

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.

Parameters
tran:Transaction

the Transaction

instant:LogInstant

the log instant of this operation

in:LimitObjectInput

optional data

Exceptions
StandardException:
Standard Derby error policy
findContainerForRedoRecoveryback to summary
protected RawContainerHandle findContainerForRedoRecovery(RawTransaction xact) throws StandardException

Overrides org.apache.derby.impl.store.raw.data.ContainerBasicOperation.findContainerForRedoRecovery.

Find container for load tran.

If we are in load tran, and the operation is a create, the container may not (should not?) exist yet. We need to recreate it.

Exceptions
StandardException:
Standard Derby error policy.
generateUndoback to summary
public Compensation generateUndo(Transaction tran, LimitObjectInput in) throws StandardException

Implements org.apache.derby.iapi.store.raw.Undoable.generateUndo.

Doc from org.apache.derby.iapi.store.raw.Undoable.generateUndo.

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
tran:Transaction

the transaction doing the rollback

Returns:Compensation

the compensation operation that will rollback this change, or null if nothing to undo.

Exceptions
StandardException:
Standard Derby error policy
See Also
org.apache.derby.iapi.store.raw.Undoable
getTypeFormatIdback to summary
public int getTypeFormatId()

Implements org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

Return my format identifier.

Returns:int

Doc from org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

The identifier. (A UUID stuffed in an array of 16 bytes).

readExternalback to summary
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Overrides org.apache.derby.impl.store.raw.data.ContainerBasicOperation.readExternal.

Implements java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Parameters
in:ObjectInput

the stream to read data from in order to restore the object

Exceptions
IOException:
cannot read log record from log stream
ClassNotFoundException:
cannot read ByteArray object
toStringback to summary
public String toString()

Overrides org.apache.derby.impl.store.raw.data.ContainerBasicOperation.toString.

debug

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

undoMeback to summary
public void undoMe(Transaction tran, RawContainerHandle hdl, LogInstant CLRInstant, LimitObjectInput in) throws StandardException

Undo of create, drop or remove

Parameters
tran:Transaction

the transaction that is undoing this operation

hdl:RawContainerHandle

the container handle. This is found here during runtime undo - in which case we made the CLR and passed in the containerHdl found in generateUndo and it is passed back to this; or it is found in the CLR's needsRedo and is passed in and this operation never found the container. Either case, release resource at the end is safe

CLRInstant:LogInstant

the log instant of the CLR

in:LimitObjectInput

optional data

Exceptions
StandardException:
Standard Derby error policy
writeExternalback to summary
public void writeExternal(ObjectOutput out) throws IOException

Overrides org.apache.derby.impl.store.raw.data.ContainerBasicOperation.writeExternal.

Implements java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Parameters
out:ObjectOutput

the stream to write the object to

Exceptions
IOException:
Includes any I/O exceptions that may occur