KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > log > CheckpointOperation


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.log.CheckpointOperation
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.store.raw.log;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25 import org.apache.derby.iapi.services.io.Formatable;
26 import org.apache.derby.iapi.services.io.FormatIdUtil;
27 import org.apache.derby.iapi.services.io.StoredFormatIds;
28 import org.apache.derby.catalog.UUID;
29
30 import org.apache.derby.iapi.store.raw.Transaction;
31 import org.apache.derby.iapi.store.raw.Loggable;
32 import org.apache.derby.iapi.store.raw.log.LogInstant;
33 import org.apache.derby.iapi.store.raw.log.LogFactory;
34 import org.apache.derby.iapi.store.raw.xact.RawTransaction;
35
36 import org.apache.derby.iapi.error.StandardException;
37
38 import org.apache.derby.iapi.services.io.CompressedNumber;
39 import org.apache.derby.iapi.util.ByteArray;
40
41 import java.io.Externalizable JavaDoc;
42 import java.io.OutputStream JavaDoc;
43 import java.io.InputStream JavaDoc;
44 import java.io.ObjectInput JavaDoc;
45 import java.io.ObjectOutput JavaDoc;
46 import java.io.IOException JavaDoc;
47 import org.apache.derby.iapi.services.io.LimitObjectInput;
48
49 /**
50     A Log Operation that represents a checkpoint.
51     @see Loggable
52 */

53
54 public class CheckpointOperation implements Loggable
55 {
56
57     // redo LWM
58
protected long redoLWM;
59
60     // undo LWM
61
protected long undoLWM;
62
63     protected Formatable transactionTable;
64
65     public CheckpointOperation(long redoLWM, long undoLWM, Formatable ttab)
66     {
67         this.redoLWM = redoLWM;
68         this.undoLWM = undoLWM;
69         this.transactionTable = ttab;
70     }
71
72     /*
73      * Formatable methods
74      */

75
76     // no-arg constructor, required by Formatable
77
public CheckpointOperation() { super(); }
78
79     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
80     {
81         CompressedNumber.writeLong(out, redoLWM);
82         CompressedNumber.writeLong(out, undoLWM);
83         // RESOLVE: Following write Not needed, keeping it to avoid upgrade/downgrade issues.
84
CompressedNumber.writeInt(out, 0); // no other truncation LWM
85

86         if (transactionTable == null)
87             CompressedNumber.writeInt(out, 0);
88         else
89         {
90             CompressedNumber.writeInt(out, 1);
91             out.writeObject(transactionTable);
92         }
93     }
94
95     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
96     {
97         redoLWM = CompressedNumber.readLong(in);
98         undoLWM = CompressedNumber.readLong(in);
99
100         // RESOLVE: Following read Not required, keeping it to avoid upgrade/downgrade issues.
101
int tsize = CompressedNumber.readInt(in); // is there any truncationLWM?
102

103         int haveTTab = CompressedNumber.readInt(in);
104         if (haveTTab == 1)
105             transactionTable = (Formatable)in.readObject();
106         else
107             transactionTable = (Formatable)null;
108     }
109
110     /**
111         Return my format identifier.
112     */

113     public int getTypeFormatId() {
114         return StoredFormatIds.LOGOP_CHECKPOINT;
115     }
116
117     /**
118         Loggable methods
119     */

120
121     /**
122      * Nothing to do unless we are rollforward recovery;
123      * Redoing of checkpoints during rollforward recovery allows us to restart
124      * the roll-forward recovery from the last checkpoint redone during rollforward recovery, if
125      * we happen to crash during the roll-forward recovery process.
126      * Another reason why we need to do this is dropped table stub files
127      * removed at checkpoint because the containerids may have been reused
128      * after a checkpoint if the system was rebooted.
129     */

130     public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in) throws StandardException
131     {
132         //redo the checkpoint if we are in roll-forward recovery only
133
if(((RawTransaction)xact).inRollForwardRecovery())
134         {
135             ((RawTransaction)xact).checkpointInRollForwardRecovery(instant, redoLWM);
136         }
137         return;
138     }
139
140     /**
141         the default for prepared log is always null for all the operations
142         that don't have optionalData. If an operation has optional data,
143         the operation need to prepare the optional data for this method.
144
145         Checkpoint has no optional data to write out
146     */

147     public ByteArray getPreparedLog()
148     {
149         return (ByteArray) null;
150     }
151
152     /**
153         Checkpoint does not need to be redone unless
154         we are doing rollforward recovery.
155     */

156     public boolean needsRedo(Transaction xact)
157     {
158         
159         if(((RawTransaction)xact).inRollForwardRecovery())
160             return true;
161         else
162             return false;
163     }
164
165
166     /**
167       Checkpoint has not resource to release
168     */

169     public void releaseResource(Transaction xact)
170     {}
171
172     /**
173         Checkpoint is a raw store operation
174     */

175     public int group()
176     {
177         return Loggable.RAWSTORE;
178     }
179
180     /**
181         Access attributes of the checkpoint record
182     */

183     public long redoLWM()
184     {
185         return redoLWM;
186     }
187
188     public long undoLWM()
189     {
190         return undoLWM;
191     }
192
193
194     public Formatable getTransactionTable()
195     {
196         return transactionTable;
197     }
198
199     /**
200       DEBUG: Print self.
201     */

202     public String JavaDoc toString()
203     {
204         if (SanityManager.DEBUG)
205         {
206             LogCounter undolwm = new LogCounter(undoLWM);
207             LogCounter redolwm = new LogCounter(redoLWM);
208
209             StringBuffer JavaDoc str = new StringBuffer JavaDoc(1000)
210                 .append("Checkpoint : \tredoLWM ")
211                 .append(redolwm.toString())
212                 .append("\n\t\tundoLWM ").append(undolwm.toString());
213
214             if (transactionTable != null)
215             {
216                 str.append(transactionTable.toString());
217             }
218
219             return str.toString();
220         }
221         else
222             return null;
223     }
224 }
225
226
227
228
229
230
231
232
233
234
235
236
237
Popular Tags