/** * Ensure that the current/ directory exists in all storage * directories */ void ensureCurrentDirExists() throws IOException { for (Iterator<StorageDirectory> it = storage.dirIterator(); it.hasNext();) { StorageDirectory sd = it.next(); File curDir = sd.getCurrentDir(); if (!curDir.exists() && !curDir.mkdirs()) { throw new IOException("Could not create directory " + curDir); } } }
/** * Find an edits file spanning the given transaction ID range. * If no such file exists, an exception is thrown. */ File findFinalizedEditsFile(long startTxId, long endTxId) throws IOException { File ret = new File(sd.getCurrentDir(), NNStorage.getFinalizedEditsFileName(startTxId, endTxId)); if (!ret.exists()) { throw new IOException( "No edits file for range " + startTxId + "-" + endTxId); } return ret; }
static File getStorageFile(StorageDirectory sd, NameNodeFile type, long imageTxId) { return new File(sd.getCurrentDir(), String.format("%s_%019d", type.getName(), imageTxId)); }
static File getInProgressEditsFile(StorageDirectory sd, long startTxId) { return new File(sd.getCurrentDir(), getInProgressEditsFileName(startTxId)); }
@Override synchronized public void selectInputStreams( Collection<EditLogInputStream> streams, long fromTxId, boolean inProgressOk, boolean onlyDurableTxns) throws IOException { List<EditLogFile> elfs = matchEditLogs(sd.getCurrentDir()); if (LOG.isDebugEnabled()) { LOG.debug(this + ": selecting input streams starting at " + fromTxId + (inProgressOk ? " (inProgress ok) " : " (excluding inProgress) ") + "from among " + elfs.size() + " candidate file(s)"); } addStreamsToCollectionFromFiles(elfs, streams, fromTxId, getLastReadableTxId(), inProgressOk); }
File getPaxosDir() { return new File(sd.getCurrentDir(), "paxos"); }
@Override public void purgeLogsOlderThan(long minTxIdToKeep) throws IOException { Iterator<StorageDirectory> iter = storage.dirIterator(); while (iter.hasNext()) { StorageDirectory dir = iter.next(); List<EditLogFile> editFiles = FileJournalManager.matchEditLogs( dir.getCurrentDir()); for (EditLogFile f : editFiles) { if (f.getLastTxId() < minTxIdToKeep) { purger.purgeLog(f); } } } }
File getCurrentDir() { return sd.getCurrentDir(); }
static File getImageFile(StorageDirectory sd, NameNodeFile nnf, long txid) { return new File(sd.getCurrentDir(), getNameNodeFileName(nnf, txid)); }
public EditLogFile getLogFile(long startTxId) throws IOException { return getLogFile(sd.getCurrentDir(), startTxId, true); }
File getFinalizedEditsFile(long startTxId, long endTxId) { return new File(sd.getCurrentDir(), String.format("%s_%019d-%019d", NNStorage.NameNodeFile.EDITS.getName(), startTxId, endTxId)); }
public EditLogFile getLogFile(long startTxId, boolean inProgressOk) throws IOException { return getLogFile(sd.getCurrentDir(), startTxId, inProgressOk); }
public List<EditLogFile> getLogFiles(long fromTxId) throws IOException { File currentDir = sd.getCurrentDir(); List<EditLogFile> allLogFiles = matchEditLogs(currentDir); List<EditLogFile> logFiles = Lists.newArrayList(); for (EditLogFile elf : allLogFiles) { if (fromTxId <= elf.getFirstTxId() || elf.containsTxId(fromTxId)) { logFiles.add(elf); } } Collections.sort(logFiles, EditLogFile.COMPARE_BY_START_TXID); return logFiles; }
@Override public void purgeLogsOlderThan(long minTxIdToKeep) throws IOException { LOG.info("Purging logs older than " + minTxIdToKeep); File[] files = FileUtil.listFiles(sd.getCurrentDir()); List<EditLogFile> editLogs = matchEditLogs(files, true); for (EditLogFile log : editLogs) { if (log.getFirstTxId() < minTxIdToKeep && log.getLastTxId() < minTxIdToKeep) { purger.purgeLog(log); } } }
/** * @param segmentTxId the first txid of the segment * @param epoch the epoch number of the writer which is coordinating * recovery * @return the temporary path in which an edits log should be stored * while it is being downloaded from a remote JournalNode */ File getSyncLogTemporaryFile(long segmentTxId, long epoch) { String name = NNStorage.getInProgressEditsFileName(segmentTxId) + ".epoch=" + epoch; return new File(sd.getCurrentDir(), name); }
/** * Get a storage file for one of the files that doesn't need a txid associated * (e.g version, seen_txid). */ static File getStorageFile(StorageDirectory sd, NameNodeFile type) { return new File(sd.getCurrentDir(), type.getName()); }
/** * Remove any log files and associated paxos files which are older than * the given txid. */ void purgeDataOlderThan(long minTxIdToKeep) throws IOException { purgeMatching(sd.getCurrentDir(), CURRENT_DIR_PURGE_REGEXES, minTxIdToKeep); purgeMatching(getPaxosDir(), PAXOS_DIR_PURGE_REGEXES, minTxIdToKeep); }
public static File getTemporaryEditsFile(StorageDirectory sd, long startTxId, long endTxId, long timestamp) { return new File(sd.getCurrentDir(), getTemporaryEditsFileName(startTxId, endTxId, timestamp)); }
/** * @return the path for an in-progress edits file starting at the given * transaction ID. This does not verify existence of the file. */ File getInProgressEditLog(long startTxId) { return new File(sd.getCurrentDir(), NNStorage.getInProgressEditsFileName(startTxId)); }
public static File getFinalizedEditsFile(StorageDirectory sd, long startTxId, long endTxId) { return new File(sd.getCurrentDir(), getFinalizedEditsFileName(startTxId, endTxId)); }