Decodes a checkpoint file name into a {@link UfsJournalFile}.

@param journal the UFS journal instance
@param filename the filename
@return the instance of {@link UfsJournalFile}, null if the file invalid
974034
@Nullable
  static UfsJournalFile decodeCheckpointFile(UfsJournal journal, String filename) {
    URI location = URIUtils.appendPathOrDie(journal.getCheckpointDir(), filename);
    try {
      String[] parts = filename.split("-");

      // There can be temporary files in logs directory. Skip them.
      if (parts.length != 2) {
        return null;
      }
      long start = Long.decode(parts[0]);
      long end = Long.decode(parts[1]);

      Preconditions.checkState(start == 0);
      return UfsJournalFile.createCheckpointFile(location, end);
    } catch (IllegalStateException e) {
      LOG.error("Illegal journal file {}.", location);
      throw e;
    } catch (NumberFormatException e) {
      // There can be temporary files (e.g. created for rename).
      return null;
    }
  }
683368
public void closeFile() throws JournalException {
        if (journalFile == null) {
            throw logAndGetException("Attempting to close a file "
                    + "when no file is open.");
        }

        try {
            writer.close();
            journalFile.close();
        } catch (IOException e) {
            throw logAndGetException("Problem closing the file '"
                    + journalFile.getName() + "'", e);
        }

        logger.debug("closing file: '" + journalFile.getName() + "'");
        journalFile = null;
    }
1280388
private void scanThroughFilesForNextJournalEntry() throws JournalException {
        try {
            while (true) {
                if (currentFile != null) {
                    // Check to see whether the current file contains any more
                    // entries. 
                    advancePastWhitespace(currentFile.getReader());

                    XMLEvent next = currentFile.getReader().peek();
                    if (isStartTagEvent(next, QNAME_TAG_JOURNAL_ENTRY)) {
                        // found it
                        return;
                    } else if (isEndTagEvent(next, QNAME_TAG_JOURNAL)) {
                        // need to get the next file
                        closeCurrentFile();
                    } else {
                        // problems
                        throw getNotNextMemberOrEndOfGroupException(QNAME_TAG_JOURNAL,
                                                                    QNAME_TAG_JOURNAL_ENTRY,
                                                                    next);
                    }
                }

                // If we don't have a file open, try to open one.
                if (currentFile == null) {
                    currentFile = openNextFile();
                }

                // If we still don't have a file open, we're finished.
                if (currentFile == null) {
                    // if there was no next file, we're done.
                    return;
                }

                // A new file needs to be advanced before using.
                advanceIntoFile(currentFile.getReader());
            }
        } catch (XMLStreamException e) {
            throw new JournalException(e);
        }
    }
1077612
public static String parseNonceFromDigestFilename(String filename) {
        if (filename == null || !filename.endsWith(".digest")) {
            throw new IllegalArgumentException("Bad digest filename: " + filename);
        }

        return parseNonceFromSnapshotFilename(filename);
    }
191376
synchronized void startLogSegment(final long segmentTxId,
      boolean writeHeaderTxn) throws IOException {
    LOG.info("Starting log segment at " + segmentTxId);
    if (segmentTxId < 0) {
      throw new IOException("Bad txid: " + segmentTxId);
    }
    if (state != State.BETWEEN_LOG_SEGMENTS) {
      throw new IOException("Bad state: " + state);
    }
    if (segmentTxId <= curSegmentTxId) {
      throw new IOException("Cannot start writing to log segment "
          + segmentTxId + " when previous log segment started at "
          + curSegmentTxId);
    }
    if (segmentTxId != txid + 1) {
      throw new IOException("Cannot start log segment at txid " + segmentTxId
          + " when next expected " + (txid + 1));
    }

    numTransactions = totalTimeTransactions = numTransactionsBatchedInSync = 0;

    // TODO no need to link this back to storage anymore!
    // See HDFS-2174.
    storage.attemptRestoreRemovedStorage();
    try {
      editLogStream = journalSet.startLogSegment(segmentTxId);
    } catch (IOException ex) {
      throw new IOException("Unable to start log segment " + segmentTxId
          + ": no journals successfully started.");

    }
    curSegmentTxId = segmentTxId;
    state = State.IN_SEGMENT;
    if (writeHeaderTxn) {
      logEdit(LogSegmentOp.getInstance(FSEditLogOpCodes.OP_START_LOG_SEGMENT));
      logSync();
    }
    
    // force update of journal and image metrics
    journalSet.updateJournalMetrics();
    // If it is configured, we want to schedule an automatic edits roll
    if (timeoutRollEdits > 0) {
      FSNamesystem fsn = this.journalSet.getImage().getFSNamesystem();
      if (fsn != null) {
        // In some test cases fsn is NULL in images. Simply skip the feature.
        AutomaticEditsRoller aer = fsn.automaticEditsRoller;
        if (aer != null) {
          aer.setNextRollTime(System.currentTimeMillis() + timeoutRollEdits);
        } else {
          LOG.warn("Automatic edits roll is enabled but the roller thread "
              + "is not enabled. Should only happen in unit tests.");
        }
      } else {
        LOG.warn("FSNamesystem is NULL in FSEditLog.");
      }
    }
  }
