Encodes a log location under the log directory.

@param journal the UFS journal instance
@param start the start sequence number (inclusive)
@param end the end sequence number (exclusive)
@return the location
170227
static URI encodeLogFileLocation(UfsJournal journal, long start, long end) {
    String filename = String.format("0x%x-0x%x", start, end);
    URI location = URIUtils.appendPathOrDie(journal.getLogDir(), filename);
    return location;
  }
1215495
public int getLineNumber(Location start) {
        LineNumberTableAttr table = mOldLineNumberTable;
        if (table == null) {
            table = mLineNumberTable;
        }

        if (table == null || start.getLocation() < 0) {
            return -1;
        } else {
            return table.getLineNumber(start);
        }
    }
90343
public File closeAndRecycle() throws JournalException
    {
    	File recycledFile = new File(file.getAbsolutePath()+RECYCLED_SUFFIX);
    	if (!file.renameTo(recycledFile))
    		throw new JournalException("Cannot rename journal file "+file.getAbsolutePath()+" to "+recycledFile.getAbsolutePath());
    	
    	try
    	{
    		fillWithZeroes(recycledFile.length(), writeBuffer.length);
    	}
        catch (IOException e)
        {
            throw new JournalException("Cannot clear journal file : "+recycledFile.getAbsolutePath(),e);
        }
        
        sync();
        close();
        
        return recycledFile;
    }
267544
def _get_journal():
    '''
    
    '''
    if 'systemd.journald' in __context__:
        return __context__['systemd.journald']
    __context__['systemd.journald'] = systemd.journal.Reader()
    # get to the end of the journal
    __context__['systemd.journald'].seek_tail()
    __context__['systemd.journald'].get_previous()
    return __context__['systemd.journald']
186865
private void advanceIntoFile() throws XMLStreamException, JournalException {
        XMLEvent event = reader.nextEvent();
        if (!event.isStartDocument()) {
            throw new JournalException("Expecting XML document header, but event was '"
                    + event + "'");
        }

        event = reader.nextTag();
        if (!isStartTagEvent(event, QNAME_TAG_JOURNAL)) {
            throw new JournalException("Expecting FedoraJournal start tag, but event was '"
                    + event + "'");
        }

        String hash =
                getOptionalAttributeValue(event.asStartElement(),
                                          QNAME_ATTR_REPOSITORY_HASH);
        checkRepositoryHash(hash);
    }
398326
@Override
    public Appendable append(CharSequence csq, int start, int end) throws IOException {
        this.loggingWriter.append(csq, start, end);
        return this;
    }
1202333
public synchronized void startLogSegment(RequestInfo reqInfo, long txid)
      throws IOException {
    assert fjm != null;
    checkJournalStorageFormatted();
    checkRequest(reqInfo);
    
    if (curSegment != null) {
      LOG.warn("Client is requesting a new log segment " + txid + 
          " though we are already writing " + curSegment + ". " +
          "Aborting the current segment in order to begin the new one.");
      // The writer may have lost a connection to us and is now
      // re-connecting after the connection came back.
      // We should abort our own old segment.
      abortCurSegment();
    }

    // Paranoid sanity check: we should never overwrite a finalized log file.
    // Additionally, if it's in-progress, it should have at most 1 transaction.
    // This can happen if the writer crashes exactly at the start of a segment.
    EditLogFile existing = fjm.getLogFile(txid);
    if (existing != null) {
      if (!existing.isInProgress()) {
        throw new IllegalStateException("Already have a finalized segment " +
            existing + " beginning at " + txid);
      }
      
      // If it's in-progress, it should only contain one transaction,
      // because the "startLogSegment" transaction is written alone at the
      // start of each segment. 
      existing.validateLog();
      if (existing.getLastTxId() != existing.getFirstTxId()) {
        throw new IllegalStateException("The log file " +
            existing + " seems to contain valid transactions");
      }
    }
    
    long curLastWriterEpoch = lastWriterEpoch.get();
    if (curLastWriterEpoch != reqInfo.getEpoch()) {
      LOG.info("Updating lastWriterEpoch from " + curLastWriterEpoch +
          " to " + reqInfo.getEpoch() + " for client " +
          Server.getRemoteIp());
      lastWriterEpoch.set(reqInfo.getEpoch());
      metrics.lastWriterEpoch.set(reqInfo.getEpoch());
    }

    // The fact that we are starting a segment at this txid indicates
    // that any previous recovery for this same segment was aborted.
    // Otherwise, no writer would have started writing. So, we can
    // remove the record of the older segment here.
    purgePaxosDecision(txid);
    
    curSegment = fjm.startLogSegment(txid);
    curSegmentTxId = txid;
    nextTxId = txid;
    // the layout version has only been written
    // plus OP_INVALID
    currentSegmentWrittenBytes = 5L;
    
    // inform the syncer service that we might have some work to do
    if (journalNode != null) {
      journalNode.addSyncTask(this, curSegmentTxId);
    }
  }
485029
public String getSequence(Long beginPosition, Long endPosition)
	{
		byte[] sequenceByte = getSequenceByte(beginPosition, endPosition);
		if (sequenceByte != null)
			return new String(sequenceByte);
		return null;
	}
