/** Scan to a commit entry, starting at a given position in the journal. * Return address of entry after commit if found, else -1. */ private static long scanForCommit(Journal jrnl, long startPosn) { Iterator<JournalEntry> iter = jrnl.entries(startPosn) ; try { for ( ; iter.hasNext() ; ) { JournalEntry e = iter.next() ; if ( e.getType() == JournalEntryType.Commit ) return e.getEndPosition() ; } return -1 ; } finally { Iter.close(iter) ; } }
/** Recover one transaction from the start position given. * Scan to see if there is a commit; if found, play the * journal from the start point to the commit. * Return true is a commit was found. * Leave journal positioned just after commit or at end if none found. */ private static void recoverSegment(Journal jrnl, long startPosn, long endPosn, StorageConfig sConf) { //System.out.printf("Segment: %d %d\n", startPosn, endPosn); Iterator<JournalEntry> iter = jrnl.entries(startPosn) ; iter = jrnl.entries(startPosn) ; try { for ( ; iter.hasNext() ; ) { JournalEntry e = iter.next() ; if ( e.getType() == JournalEntryType.Commit ) { if ( e.getEndPosition() != endPosn ) log.warn(format("Inconsistent: end at %d; expected %d", e.getEndPosition(), endPosn)) ; return ; } replay(e, sConf) ; } } finally { Iter.close(iter) ; } }
static public String format(JournalEntry entry) { return format(entry.getType(), entry.getByteBuffer(), entry.getBlock(), entry.getFileRef()) ; }
synchronized public long writeJournal(JournalEntry entry) { long posn = write(entry.getType(), entry.getFileRef(), entry.getBlock()) ; if ( entry.getPosition() < 0 ) { entry.setPosition(posn) ; entry.setEndPosition(position) ; } return posn ; }
private static boolean equal(JournalEntry entry1, JournalEntry entry2) { if ( entry1.getType() != entry2.getType()) return false ; if ( ! entry1.getFileRef().equals(entry2.getFileRef()) ) return false ; if ( entry1.getByteBuffer() == null && entry2.getByteBuffer() != null ) return false ; if ( entry1.getByteBuffer() != null && entry2.getByteBuffer() == null ) return false ; if ( entry1.getBlock() == null && entry2.getBlock() != null ) return false ; if ( entry1.getBlock() != null && entry2.getBlock() == null ) return false ; if ( entry1.getBlock() != null ) return sameValue(entry1.getBlock(), entry2.getBlock()) ; else return sameValue(entry1.getByteBuffer(), entry2.getByteBuffer()) ; }
private static boolean equal(JournalEntry entry1, JournalEntry entry2) { if ( entry1.getType() != entry2.getType()) return false ; if ( ! entry1.getFileRef().equals(entry2.getFileRef()) ) return false ; if ( entry1.getByteBuffer() == null && entry2.getByteBuffer() != null ) return false ; if ( entry1.getByteBuffer() != null && entry2.getByteBuffer() == null ) return false ; if ( entry1.getBlock() == null && entry2.getBlock() != null ) return false ; if ( entry1.getBlock() != null && entry2.getBlock() == null ) return false ; if ( entry1.getBlock() != null ) return sameValue(entry1.getBlock(), entry2.getBlock()) ; else return sameValue(entry1.getByteBuffer(), entry2.getByteBuffer()) ; }