001: /*
002:
003: Derby - Class org.apache.derby.impl.store.raw.log.CheckpointOperation
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.raw.log;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025: import org.apache.derby.iapi.services.io.Formatable;
026: import org.apache.derby.iapi.services.io.FormatIdUtil;
027: import org.apache.derby.iapi.services.io.StoredFormatIds;
028: import org.apache.derby.catalog.UUID;
029:
030: import org.apache.derby.iapi.store.raw.Transaction;
031: import org.apache.derby.iapi.store.raw.Loggable;
032: import org.apache.derby.iapi.store.raw.log.LogInstant;
033: import org.apache.derby.iapi.store.raw.log.LogFactory;
034: import org.apache.derby.iapi.store.raw.xact.RawTransaction;
035:
036: import org.apache.derby.iapi.error.StandardException;
037:
038: import org.apache.derby.iapi.services.io.CompressedNumber;
039: import org.apache.derby.iapi.util.ByteArray;
040:
041: import java.io.Externalizable;
042: import java.io.OutputStream;
043: import java.io.InputStream;
044: import java.io.ObjectInput;
045: import java.io.ObjectOutput;
046: import java.io.IOException;
047: import org.apache.derby.iapi.services.io.LimitObjectInput;
048:
049: /**
050: A Log Operation that represents a checkpoint.
051: @see Loggable
052: */
053:
054: public class CheckpointOperation implements Loggable {
055:
056: // redo LWM
057: protected long redoLWM;
058:
059: // undo LWM
060: protected long undoLWM;
061:
062: protected Formatable transactionTable;
063:
064: public CheckpointOperation(long redoLWM, long undoLWM,
065: Formatable ttab) {
066: this .redoLWM = redoLWM;
067: this .undoLWM = undoLWM;
068: this .transactionTable = ttab;
069: }
070:
071: /*
072: * Formatable methods
073: */
074:
075: // no-arg constructor, required by Formatable
076: public CheckpointOperation() {
077: super ();
078: }
079:
080: public void writeExternal(ObjectOutput out) throws IOException {
081: CompressedNumber.writeLong(out, redoLWM);
082: CompressedNumber.writeLong(out, undoLWM);
083: // RESOLVE: Following write Not needed, keeping it to avoid upgrade/downgrade issues.
084: CompressedNumber.writeInt(out, 0); // no other truncation LWM
085:
086: if (transactionTable == null)
087: CompressedNumber.writeInt(out, 0);
088: else {
089: CompressedNumber.writeInt(out, 1);
090: out.writeObject(transactionTable);
091: }
092: }
093:
094: public void readExternal(ObjectInput in) throws IOException,
095: ClassNotFoundException {
096: redoLWM = CompressedNumber.readLong(in);
097: undoLWM = CompressedNumber.readLong(in);
098:
099: // RESOLVE: Following read Not required, keeping it to avoid upgrade/downgrade issues.
100: int tsize = CompressedNumber.readInt(in); // is there any truncationLWM?
101:
102: int haveTTab = CompressedNumber.readInt(in);
103: if (haveTTab == 1)
104: transactionTable = (Formatable) in.readObject();
105: else
106: transactionTable = (Formatable) null;
107: }
108:
109: /**
110: Return my format identifier.
111: */
112: public int getTypeFormatId() {
113: return StoredFormatIds.LOGOP_CHECKPOINT;
114: }
115:
116: /**
117: Loggable methods
118: */
119:
120: /**
121: * Nothing to do unless we are rollforward recovery;
122: * Redoing of checkpoints during rollforward recovery allows us to restart
123: * the roll-forward recovery from the last checkpoint redone during rollforward recovery, if
124: * we happen to crash during the roll-forward recovery process.
125: * Another reason why we need to do this is dropped table stub files
126: * removed at checkpoint because the containerids may have been reused
127: * after a checkpoint if the system was rebooted.
128: */
129: public void doMe(Transaction xact, LogInstant instant,
130: LimitObjectInput in) throws StandardException {
131: //redo the checkpoint if we are in roll-forward recovery only
132: if (((RawTransaction) xact).inRollForwardRecovery()) {
133: ((RawTransaction) xact).checkpointInRollForwardRecovery(
134: instant, redoLWM);
135: }
136: return;
137: }
138:
139: /**
140: the default for prepared log is always null for all the operations
141: that don't have optionalData. If an operation has optional data,
142: the operation need to prepare the optional data for this method.
143:
144: Checkpoint has no optional data to write out
145: */
146: public ByteArray getPreparedLog() {
147: return (ByteArray) null;
148: }
149:
150: /**
151: Checkpoint does not need to be redone unless
152: we are doing rollforward recovery.
153: */
154: public boolean needsRedo(Transaction xact) {
155:
156: if (((RawTransaction) xact).inRollForwardRecovery())
157: return true;
158: else
159: return false;
160: }
161:
162: /**
163: Checkpoint has not resource to release
164: */
165: public void releaseResource(Transaction xact) {
166: }
167:
168: /**
169: Checkpoint is a raw store operation
170: */
171: public int group() {
172: return Loggable.RAWSTORE;
173: }
174:
175: /**
176: Access attributes of the checkpoint record
177: */
178: public long redoLWM() {
179: return redoLWM;
180: }
181:
182: public long undoLWM() {
183: return undoLWM;
184: }
185:
186: public Formatable getTransactionTable() {
187: return transactionTable;
188: }
189:
190: /**
191: DEBUG: Print self.
192: */
193: public String toString() {
194: if (SanityManager.DEBUG) {
195: LogCounter undolwm = new LogCounter(undoLWM);
196: LogCounter redolwm = new LogCounter(redoLWM);
197:
198: StringBuffer str = new StringBuffer(1000).append(
199: "Checkpoint : \tredoLWM ").append(
200: redolwm.toString()).append("\n\t\tundoLWM ")
201: .append(undolwm.toString());
202:
203: if (transactionTable != null) {
204: str.append(transactionTable.toString());
205: }
206:
207: return str.toString();
208: } else
209: return null;
210: }
211: }
|