// FEATURE: 300792 public LogRecord getNext(LogRecord lr) throws InvalidLogBufferException, LogException { if (lr == null || lr.buffer == null) throw new IllegalArgumentException(); LogBuffer buffer = lr.buffer; // get next record lr.get(buffer); if (lr.isEOB()) { long bsn = buffer.bsn; // so we can test for wraparound try { lfmgr.read(buffer, buffer.bsn + 1); } catch (IOException e) { LogFile lf = lr.buffer.lf; String msg = "Error reading " + lf.file + " @ position [" + lf.position + "]"; throw new LogException(msg, e); } if (buffer.bsn == -1 || buffer.bsn < bsn) // BUG 304982 { lr.type = LogRecordType.END_OF_LOG; return lr; } lr.get(buffer); } return lr; }
// FEATURE: 300792 public LogRecord get(LogRecord lr, long mark) throws InvalidLogKeyException, LogConfigurationException, LogException, InvalidLogBufferException { /* this code is similar to LogBufferManager.replay() -- potential for refactor */ int bsn = bmgr.bsnFromMark(mark); if (mark < 0 || (bsn == 0 && mark != 0)) throw new InvalidLogKeyException(Long.toHexString(mark)); if (lr == null) lr = new LogRecord((config.getBufferSize() * 1024) / 4); // default to 1/4 buffer size // allocate a LogBuffer that we can use to read the journal try { if (lr.buffer == null) lr.buffer = bmgr.getLogBuffer(-1); } catch (ClassNotFoundException e) { throw new LogConfigurationException(e); } LogBuffer buffer = lr.buffer; // read block containing requested mark try { bmgr.forceCurrentBuffer(); lfmgr.read(buffer, bsn); } catch (IOException e) { LogFile lf = buffer.lf; String msg = "Error reading " + lf.file + " @ position [" + lf.position + "]"; throw new LogException(msg, e); } if (buffer.bsn == -1) { lr.type = LogRecordType.END_OF_LOG; return lr; } // verify we have the desired block // if requested mark == 0 then we start with the oldest block available int markBSN = (mark == 0) ? buffer.bsn : bmgr.bsnFromMark(mark); if (markBSN != buffer.bsn) { InvalidLogBufferException lbe = new InvalidLogBufferException( "block read [" + buffer.bsn + "] not block requested: " + markBSN); throw lbe; } /* * position buffer to requested mark. * * Although the mark contains a buffer offset, we search forward * through the buffer to guarantee that we have the start * of a record. This protects against using marks that were * not generated by the current Logger. */ lr.get(buffer); // get first record in buffer if (mark > 0 && mark > bmgr.markFromBsn(markBSN, 0)) { while (lr.key < mark) { lr.get(buffer); } if (lr.key != mark) { String msg = "The requested mark [" + Long.toHexString(mark) + "] was not found in the log."; // BUG 300733 following line changed to throw an exception throw new InvalidLogKeyException(msg); } } return lr; }