1 8 9 package com.sleepycat.je.log.entry; 10 11 import java.nio.ByteBuffer ; 12 13 import com.sleepycat.je.DatabaseException; 14 import com.sleepycat.je.dbi.DatabaseId; 15 import com.sleepycat.je.dbi.EnvironmentImpl; 16 import com.sleepycat.je.log.LogEntryType; 17 import com.sleepycat.je.log.LogUtils; 18 import com.sleepycat.je.log.LoggableObject; 19 import com.sleepycat.je.tree.IN; 20 import com.sleepycat.je.utilint.DbLsn; 21 22 26 public class INLogEntry 27 implements LogEntry, LoggableObject, NodeLogEntry, INContainingEntry { 28 29 30 private IN in; 31 private DatabaseId dbId; 32 33 38 private long obsoleteLsn; 39 40 private long nodeId; 41 private Class logClass; 42 43 46 public INLogEntry(Class logClass) { 47 this.logClass = logClass; 48 } 49 50 53 public INLogEntry(IN in) { 54 this.in = in; 55 this.dbId = in.getDatabase().getId(); 56 this.logClass = in.getClass(); 57 this.nodeId = in.getNodeId(); 58 this.obsoleteLsn = in.getLastFullVersion(); 59 } 60 61 64 65 68 public void readEntry(ByteBuffer entryBuffer, 69 int entrySize, 70 byte entryTypeVersion, 71 boolean readFullItem) 72 throws DatabaseException { 73 74 entryTypeVersion &= LogEntryType.clearProvisional(entryTypeVersion); 75 76 try { 77 if (readFullItem) { 78 79 in = (IN) logClass.newInstance(); 80 in.readFromLog(entryBuffer, entryTypeVersion); 81 nodeId = in.getNodeId(); 82 } else { 83 84 int position = entryBuffer.position() + entrySize; 85 if (entryTypeVersion == 1) { 86 87 position -= LogUtils.UNSIGNED_INT_BYTES; 88 } else if (entryTypeVersion >= 2) { 89 90 position -= LogUtils.LONG_BYTES; 91 } 92 93 position -= LogUtils.INT_BYTES; 94 95 nodeId = LogUtils.readLong(entryBuffer); 96 entryBuffer.position(position); 97 in = null; 98 } 99 dbId = new DatabaseId(); 100 dbId.readFromLog(entryBuffer, entryTypeVersion); 101 if (entryTypeVersion < 1) { 102 obsoleteLsn = DbLsn.NULL_LSN; 103 } else if (entryTypeVersion == 1) { 104 long fileNum = LogUtils.getUnsignedInt(entryBuffer); 105 if (fileNum == 0xffffffffL) { 106 obsoleteLsn = DbLsn.NULL_LSN; 107 } else { 108 obsoleteLsn = DbLsn.makeLsn(fileNum, 0); 109 } 110 } else { 111 obsoleteLsn = LogUtils.readLong(entryBuffer); 112 } 113 } catch (IllegalAccessException e) { 114 throw new DatabaseException(e); 115 } catch (InstantiationException e) { 116 throw new DatabaseException(e); 117 } 118 } 119 120 125 public long getObsoleteLsn() { 126 127 return obsoleteLsn; 128 } 129 130 133 public StringBuffer dumpEntry(StringBuffer sb, boolean verbose) { 134 in.dumpLog(sb, verbose); 135 dbId.dumpLog(sb, verbose); 136 return sb; 137 } 138 139 142 public Object getMainItem() { 143 return in; 144 } 145 146 public Object clone() 147 throws CloneNotSupportedException { 148 149 return super.clone(); 150 } 151 152 155 public boolean isTransactional() { 156 return false; 157 } 158 159 162 public long getTransactionId() { 163 return 0; 164 } 165 166 169 170 173 public LogEntryType getLogType() { 174 return in.getLogType(); 175 } 176 177 181 public boolean marshallOutsideWriteLatch() { 182 return in.marshallOutsideWriteLatch(); 183 } 184 185 188 public boolean countAsObsoleteWhenLogged() { 189 return false; 190 } 191 192 195 public void postLogWork(long justLoggedLsn) { 196 } 197 198 201 public int getLogSize() { 202 return (in.getLogSize() + 203 dbId.getLogSize() + 204 LogUtils.LONG_BYTES); 205 } 206 207 210 public void writeToLog(ByteBuffer destBuffer) { 211 in.writeToLog(destBuffer); 212 dbId.writeToLog(destBuffer); 213 LogUtils.writeLong(destBuffer, obsoleteLsn); 214 } 215 216 220 public IN getIN(EnvironmentImpl env) 221 throws DatabaseException { 222 223 return in; 224 } 225 226 229 public long getNodeId() { 230 return nodeId; 231 } 232 233 236 public DatabaseId getDbId() { 237 238 return dbId; 239 } 240 241 245 public long getLsnOfIN(long lastReadLsn) { 246 return lastReadLsn; 247 } 248 } 249 | Popular Tags |