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.log; 9 10 import java.nio.ByteBuffer; 11 12 import com.sleepycat.je.DatabaseException; 13 import com.sleepycat.je.dbi.EnvironmentImpl; 14 15 /** 16 * CheckpointFileReader searches for root and checkpoint entries. 17 */ 18 public class CheckpointFileReader extends FileReader { 19 /* Status about the last entry. */ 20 private boolean isDbTree; 21 private boolean isCheckpointEnd; 22 private boolean isCheckpointStart; 23 24 /** 25 * Create this reader to start at a given LSN. 26 */ CheckpointFileReader(EnvironmentImpl env, int readBufferSize, boolean forward, long startLsn, long finishLsn, long endOfFileLsn)27 public CheckpointFileReader(EnvironmentImpl env, 28 int readBufferSize, 29 boolean forward, 30 long startLsn, 31 long finishLsn, 32 long endOfFileLsn) 33 throws DatabaseException { 34 35 super(env, readBufferSize, forward, startLsn, 36 null, endOfFileLsn, finishLsn); 37 } 38 39 /** 40 * @return true if this is a targeted entry. 41 */ 42 @Override isTargetEntry()43 protected boolean isTargetEntry() { 44 byte logEntryTypeNumber = currentEntryHeader.getType(); 45 boolean isTarget = false; 46 isDbTree = false; 47 isCheckpointEnd = false; 48 isCheckpointStart = false; 49 if (LogEntryType.LOG_CKPT_END.equalsType(logEntryTypeNumber)) { 50 isTarget = true; 51 isCheckpointEnd = true; 52 } else if (LogEntryType.LOG_CKPT_START.equalsType 53 (logEntryTypeNumber)) { 54 isTarget = true; 55 isCheckpointStart = true; 56 } else if (LogEntryType.LOG_DBTREE.equalsType 57 (logEntryTypeNumber)) { 58 isTarget = true; 59 isDbTree = true; 60 } 61 return isTarget; 62 } 63 64 /** 65 * This reader instantiates the first object of a given log entry 66 */ 67 @Override processEntry(ByteBuffer entryBuffer)68 protected boolean processEntry(ByteBuffer entryBuffer) { 69 /* Don't need to read the entry, since we just use the LSN. */ 70 return true; 71 } 72 73 /** 74 * @return true if last entry was a DbTree entry. 75 */ isDbTree()76 public boolean isDbTree() { 77 return isDbTree; 78 } 79 80 /** 81 * @return true if last entry was a checkpoint end entry. 82 */ isCheckpointEnd()83 public boolean isCheckpointEnd() { 84 return isCheckpointEnd; 85 } 86 87 /** 88 * @return true if last entry was a checkpoint start entry. 89 */ isCheckpointStart()90 public boolean isCheckpointStart() { 91 return isCheckpointStart; 92 } 93 } 94