1 8 9 package com.sleepycat.je.log; 10 11 import java.io.IOException ; 12 import java.nio.ByteBuffer ; 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import com.sleepycat.je.DatabaseException; 17 import com.sleepycat.je.dbi.DatabaseId; 18 import com.sleepycat.je.dbi.EnvironmentImpl; 19 import com.sleepycat.je.log.entry.INLogEntry; 20 import com.sleepycat.je.log.entry.LNLogEntry; 21 import com.sleepycat.je.log.entry.LogEntry; 22 import com.sleepycat.je.tree.IN; 23 import com.sleepycat.je.tree.LN; 24 import com.sleepycat.je.utilint.DbLsn; 25 26 29 public class CleanerFileReader extends FileReader { 30 private static final byte IS_IN = 0; 31 private static final byte IS_LN = 1; 32 private static final byte IS_ROOT = 2; 33 private static final byte IS_FILEHEADER = 3; 34 35 private Map targetEntryMap; 36 private LogEntry targetLogEntry; 37 private byte targetCategory; 38 39 46 public CleanerFileReader(EnvironmentImpl env, 47 int readBufferSize, 48 long startLsn, 49 Long fileNum) 50 throws IOException , DatabaseException { 51 52 super(env, 53 readBufferSize, 54 true, startLsn, 56 fileNum, DbLsn.NULL_LSN, DbLsn.NULL_LSN); 60 targetEntryMap = new HashMap (); 61 62 addTargetType(IS_LN, LogEntryType.LOG_LN_TRANSACTIONAL); 63 addTargetType(IS_LN, LogEntryType.LOG_LN); 64 addTargetType(IS_LN, LogEntryType.LOG_NAMELN_TRANSACTIONAL); 65 addTargetType(IS_LN, LogEntryType.LOG_NAMELN); 66 addTargetType(IS_LN, LogEntryType.LOG_MAPLN_TRANSACTIONAL); 67 addTargetType(IS_LN, LogEntryType.LOG_MAPLN); 68 addTargetType(IS_LN, LogEntryType.LOG_DEL_DUPLN_TRANSACTIONAL); 69 addTargetType(IS_LN, LogEntryType.LOG_DEL_DUPLN); 70 addTargetType(IS_LN, LogEntryType.LOG_DUPCOUNTLN_TRANSACTIONAL); 71 addTargetType(IS_LN, LogEntryType.LOG_DUPCOUNTLN); 72 addTargetType(IS_LN, LogEntryType.LOG_FILESUMMARYLN); 73 addTargetType(IS_IN, LogEntryType.LOG_IN); 74 addTargetType(IS_IN, LogEntryType.LOG_BIN); 75 addTargetType(IS_IN, LogEntryType.LOG_DIN); 76 addTargetType(IS_IN, LogEntryType.LOG_DBIN); 77 addTargetType(IS_ROOT, LogEntryType.LOG_ROOT); 78 addTargetType(IS_FILEHEADER, LogEntryType.LOG_FILE_HEADER); 79 } 80 81 private void addTargetType(byte category, LogEntryType entryType) 82 throws DatabaseException { 83 84 targetEntryMap.put(entryType, 85 new EntryInfo(entryType.getNewLogEntry(), 86 category)); 87 } 88 89 93 protected void initStartingPosition(long endOfFileLsn, 94 Long fileNum) 95 throws IOException , DatabaseException { 96 97 eof = false; 98 99 104 readBufferFileNum = fileNum.longValue(); 105 readBufferFileEnd = 0; 106 107 111 nextEntryOffset = readBufferFileEnd; 112 } 113 114 117 protected boolean isTargetEntry(byte entryTypeNum, 118 byte entryTypeVersion) { 119 120 LogEntryType fromLogType = new LogEntryType(entryTypeNum, 121 entryTypeVersion); 122 123 124 EntryInfo info = (EntryInfo) targetEntryMap.get(fromLogType); 125 if (info == null) { 126 return false; 127 } else { 128 targetCategory = info.targetCategory; 129 targetLogEntry = info.targetLogEntry; 130 return true; 131 } 132 } 133 134 137 protected boolean processEntry(ByteBuffer entryBuffer) 138 throws DatabaseException { 139 140 targetLogEntry.readEntry(entryBuffer, currentEntrySize, 141 currentEntryTypeVersion, true); 142 return true; 143 } 144 145 148 public boolean isIN() { 149 return (targetCategory == IS_IN); 150 } 151 152 155 public boolean isLN() { 156 return (targetCategory == IS_LN); 157 } 158 159 162 public boolean isRoot() { 163 return (targetCategory == IS_ROOT); 164 } 165 166 public boolean isFileHeader() { 167 return (targetCategory == IS_FILEHEADER); 168 } 169 170 173 public LN getLN() { 174 return ((LNLogEntry) targetLogEntry).getLN(); 175 } 176 177 180 public IN getIN() 181 throws DatabaseException { 182 183 return ((INLogEntry) targetLogEntry).getIN(env); 184 } 185 186 public FileHeader getFileHeader() 187 throws DatabaseException { 188 189 return (FileHeader) (targetLogEntry.getMainItem()); 190 } 191 192 195 public DatabaseId getDatabaseId() { 196 if (targetCategory == IS_LN) { 197 return ((LNLogEntry) targetLogEntry).getDbId(); 198 } else if (targetCategory == IS_IN) { 199 return ((INLogEntry) targetLogEntry).getDbId(); 200 } else { 201 return null; 202 } 203 } 204 205 208 public byte[] getKey() { 209 return ((LNLogEntry) targetLogEntry).getKey(); 210 } 211 212 215 public byte[] getDupTreeKey() { 216 return ((LNLogEntry) targetLogEntry).getDupKey(); 217 } 218 219 private static class EntryInfo { 220 public LogEntry targetLogEntry; 221 public byte targetCategory; 222 223 EntryInfo(LogEntry targetLogEntry, byte targetCategory) { 224 this.targetLogEntry = targetLogEntry; 225 this.targetCategory = targetCategory; 226 } 227 } 228 } 229 | Popular Tags |