582311
public static File toFile(final URI filename) {
        if (filename == null) {
            return null;
        }
        final URI f = stripFragment(filename);
        if ("file".equals(f.getScheme()) && f.getPath() != null && f.isAbsolute()) {
            return new File(f);
        } else {
            return toFile(f.toString());
        }
    }
628764
public static String getFileExt(String fileName) {
        int dotPos = fileName.lastIndexOf('.');
        if (dotPos != -1 && dotPos != fileName.length() - 1) {
            return fileName.substring(dotPos);
        } else {
            return null;
        }
    }
609548
public IndexEntry findEntryByFileName(String fileName) {
    for (IndexEntry e: entries) {
      if (fileName.equals(e.fileName)) {
        return e;
      }
    }
    return null;
  }
1237642
private void checkForPotentialFilenameConflict() throws JournalException {
        File[] journalFiles =
                MultiFileJournalHelper
                        .getSortedArrayOfJournalFiles(journalDirectory,
                                                      filenamePrefix);
        if (journalFiles.length == 0) {
            return;
        }

        String newestFilename = journalFiles[journalFiles.length - 1].getName();
        String potentialFilename =
                JournalHelper.createTimestampedFilename(filenamePrefix,
                                                        new Date());
        if (newestFilename.compareTo(potentialFilename) > 0) {
            throw new JournalException("The name of one or more existing files in the journal "
                    + "directory (e.g. '"
                    + newestFilename
                    + "') may conflict with new Journal "
                    + "files. Has the system clock changed?");
        }
    }
666922
public static void writeJournalEntryCheckpoint(OutputStream output, JournalEntryIterable iterable)
      throws IOException, InterruptedException {
    output = new CheckpointOutputStream(output, CheckpointType.JOURNAL_ENTRY);
    Iterator<JournalEntry> it = iterable.getJournalEntryIterator();
    LOG.info("Write journal entry checkpoint");
    while (it.hasNext()) {
      if (Thread.interrupted()) {
        throw new InterruptedException();
      }
      it.next().writeDelimitedTo(output);
    }
    output.flush();
  }
