private void setUnderStoreStream(long pos) throws IOException { if (mUnderStoreStream != null) { mUnderStoreStream.close(); } UnderFileSystem ufs = UnderFileSystem.get(mUfsPath, ClientContext.getConf()); mUnderStoreStream = ufs.open(mUfsPath); mPos = 0; if (pos != skip(pos)) { throw new IOException("Failed to skip: " + pos); } } }
/** * Gets the {@link JournalInputStream} for the journal checkpoint file. This must be called before * calling {@link #getNextInputStream()}. * * @return the {@link JournalInputStream} for the journal checkpoint file * @throws IOException if the checkpoint file cannot be read, or was already read */ public JournalInputStream getCheckpointInputStream() throws IOException { if (mCheckpointRead) { throw new IOException("Checkpoint file has already been read."); } mCheckpointOpenedTime = getCheckpointLastModifiedTimeMs(); LOG.info("Opening journal checkpoint file: " + mCheckpointPath); JournalInputStream jis = mJournal.getJournalFormatter().deserialize(mUfs.open(mCheckpointPath)); mCheckpointRead = true; return jis; }
/** * @return the input stream for the next completed log file. Will return null if the next * completed log file does not exist yet. * @throws IOException */ public JournalInputStream getNextInputStream() throws IOException { if (!mCheckpointRead) { throw new IOException("Must read the checkpoint file before getting input stream."); } if (getCheckpointLastModifiedTimeMs() != mCheckpointOpenedTime) { throw new IOException("Checkpoint file has been updated. This reader is no longer valid."); } String currentLogPath = mJournal.getCompletedLogFilePath(mCurrentLogNumber); if (!mUfs.exists(currentLogPath)) { LOG.debug("Journal log file: " + currentLogPath + " does not exist yet."); return null; } // Open input stream from the current log file. LOG.info("Opening journal log file: " + currentLogPath); JournalInputStream jis = mJournal.getJournalFormatter().deserialize(mUfs.open(currentLogPath)); // Increment the log file number. mCurrentLogNumber ++; return jis; }