1187546
protected void writeDocumentTrailer(XMLEventWriter writer)
            throws JournalException {
        try {
            putEndDocument(writer);
        } catch (XMLStreamException e) {
            throw new JournalException(e);
        }
    }
1104743
private void compactByAge() {
    if (maxLogAge != null) {
      long currentTime = System.currentTimeMillis();
      JournalSegment<LogEntry> compactSegment = null;
      Long compactIndex = null;
      for (JournalSegment<LogEntry> segment : journal.segments()) {
        if (currentTime - segment.descriptor().updated() > maxLogAge.toMillis()) {
          log.debug("Found expired journal segment {}", segment.file().file());
          compactSegment = segment;
        } else if (compactSegment != null) {
          compactIndex = segment.index();
          break;
        }
      }

      if (compactIndex != null) {
        log.info("Compacting journal by age up to {}", compactIndex);
        journal.compact(compactIndex);
      }
    }
  }
397448
File syncLog(RequestInfo reqInfo, final SegmentStateProto segment,
      final URL url) throws IOException {
    long startTxId = segment.getStartTxId();
    long epoch = reqInfo.getEpoch();
    return syncLog(epoch, segment.getStartTxId(), url, segment.toString(),
        journalStorage.getSyncLogTemporaryFile(startTxId, epoch));
  }
413115
public String getFragmentByLines(int startLine, int endLine) {
    Preconditions.checkArgument(startLine <= endLine);
    return Joiner.on("\n").join(getLines(startLine, endLine)) + "\n";
  }
1016666
public static UfsJournalSnapshot getSnapshot(UfsJournal journal) throws IOException {
    // Checkpoints.
    List<UfsJournalFile> checkpoints = new ArrayList<>();
    UfsStatus[] statuses = journal.getUfs().listStatus(journal.getCheckpointDir().toString());
    if (statuses != null) {
      for (UfsStatus status : statuses) {
        UfsJournalFile file = UfsJournalFile.decodeCheckpointFile(journal, status.getName());
        if (file != null) {
          checkpoints.add(file);
        }
      }
      Collections.sort(checkpoints);
    }

    List<UfsJournalFile> logs = new ArrayList<>();
    statuses = journal.getUfs().listStatus(journal.getLogDir().toString());
    if (statuses != null) {
      for (UfsStatus status : statuses) {
        UfsJournalFile file = UfsJournalFile.decodeLogFile(journal, status.getName());
        if (file != null) {
          logs.add(file);
        }
      }
      Collections.sort(logs);
    }

    List<UfsJournalFile> tmpCheckpoints = new ArrayList<>();
    statuses = journal.getUfs().listStatus(journal.getTmpDir().toString());
    if (statuses != null) {
      for (UfsStatus status : statuses) {
        tmpCheckpoints.add(UfsJournalFile.decodeTemporaryCheckpointFile(journal, status.getName()));
      }
    }

    return new UfsJournalSnapshot(checkpoints, logs, tmpCheckpoints);
  }
244371
public static JournalRecoveryLog getInstance(Map<String, String> parameters,
                                                 String role,
                                                 ServerInterface server)
            throws ModuleInitializationException {

        try {
            Object recoveryLog =
                    JournalHelper
                            .createInstanceAccordingToParameter(PARAMETER_JOURNAL_RECOVERY_LOG_CLASSNAME,
                                                                new Class[] {
                                                                        Map.class,
                                                                        String.class,
                                                                        ServerInterface.class},
                                                                new Object[] {
                                                                        parameters,
                                                                        role,
                                                                        server},
                                                                parameters);
            logger.info("JournalRecoveryLog is " + recoveryLog.toString());
            return (JournalRecoveryLog) recoveryLog;
        } catch (JournalException e) {
            throw new ModuleInitializationException("Can't create JournalRecoveryLog",
                                                    role,
                                                    e);
        }
    }
1065158
public synchronized void formatJournal() throws IOException {
    if (mDeployMode == DeployMode.EMBEDDED) {
      for (Master master : mMasters) {
        File journalDir = new File(master.getConf().get(PropertyKey.MASTER_JOURNAL_FOLDER));
        FileUtils.deleteDirectory(journalDir);
        journalDir.mkdirs();
      }
      return;
    }
    try (Closeable c = new ConfigurationRule(mProperties, ServerConfiguration.global())
        .toResource()) {
      Format.format(Format.Mode.MASTER, ServerConfiguration.global());
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
779138
private void writeStartSequence(IXADataRecorder dataRecorder)
			throws IOException, InterruptedException {

		LogRecordWriter writer = new LogRecordWriter();
		writer.writeLong(dataRecorder.getXADataRecorderId());
		dataRecorder.writeRollbackData(writer.toByteArray());
	}
469348
@Override
    public void writeJournalEntry(CreatorJournalEntry journalEntry)
            throws JournalException {
        if (open) {
            try {
                synchronized (JournalWriter.SYNCHRONIZER) {
                    XMLEventWriter xmlWriter = currentJournal.getXmlWriter();
                    super.writeJournalEntry(journalEntry, xmlWriter);
                    xmlWriter.flush();
                    currentJournal.closeIfAppropriate();
                }
            } catch (XMLStreamException e) {
                throw new JournalException(e);
            }
        }
    }