KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > recovery > CheckpointEnd


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: CheckpointEnd.java,v 1.28 2006/10/30 21:14:22 bostic Exp $
7  */

8
9 package com.sleepycat.je.recovery;
10
11 import java.nio.ByteBuffer JavaDoc;
12 import java.sql.Timestamp JavaDoc;
13 import java.util.Calendar JavaDoc;
14
15 import com.sleepycat.je.log.LogEntryType;
16 import com.sleepycat.je.log.LogException;
17 import com.sleepycat.je.log.LogReadable;
18 import com.sleepycat.je.log.LogUtils;
19 import com.sleepycat.je.log.LoggableObject;
20 import com.sleepycat.je.utilint.DbLsn;
21
22 /**
23  * CheckpointEnd encapsulates the information needed by a checkpoint end
24  * log entry.
25  */

26 public class CheckpointEnd implements LoggableObject, LogReadable {
27     
28     /*
29      * invoker is just a way to tag each checkpoint in the
30      * log for easier log based debugging. It will tell us whether the
31      * checkpoint was invoked by recovery, the daemon, the api, or
32      * the cleaner.
33      */

34     private String JavaDoc invoker;
35
36     private Timestamp JavaDoc endTime;
37     private long checkpointStartLsn;
38     private boolean rootLsnExists;
39     private long rootLsn;
40     private long firstActiveLsn;
41     private long lastNodeId;
42     private int lastDbId;
43     private long lastTxnId;
44     private long id;
45
46     public CheckpointEnd(String JavaDoc invoker,
47                          long checkpointStartLsn,
48                          long rootLsn,
49                          long firstActiveLsn,
50                          long lastNodeId,
51                          int lastDbId,
52                          long lastTxnId,
53                          long id) {
54         if (invoker == null) {
55             this.invoker = "";
56         } else {
57             this.invoker = invoker;
58         }
59             
60         Calendar JavaDoc cal = Calendar.getInstance();
61         this.endTime = new Timestamp JavaDoc(cal.getTime().getTime());
62         this.checkpointStartLsn = checkpointStartLsn;
63         this.rootLsn = rootLsn;
64         if (rootLsn == DbLsn.NULL_LSN) {
65             rootLsnExists = false;
66         } else {
67             rootLsnExists = true;
68         }
69         if (firstActiveLsn == DbLsn.NULL_LSN) {
70             this.firstActiveLsn = checkpointStartLsn;
71         } else {
72             this.firstActiveLsn = firstActiveLsn;
73         }
74         this.lastNodeId = lastNodeId;
75         this.lastDbId = lastDbId;
76         this.lastTxnId = lastTxnId;
77         this.id = id;
78     }
79
80     /* For logging only */
81     public CheckpointEnd() {
82         checkpointStartLsn = DbLsn.NULL_LSN;
83         rootLsn = DbLsn.NULL_LSN;
84         firstActiveLsn = DbLsn.NULL_LSN;
85     }
86
87     /*
88      * Logging support for writing to the log
89      */

90
91     /**
92      * @see LoggableObject#getLogType
93      */

94     public LogEntryType getLogType() {
95         return LogEntryType.LOG_CKPT_END;
96     }
97
98     /**
99      * @see LoggableObject#marshallOutsideWriteLatch
100      * Can be marshalled outside the log write latch.
101      */

102     public boolean marshallOutsideWriteLatch() {
103         return true;
104     }
105
106     /**
107      * @see LoggableObject#countAsObsoleteWhenLogged
108      */

109     public boolean countAsObsoleteWhenLogged() {
110         return false;
111     }
112
113     /**
114      * @see LoggableObject#postLogWork
115      */

116     public void postLogWork(long justLoggedLsn) {
117     }
118
119     /**
120      * @see LoggableObject#getLogSize
121      */

122     public int getLogSize() {
123         int size =
124             LogUtils.getStringLogSize(invoker) + // invoker
125
LogUtils.getTimestampLogSize() + // endTime
126
LogUtils.getLongLogSize() + // checkpointStartLsn
127
LogUtils.getBooleanLogSize() + // rootLsnExists
128
LogUtils.getLongLogSize() + // firstActiveLsn
129
LogUtils.getLongLogSize() + // lastNodeId
130
LogUtils.getIntLogSize() + // lastDbId
131
LogUtils.getLongLogSize() + // lastTxnId
132
LogUtils.getLongLogSize(); // id
133

134         if (rootLsnExists) {
135             size += LogUtils.getLongLogSize();
136         }
137         return size;
138     }
139
140     /**
141      * @see LoggableObject#writeToLog
142      */

143     public void writeToLog(ByteBuffer JavaDoc logBuffer) {
144         LogUtils.writeString(logBuffer, invoker);
145         LogUtils.writeTimestamp(logBuffer, endTime);
146     LogUtils.writeLong(logBuffer, checkpointStartLsn);
147         LogUtils.writeBoolean(logBuffer, rootLsnExists);
148         if (rootLsnExists) {
149         LogUtils.writeLong(logBuffer, rootLsn);
150         }
151     LogUtils.writeLong(logBuffer, firstActiveLsn);
152         LogUtils.writeLong(logBuffer, lastNodeId);
153         LogUtils.writeInt(logBuffer, lastDbId);
154         LogUtils.writeLong(logBuffer, lastTxnId);
155         LogUtils.writeLong(logBuffer, id);
156     }
157
158     /**
159      * @see LogReadable#readFromLog
160      */

161     public void readFromLog(ByteBuffer JavaDoc logBuffer, byte entryTypeVersion)
162     throws LogException {
163         invoker = LogUtils.readString(logBuffer);
164         endTime = LogUtils.readTimestamp(logBuffer);
165     checkpointStartLsn = LogUtils.readLong(logBuffer);
166         rootLsnExists = LogUtils.readBoolean(logBuffer);
167         if (rootLsnExists) {
168         rootLsn = LogUtils.readLong(logBuffer);
169         }
170     firstActiveLsn = LogUtils.readLong(logBuffer);
171         lastNodeId = LogUtils.readLong(logBuffer);
172         lastDbId = LogUtils.readInt(logBuffer);
173         lastTxnId = LogUtils.readLong(logBuffer);
174         id = LogUtils.readLong(logBuffer);
175     }
176
177     /**
178      * @see LogReadable#dumpLog
179      */

180     public void dumpLog(StringBuffer JavaDoc sb, boolean verbose) {
181         sb.append("<CkptEnd invoker=\"").append(invoker);
182         sb.append("\" time=\"").append(endTime);
183         sb.append("\" lastNodeId=\"").append(lastNodeId);
184         sb.append("\" lastDbId=\"").append(lastDbId);
185         sb.append("\" lastTxnId=\"").append(lastTxnId);
186         sb.append("\" id=\"").append(id);
187         sb.append("\" rootExists=\"").append(rootLsnExists);
188         sb.append("\">");
189         sb.append("<ckptStart>");
190     sb.append(DbLsn.toString(checkpointStartLsn));
191         sb.append("</ckptStart>");
192
193         if (rootLsnExists) {
194             sb.append("<root>");
195         sb.append(DbLsn.toString(rootLsn));
196             sb.append("</root>");
197         }
198         sb.append("<firstActive>");
199     sb.append(DbLsn.toString(firstActiveLsn));
200         sb.append("</firstActive>");
201         sb.append("</CkptEnd>");
202     }
203
204     /**
205      * @see LogReadable#logEntryIsTransactional
206      */

207     public boolean logEntryIsTransactional() {
208     return false;
209     }
210
211     /**
212      * @see LogReadable#getTransactionId
213      */

214     public long getTransactionId() {
215     return 0;
216     }
217
218     public String JavaDoc toString() {
219         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
220         sb.append("time=").append(endTime);
221         sb.append(" lastNodeId=").append(lastNodeId);
222         sb.append(" lastDbId=").append(lastDbId);
223         sb.append(" lastTxnId=").append(lastTxnId);
224         sb.append(" id=").append(id);
225         sb.append(" rootExists=").append(rootLsnExists);
226         sb.append(" ckptStartLsn=").append
227             (DbLsn.getNoFormatString(checkpointStartLsn));
228         if (rootLsnExists) {
229             sb.append(" root=").append(DbLsn.getNoFormatString(rootLsn));
230         }
231         sb.append(" firstActive=").
232         append(DbLsn.getNoFormatString(firstActiveLsn));
233         return sb.toString();
234     }
235
236     /*
237      * Accessors
238      */

239     long getCheckpointStartLsn() {
240         return checkpointStartLsn;
241     }
242
243     long getRootLsn() {
244         return rootLsn;
245     }
246
247     long getFirstActiveLsn() {
248         return firstActiveLsn;
249     }
250
251     long getLastNodeId() {
252         return lastNodeId;
253     }
254     int getLastDbId() {
255         return lastDbId;
256     }
257     long getLastTxnId() {
258         return lastTxnId;
259     }
260     long getId() {
261         return id;
262     }
263 }
264
Popular Tags