1 8 9 package com.sleepycat.je.recovery.stepwise; 10 11 import java.io.IOException ; 12 import java.nio.ByteBuffer ; 13 import java.util.List ; 14 15 import com.sleepycat.bind.tuple.IntegerBinding; 16 import com.sleepycat.je.DatabaseEntry; 17 import com.sleepycat.je.DatabaseException; 18 import com.sleepycat.je.dbi.EnvironmentImpl; 19 import com.sleepycat.je.log.FileReader; 20 import com.sleepycat.je.log.LogEntryType; 21 import com.sleepycat.je.log.entry.DeletedDupLNLogEntry; 22 import com.sleepycat.je.log.entry.LNLogEntry; 23 import com.sleepycat.je.log.entry.LogEntry; 24 import com.sleepycat.je.log.entry.SingleItemLogEntry; 25 import com.sleepycat.je.txn.TxnCommit; 26 import com.sleepycat.je.utilint.DbLsn; 27 28 34 public class EntryTrackerReader extends FileReader { 35 36 40 private List entryInfo; 41 private DatabaseEntry dbt = new DatabaseEntry(); 42 private LogEntry useLogEntry; 43 private boolean isCommit; 44 45 48 public EntryTrackerReader(EnvironmentImpl env, 49 long startLsn, 50 List entryInfo) throws IOException , DatabaseException { 52 53 super(env, 2000, true, startLsn, null, 54 -1, DbLsn.NULL_LSN); 55 56 this.entryInfo = entryInfo; 57 } 58 59 62 protected boolean isTargetEntry(byte logEntryTypeNumber, 63 byte logEntryTypeVersion) { 64 isCommit = false; 65 66 if (LogEntryType.LOG_LN.equalsType(logEntryTypeNumber)) { 67 useLogEntry = LogEntryType.LOG_LN.getSharedLogEntry(); 68 return true; 69 } else if (LogEntryType.LOG_LN_TRANSACTIONAL.equalsType( 70 logEntryTypeNumber)) { 71 useLogEntry = 72 LogEntryType.LOG_LN_TRANSACTIONAL.getSharedLogEntry(); 73 return true; 74 } else if (LogEntryType.LOG_DEL_DUPLN.equalsType(logEntryTypeNumber)) { 75 useLogEntry = LogEntryType.LOG_DEL_DUPLN.getSharedLogEntry(); 76 return true; 77 } else if (LogEntryType.LOG_DEL_DUPLN_TRANSACTIONAL.equalsType( 78 logEntryTypeNumber)) { 79 useLogEntry = 80 LogEntryType.LOG_DEL_DUPLN_TRANSACTIONAL.getSharedLogEntry(); 81 return true; 82 } else if (LogEntryType.LOG_TXN_COMMIT.equalsType(logEntryTypeNumber)) { 83 useLogEntry = LogEntryType.LOG_TXN_COMMIT.getSharedLogEntry(); 84 isCommit = true; 85 return true; 86 } else { 87 92 entryInfo.add(new LogEntryInfo(DbLsn.makeLsn(readBufferFileNum, 93 nextEntryOffset), 94 0, 0)); 95 return false; 96 } 97 } 98 99 100 108 protected boolean processEntry(ByteBuffer entryBuffer) 109 throws DatabaseException { 110 111 115 long lsn = DbLsn.makeLsn(readBufferFileNum, currentEntryOffset); 116 useLogEntry.readEntry(entryBuffer, currentEntrySize, 117 currentEntryTypeVersion, true); 118 119 boolean isTxnal = useLogEntry.isTransactional(); 120 long txnId = useLogEntry.getTransactionId(); 121 122 if (isCommit) { 123 SingleItemLogEntry singleEntry = (SingleItemLogEntry) useLogEntry; 124 128 txnId = ((TxnCommit) singleEntry.getMainItem()).getId(); 129 entryInfo.add(new CommitEntry(lsn, txnId)); 130 } else if (useLogEntry instanceof DeletedDupLNLogEntry) { 131 132 133 DeletedDupLNLogEntry delDupLogEntry = 134 (DeletedDupLNLogEntry) useLogEntry; 135 dbt.setData(delDupLogEntry.getKey()); 136 int keyValue = IntegerBinding.entryToInt(dbt); 137 dbt.setData(delDupLogEntry.getDupKey()); 138 int dataValue = IntegerBinding.entryToInt(dbt); 139 140 if (isTxnal) { 141 entryInfo.add(new TxnalDeletedEntry(lsn, keyValue, 142 dataValue, txnId)); 143 } else { 144 entryInfo.add(new NonTxnalDeletedEntry(lsn, keyValue, 145 dataValue)); 146 } 147 } else { 148 LNLogEntry lnLogEntry = (LNLogEntry) useLogEntry; 149 byte [] keyArray = lnLogEntry.getKey(); 150 dbt.setData(keyArray); 151 int keyValue = IntegerBinding.entryToInt(dbt); 152 byte [] dataArray = lnLogEntry.getLN().getData(); 153 154 if (dataArray == null) { 155 156 if (isTxnal) { 157 entryInfo.add(new TxnalDeletedEntry(lsn, keyValue, -1, 158 txnId)); 159 } else { 160 entryInfo.add(new NonTxnalDeletedEntry(lsn, keyValue, -1)); 161 } 162 } else { 163 164 dbt.setData(dataArray); 165 int dataValue = IntegerBinding.entryToInt(dbt); 166 if (isTxnal) { 167 entryInfo.add(new TxnalEntry(lsn, keyValue, dataValue, 168 txnId)); 169 } else { 170 entryInfo.add(new NonTxnalEntry(lsn, keyValue, dataValue)); 171 } 172 } 173 } 174 175 return true; 176 } 177 } 178 | Popular Tags |