1 /* 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002, 2014 Oracle and/or its affiliates. All rights reserved. 5 * 6 */ 7 8 package com.sleepycat.je.txn; 9 10 import java.nio.ByteBuffer; 11 12 import com.sleepycat.je.log.LogUtils; 13 import com.sleepycat.je.log.Loggable; 14 import com.sleepycat.je.utilint.DbLsn; 15 import com.sleepycat.je.utilint.Timestamp; 16 17 /** 18 * This class indicates the end of a partial rollback at syncup. This is a 19 * non-replicated entry. Although this is a replication class, it resides in 20 * the utilint package because it is referenced in LogEntryType.java and is 21 * used in a general way at recovery. 22 */ 23 public class RollbackEnd implements Loggable { 24 25 private long matchpointLSN; 26 private long rollbackStartLSN; 27 /* For debugging in the field */ 28 private Timestamp time; 29 RollbackEnd(long matchpointLSN, long rollbackStartLSN)30 public RollbackEnd(long matchpointLSN, long rollbackStartLSN) { 31 this.matchpointLSN = matchpointLSN; 32 this.rollbackStartLSN = rollbackStartLSN; 33 time = new Timestamp(System.currentTimeMillis()); 34 } 35 36 /** 37 * For constructing from the log. 38 */ RollbackEnd()39 public RollbackEnd() { 40 } 41 getMatchpoint()42 public long getMatchpoint() { 43 return matchpointLSN; 44 } 45 getRollbackStart()46 public long getRollbackStart() { 47 return rollbackStartLSN; 48 } 49 50 /** 51 * @see Loggable#getLogSize 52 */ getLogSize()53 public int getLogSize() { 54 return LogUtils.getPackedLongLogSize(matchpointLSN) + 55 LogUtils.getPackedLongLogSize(rollbackStartLSN) + 56 LogUtils.getTimestampLogSize(time); 57 58 } 59 60 /** 61 * @see Loggable#writeToLog 62 */ writeToLog(ByteBuffer buffer)63 public void writeToLog(ByteBuffer buffer) { 64 LogUtils.writePackedLong(buffer, matchpointLSN); 65 LogUtils.writePackedLong(buffer, rollbackStartLSN); 66 LogUtils.writeTimestamp(buffer, time); 67 } 68 69 /** 70 * @see Loggable#readFromLog 71 */ 72 @SuppressWarnings("unused") readFromLog(ByteBuffer buffer, int entryVersion)73 public void readFromLog(ByteBuffer buffer, int entryVersion) { 74 matchpointLSN = LogUtils.readPackedLong(buffer); 75 rollbackStartLSN = LogUtils.readPackedLong(buffer); 76 /* the timestamp is packed -- double negative, unpacked == false */ 77 time = LogUtils.readTimestamp(buffer, false /* unpacked. */); 78 } 79 80 /** 81 * @see Loggable#dumpLog 82 */ 83 @SuppressWarnings("unused") dumpLog(StringBuilder sb, boolean verbose)84 public void dumpLog(StringBuilder sb, boolean verbose) { 85 sb.append(" matchpointLSN="); 86 sb.append(DbLsn.getNoFormatString(matchpointLSN)); 87 sb.append(" rollbackStartLSN="); 88 sb.append(DbLsn.getNoFormatString(rollbackStartLSN)); 89 sb.append(" time=").append(time); 90 } 91 92 /** 93 * @see Loggable#getTransactionId 94 */ getTransactionId()95 public long getTransactionId() { 96 return 0; 97 } 98 99 /** 100 * @see Loggable#logicalEquals 101 */ logicalEquals(Loggable other)102 public boolean logicalEquals(Loggable other) { 103 104 if (!(other instanceof RollbackEnd)) { 105 return false; 106 } 107 108 RollbackEnd otherRE = (RollbackEnd) other; 109 return (rollbackStartLSN == otherRE.rollbackStartLSN) && 110 (matchpointLSN == otherRE.matchpointLSN) && 111 (time.equals(otherRE.time)); 112 } 113 114 @Override toString()115 public String toString() { 116 StringBuilder sb = new StringBuilder(); 117 dumpLog(sb, true); 118 return sb.toString(); 119 } 120 } 121