1 8 9 package com.sleepycat.je.log; 10 11 import java.util.HashSet ; 12 import java.util.Set ; 13 14 import com.sleepycat.je.DatabaseException; 15 import com.sleepycat.je.log.entry.BINDeltaLogEntry; 16 import com.sleepycat.je.log.entry.DeletedDupLNLogEntry; 17 import com.sleepycat.je.log.entry.INLogEntry; 18 import com.sleepycat.je.log.entry.LNLogEntry; 19 import com.sleepycat.je.log.entry.LogEntry; 20 import com.sleepycat.je.log.entry.SingleItemLogEntry; 21 22 34 public class LogEntryType { 35 36 42 43 private static final int MAX_TYPE_NUM = 27; 44 45 private static LogEntryType[] LOG_TYPES = new LogEntryType[MAX_TYPE_NUM]; 46 47 59 60 61 public static final LogEntryType LOG_LN_TRANSACTIONAL = 62 new LogEntryType((byte) 1, (byte) 0, "LN_TX", 63 new LNLogEntry(com.sleepycat.je.tree.LN.class, 64 true), 65 true ); 66 67 public static final LogEntryType LOG_LN = 68 new LogEntryType((byte) 2, (byte) 0, "LN", 69 new LNLogEntry(com.sleepycat.je.tree.LN.class, 70 false), 71 false ); 72 73 public static final LogEntryType LOG_MAPLN_TRANSACTIONAL = 74 new LogEntryType((byte) 3, (byte) 2, "MapLN_TX", 75 new LNLogEntry(com.sleepycat.je.tree.MapLN.class, 76 true), 77 true ); 78 79 public static final LogEntryType LOG_MAPLN = 80 new LogEntryType((byte) 4, (byte) 2, "MapLN", 81 new LNLogEntry(com.sleepycat.je.tree.MapLN.class, 82 false), 83 false ); 84 85 public static final LogEntryType LOG_NAMELN_TRANSACTIONAL = 86 new LogEntryType((byte) 5, (byte) 0, "NameLN_TX", 87 new LNLogEntry(com.sleepycat.je.tree.NameLN.class, 88 true), 89 true ); 90 91 public static final LogEntryType LOG_NAMELN = 92 new LogEntryType((byte) 6, (byte) 0, "NameLN", 93 new LNLogEntry(com.sleepycat.je.tree.NameLN.class, 94 false), 95 false ); 96 97 public static final LogEntryType LOG_DEL_DUPLN_TRANSACTIONAL = 98 new LogEntryType((byte) 7, (byte) 0, "DelDupLN_TX", 99 new DeletedDupLNLogEntry(true), 100 true ); 101 102 public static final LogEntryType LOG_DEL_DUPLN = 103 new LogEntryType((byte) 8, (byte) 0, "DelDupLN", 104 new DeletedDupLNLogEntry(false), 105 false ); 106 107 public static final LogEntryType LOG_DUPCOUNTLN_TRANSACTIONAL = 108 new LogEntryType 109 ((byte) 9, (byte) 0, "DupCountLN_TX", 110 new LNLogEntry(com.sleepycat.je.tree.DupCountLN.class, true), 111 true ); 112 113 public static final LogEntryType LOG_DUPCOUNTLN = 114 new LogEntryType 115 ((byte) 10, (byte) 0, "DupCountLN", 116 new LNLogEntry(com.sleepycat.je.tree.DupCountLN.class, false), 117 false ); 118 119 public static final LogEntryType LOG_FILESUMMARYLN = 120 new LogEntryType 121 ((byte) 11, (byte) 3, "FileSummaryLN", 122 new LNLogEntry(com.sleepycat.je.tree.FileSummaryLN.class, false), 123 false ); 124 125 public static final LogEntryType LOG_IN = 126 new LogEntryType 127 ((byte) 12, (byte) 2, "IN", 128 new INLogEntry(com.sleepycat.je.tree.IN.class), 129 false ); 130 131 public static final LogEntryType LOG_BIN = 132 new LogEntryType 133 ((byte) 13, (byte) 2, "BIN", 134 new INLogEntry(com.sleepycat.je.tree.BIN.class), 135 false ); 136 137 public static final LogEntryType LOG_DIN = 138 new LogEntryType 139 ((byte) 14, (byte) 2, "DIN", 140 new INLogEntry(com.sleepycat.je.tree.DIN.class), 141 false ); 142 143 public static final LogEntryType LOG_DBIN = 144 new LogEntryType 145 ((byte) 15, (byte) 2, "DBIN", 146 new INLogEntry(com.sleepycat.je.tree.DBIN.class), 147 false ); 148 149 public static final LogEntryType[] IN_TYPES = { 150 LogEntryType.LOG_IN, 151 LogEntryType.LOG_BIN, 152 LogEntryType.LOG_DIN, 153 LogEntryType.LOG_DBIN, 154 }; 155 156 157 158 private static final int MAX_NODE_TYPE_NUM = 15; 159 160 public static boolean isNodeType(byte typeNum, byte version) { 161 return (typeNum <= MAX_NODE_TYPE_NUM); 162 } 163 164 165 public static final LogEntryType LOG_ROOT = 166 new LogEntryType((byte) 16, (byte) 1, "Root", 167 new SingleItemLogEntry 168 (com.sleepycat.je.dbi.DbTree.class), 169 false ); 170 171 172 public static final LogEntryType LOG_TXN_COMMIT = 173 new LogEntryType((byte) 17, (byte) 0, "Commit", 174 new SingleItemLogEntry 175 (com.sleepycat.je.txn.TxnCommit.class), 176 true ); 177 178 public static final LogEntryType LOG_TXN_ABORT = 179 new LogEntryType((byte) 18, (byte) 0, "Abort", 180 new SingleItemLogEntry 181 (com.sleepycat.je.txn.TxnAbort.class), 182 true ); 183 184 public static final LogEntryType LOG_CKPT_START = 185 new LogEntryType 186 ((byte) 19, (byte) 0, "CkptStart", 187 new SingleItemLogEntry 188 (com.sleepycat.je.recovery.CheckpointStart.class), 189 false ); 190 191 public static final LogEntryType LOG_CKPT_END = 192 new LogEntryType((byte) 20, (byte) 0, "CkptEnd", 193 new SingleItemLogEntry 194 (com.sleepycat.je.recovery.CheckpointEnd.class), 195 false ); 196 197 public static final LogEntryType LOG_IN_DELETE_INFO = 198 new LogEntryType((byte) 21, (byte) 0, "INDelete", 199 new SingleItemLogEntry 200 (com.sleepycat.je.tree.INDeleteInfo.class), 201 false ); 202 203 public static final LogEntryType LOG_BIN_DELTA = 204 new LogEntryType((byte) 22, (byte) 0, "BINDelta", 205 new BINDeltaLogEntry 206 (com.sleepycat.je.tree.BINDelta.class), 207 false ); 208 209 public static final LogEntryType LOG_DUP_BIN_DELTA = 210 new LogEntryType((byte) 23, (byte) 0, "DupBINDelta", 211 new BINDeltaLogEntry 212 (com.sleepycat.je.tree.BINDelta.class), 213 false ); 214 215 216 public static final LogEntryType LOG_TRACE = 217 new LogEntryType((byte) 24, (byte) 0, "Trace", 218 new SingleItemLogEntry 219 (com.sleepycat.je.utilint.Tracer.class), 220 false ); 221 222 223 public static final LogEntryType LOG_FILE_HEADER = 224 new LogEntryType((byte) 25, (byte) 0, "FileHeader", 225 new SingleItemLogEntry 226 (com.sleepycat.je.log.FileHeader.class), 227 false ); 228 229 public static final LogEntryType LOG_IN_DUPDELETE_INFO = 230 new LogEntryType((byte) 26, (byte) 0, "INDupDelete", 231 new SingleItemLogEntry 232 (com.sleepycat.je.tree.INDupDeleteInfo.class), 233 false ); 234 235 public static final LogEntryType LOG_TXN_PREPARE = 236 new LogEntryType((byte) 27, (byte) 0, "Prepare", 237 new SingleItemLogEntry 238 (com.sleepycat.je.txn.TxnPrepare.class), 239 false ); 240 241 242 243 244 245 private static final byte PROVISIONAL_MASK = (byte) 0x80; 246 private static final byte IGNORE_PROVISIONAL = ~PROVISIONAL_MASK; 247 248 251 private byte typeNum; private byte version; private String displayName; 254 private LogEntry logEntry; 255 private boolean isReplicated; 256 257 260 261 264 265 266 LogEntryType(byte typeNum, byte version) { 267 this.typeNum = typeNum; 268 this.version = version; 269 } 270 271 274 private LogEntryType(byte typeNum, 275 byte version, 276 String displayName, 277 LogEntry logEntry, 278 boolean isReplicated) { 279 280 this.typeNum = typeNum; 281 this.version = version; 282 this.logEntry = logEntry; 283 this.displayName = displayName; 284 this.isReplicated = isReplicated; 285 LOG_TYPES[typeNum - 1] = this; 286 } 287 288 public boolean isNodeType() { 289 return (typeNum <= MAX_NODE_TYPE_NUM); 290 } 291 292 295 public static LogEntryType findType(byte typeNum, byte version) { 296 if (typeNum <= 0 || typeNum > MAX_TYPE_NUM) { 297 return null; 298 } 299 return (LogEntryType) LOG_TYPES[typeNum - 1]; 300 } 301 302 305 public static Set getAllTypes() { 306 HashSet ret = new HashSet (); 307 308 for (int i = 0; i < MAX_TYPE_NUM; i++) { 309 ret.add(LOG_TYPES[i]); 310 } 311 return ret; 312 } 313 314 317 public LogEntry getSharedLogEntry() { 318 return logEntry; 319 } 320 321 324 LogEntry getNewLogEntry() 325 throws DatabaseException { 326 327 try { 328 return (LogEntry) logEntry.clone(); 329 } catch (CloneNotSupportedException e) { 330 throw new DatabaseException(e); 331 } 332 } 333 334 337 static byte setProvisional(byte version) { 338 return (byte) (version | PROVISIONAL_MASK); 339 } 340 341 344 public static byte clearProvisional(byte version) { 345 return (byte) (version & IGNORE_PROVISIONAL); 346 } 347 348 351 static boolean isProvisional(byte version) { 352 return ((version & PROVISIONAL_MASK) != 0); 353 } 354 355 byte getTypeNum() { 356 return typeNum; 357 } 358 359 byte getVersion() { 360 return version; 361 } 362 363 366 static boolean isValidType(byte typeNum) { 367 return typeNum > 0 && typeNum <= MAX_TYPE_NUM; 368 } 369 370 public String toString() { 371 return displayName + "/" + version; 372 } 373 374 377 boolean equalsType(byte typeNum, byte version) { 378 return (this.typeNum == typeNum); 379 } 380 381 public boolean equalsType(byte typeNum) { 382 return (this.typeNum == typeNum); 383 } 384 385 389 public boolean equals(Object obj) { 390 if (this == obj) { 392 return true; 393 } 394 395 if (!(obj instanceof LogEntryType)) { 397 return false; 398 } 399 400 return typeNum == ((LogEntryType) obj).typeNum; 401 } 402 403 406 public int hashCode() { 407 return typeNum; 408 } 409 410 414 public boolean isReplicated() { 415 return isReplicated; 416 } 417 } 418 | Popular Tags |