1 8 9 package com.sleepycat.je.recovery; 10 11 import java.nio.ByteBuffer ; 12 import java.sql.Timestamp ; 13 import java.util.Calendar ; 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 26 public class CheckpointEnd implements LoggableObject, LogReadable { 27 28 34 private String invoker; 35 36 private Timestamp 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 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 cal = Calendar.getInstance(); 61 this.endTime = new Timestamp (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 81 public CheckpointEnd() { 82 checkpointStartLsn = DbLsn.NULL_LSN; 83 rootLsn = DbLsn.NULL_LSN; 84 firstActiveLsn = DbLsn.NULL_LSN; 85 } 86 87 90 91 94 public LogEntryType getLogType() { 95 return LogEntryType.LOG_CKPT_END; 96 } 97 98 102 public boolean marshallOutsideWriteLatch() { 103 return true; 104 } 105 106 109 public boolean countAsObsoleteWhenLogged() { 110 return false; 111 } 112 113 116 public void postLogWork(long justLoggedLsn) { 117 } 118 119 122 public int getLogSize() { 123 int size = 124 LogUtils.getStringLogSize(invoker) + LogUtils.getTimestampLogSize() + LogUtils.getLongLogSize() + LogUtils.getBooleanLogSize() + LogUtils.getLongLogSize() + LogUtils.getLongLogSize() + LogUtils.getIntLogSize() + LogUtils.getLongLogSize() + LogUtils.getLongLogSize(); 134 if (rootLsnExists) { 135 size += LogUtils.getLongLogSize(); 136 } 137 return size; 138 } 139 140 143 public void writeToLog(ByteBuffer 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 161 public void readFromLog(ByteBuffer 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 180 public void dumpLog(StringBuffer 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 207 public boolean logEntryIsTransactional() { 208 return false; 209 } 210 211 214 public long getTransactionId() { 215 return 0; 216 } 217 218 public String toString() { 219 StringBuffer sb = new StringBuffer (); 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 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 |