801374
public static MutableInodeFile fromJournalEntry(InodeFileEntry entry) {
    // If journal entry has no mode set, set default mode for backwards-compatibility.
    MutableInodeFile ret = new MutableInodeFile(BlockId.getContainerId(entry.getId()))
        .setName(entry.getName())
        .setBlockIds(entry.getBlocksList())
        .setBlockSizeBytes(entry.getBlockSizeBytes())
        .setCacheable(entry.getCacheable())
        .setCompleted(entry.getCompleted())
        .setCreationTimeMs(entry.getCreationTimeMs())
        .setLastModificationTimeMs(entry.getLastModificationTimeMs(), true)
        .setLength(entry.getLength())
        .setParentId(entry.getParentId())
        .setPersistenceState(PersistenceState.valueOf(entry.getPersistenceState()))
        .setPinned(entry.getPinned())
        .setPersistJobId(entry.getPersistJobId())
        .setReplicationDurable(entry.getReplicationDurable())
        .setReplicationMax(entry.getReplicationMax())
        .setReplicationMin(entry.getReplicationMin())
        .setTempUfsPath(entry.getTempUfsPath())
        .setTtl(entry.getTtl())
        .setTtlAction((ProtobufUtils.fromProtobuf(entry.getTtlAction())))
        .setUfsFingerprint(entry.hasUfsFingerprint() ? entry.getUfsFingerprint() :
            Constants.INVALID_UFS_FINGERPRINT);
    if (entry.hasAcl()) {
      ret.mAcl = ProtoUtils.fromProto(entry.getAcl());
    } else {
      // Backward compatibility.
      AccessControlList acl = new AccessControlList();
      acl.setOwningUser(entry.getOwner());
      acl.setOwningGroup(entry.getGroup());
      short mode = entry.hasMode() ? (short) entry.getMode() : Constants.DEFAULT_FILE_SYSTEM_MODE;
      acl.setMode(mode);
      ret.mAcl = acl;
    }
    return ret;
  }
1302092
public void openFile(String repositoryHash, String filename)
            throws JournalException {
        if (journalFile != null) {
            throw logAndGetException("Attempting to open file '" + filename
                    + "' when file '" + journalFile.getName()
                    + "' has not been closed.");
        }

        try {
            journalFile = new TransportOutputFile(directory, filename);
            writer = journalFile.open();
        } catch (IOException e) {
            throw logAndGetException("Problem opening" + filename + "'", e);
        }

        currentRepositoryHash = repositoryHash;
        itemIndex = 0;
        logger.debug("opened file '" + filename + "', hash is '" + repositoryHash
                + "'");
    }
1167748
public void closeAndRename(File archiveDirectory) throws JournalException {
        try {
            xmlReader.close();
            fileReader.close();
            File archiveFile = new File(archiveDirectory, file.getName());

            /*
             * java.io.File.renameTo() has a known bug when working across
             * file-systems, see:
             * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756 So
             * instead of this call: file.renameTo(archiveFile); We use the
             * following line, and check for exception...
             */
            try {
                FileMovingUtil.move(file, archiveFile);
            } catch (IOException e) {
                throw new JournalException("Failed to rename file from '"
                        + file.getPath() + "' to '" + archiveFile.getPath()
                        + "'", e);
            }
        } catch (XMLStreamException e) {
            throw new JournalException(e);
        } catch (IOException e) {
            throw new JournalException(e);
        }
    }
708343
public static String getJournalReport(QJMStatus status) {
    StringBuilder sb = new StringBuilder();
    sb.append("<table border=1 cellpadding=1 cellspacing=0 title=\"Journals\">");
    sb.append("<thead><tr><td><b>JournalId</b></td><td><b>Statistics</b></td></tr></thead>");
    for (String journalId : status.getJournalIds()) {
      sb.append("<tr><td>" + journalId + "</td><td>");
      getHTMLTableForASingleJournal(status, journalId, sb);
      sb.append("</td></tr>");
    }
    sb.append("</table>");
    return sb.toString();
  }
988032
static UfsJournalFile createLogFile(URI location, long start, long end) {
    return new UfsJournalFile(location, start, end, false);
  }
25235
def parse_journal_file(journal_file):
    """"""
    counter = count()

    for block in read_next_block(journal_file):
        block = remove_nullchars(block)

        while len(block) > MIN_RECORD_SIZE:
            header = RECORD_HEADER.unpack_from(block)
            size = header[0]

            try:
                yield parse_record(header, block[:size])

                next(counter)
            except RuntimeError:
                yield CorruptedUsnRecord(next(counter))
            finally:
                block = remove_nullchars(block[size:])

        journal_file.seek(- len(block), 1)
1211956
public static String parseParametersForFilenamePrefix(Map<String, String> parameters) {
        return getOptionalStringParameter(parameters,
                                          PARAMETER_JOURNAL_FILENAME_PREFIX,
                                          DEFAULT_FILENAME_PREFIX);
    }