/** 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) ; } }
public static void print(Journal journal) { System.out.println("Size: "+journal.size()) ; Iterator<JournalEntry> iter = journal.entries() ; for ( ; ; ) { long posn0 = journal.position(); if ( ! iter.hasNext() ) break; JournalEntry e = iter.next() ; long posn1 = journal.position(); long size = posn1 - posn0; System.out.printf("Posn: (%d, %d) Len=%d reverse %d\n", posn0, posn1, size, (journal.size()-journal.position())) ; System.out.print(" "); System.out.println(JournalEntry.format(e)) ; } }
Iterator<JournalEntry> iter = journal.entries() ;
@Test public void journal_01() { assertFalse(journal.entries().hasNext()) ; }
@Test public void journal_01() { assertFalse(journal.entries().hasNext()) ; }
@Test public void journal_04() { JournalEntry entry1 = new JournalEntry(JournalEntryType.Object, testRef, bb1) ; JournalEntry entry2 = new JournalEntry(JournalEntryType.Object, testRef, bb3) ; long x1 = journal.writeJournal(entry1) ; long x2 = journal.writeJournal(entry2) ; Iterator<JournalEntry> iter = journal.entries() ; JournalEntry entry1a = iter.next(); JournalEntry entry2a = iter.next(); assertFalse(iter.hasNext()) ; }
@Test public void journal_04() { JournalEntry entry1 = new JournalEntry(JournalEntryType.Object, testRef, bb1) ; JournalEntry entry2 = new JournalEntry(JournalEntryType.Object, testRef, bb3) ; long x1 = journal.writeJournal(entry1) ; long x2 = journal.writeJournal(entry2) ; Iterator<JournalEntry> iter = journal.entries() ; JournalEntry entry1a = iter.next(); JournalEntry entry2a = iter.next(); assertFalse(iter.hasNext()) ; }