EditLogOutputStream (Apache Hadoop HDFS 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.namenode, class: EditLogOutputStream

Package org.apache.hadoop.hdfs.server.namenode

# Class EditLogOutputStream

java.lang.Object
org.apache.hadoop.hdfs.server.namenode.EditLogOutputStream

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

Direct Known Subclasses:
  `EditLogFileOutputStream`

@Private @Evolving public abstract class EditLogOutputStream extends Object implements Closeable
A generic abstract class to support journaling of edits logs into a persistent storage.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `EditLogOutputStream()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract void`
  `abort()`
  Close the stream without necessarily flushing any pending data.
  `abstract void`
  `close()`
  Close the journal.
  `abstract void`
  `create(int layoutVersion)`
  Create and initialize underlying persistent edits log storage.
  `void`
  `flush()`
  Flush data to persistent store.
  `void`
  `flush(boolean durable)`
  `protected abstract void`
  `flushAndSync(boolean durable)`
  Flush and sync all data that is ready to be flush `setReadyToFlush()` into underlying persistent store.
  `String`
  `generateReport()`
  `int`
  `getCurrentLogVersion()`
  `long`
  `getLastJournalledTxId()`
  Get the last txId journalled in the stream.
  `protected long`
  `getNumSync()`
  Return number of calls to `flushAndSync(boolean)`
  `void`
  `setCurrentLogVersion(int logVersion)`
  `abstract void`
  `setReadyToFlush()`
  All data that has been written to the stream so far will be flushed.
  `boolean`
  `shouldForceSync()`
  Implement the policy when to automatically sync the buffered edits log The buffered edits can be flushed when the buffer becomes full or a certain period of time is elapsed.
  `abstract void`
  `write(FSEditLogOp op)`
  Write edits log operation to the stream.
  `abstract void`
  `writeRaw(byte[] bytes, int offset, int length)`
  Write raw data to an edit log.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### EditLogOutputStream

    public EditLogOutputStream() throws IOException
    Throws:
      `IOException`

- ## Method Details

  - ### getLastJournalledTxId

    public long getLastJournalledTxId()
    Get the last txId journalled in the stream. The txId is recorded when FSEditLogOp is written to the stream. The default implementation is dummy. JournalSet tracks the txId uniformly for all underlying streams.

  - ### write

    public abstract void write(FSEditLogOp op) throws IOException
    Write edits log operation to the stream.
    Parameters:
      `op` - operation
    Throws:
      `IOException`

  - ### writeRaw

    public abstract void writeRaw(byte[] bytes, int offset, int length) throws IOException
    Write raw data to an edit log. This data should already have the transaction ID, checksum, etc included. It is for use within the BackupNode when replicating edits from the NameNode.
    Parameters:
      `bytes` - the bytes to write.
      `offset` - offset in the bytes to write from
      `length` - number of bytes to write
    Throws:
      `IOException`

  - ### create

    public abstract void create(int layoutVersion) throws IOException
    Create and initialize underlying persistent edits log storage.
    Parameters:
      `layoutVersion` - The LayoutVersion of the journal
    Throws:
      `IOException`

  - ### close

    public abstract void close() throws IOException
    Close the journal.
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Throws:
      `IOException` - if the journal can't be closed, or if there are unflushed edits

  - ### abort

    public abstract void abort() throws IOException
    Close the stream without necessarily flushing any pending data. This may be called after a previous write or close threw an exception.
    Throws:
      `IOException`

  - ### setReadyToFlush

    public abstract void setReadyToFlush() throws IOException
    All data that has been written to the stream so far will be flushed. New data can be still written to the stream while flushing is performed.
    Throws:
      `IOException`

  - ### flushAndSync

    protected abstract void flushAndSync(boolean durable) throws IOException
    Flush and sync all data that is ready to be flush `setReadyToFlush()` into underlying persistent store.
    Parameters:
      `durable` - if true, the edits should be made truly durable before returning
    Throws:
      `IOException`

  - ### flush

    public void flush() throws IOException
    Flush data to persistent store. Collect sync metrics.
    Throws:
      `IOException`

  - ### flush

    public void flush(boolean durable) throws IOException
    Throws:
      `IOException`

  - ### shouldForceSync

    public boolean shouldForceSync()
    Implement the policy when to automatically sync the buffered edits log The buffered edits can be flushed when the buffer becomes full or a certain period of time is elapsed.
    Returns:
      true if the buffered data should be automatically synced to disk

  - ### getNumSync

    protected long getNumSync()
    Return number of calls to `flushAndSync(boolean)`

  - ### generateReport

    public String generateReport()
    Returns:
      a short text snippet suitable for describing the current status of the stream

  - ### getCurrentLogVersion

    public int getCurrentLogVersion()
    Returns:
      The version of the current edit log

  - ### setCurrentLogVersion

    public void setCurrentLogVersion(int logVersion)
    Parameters:
      `logVersion` - The version of the current edit log