Class EditLogOutputStream
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.EditLogOutputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
EditLogFileOutputStream
A generic abstract class to support journaling of edits logs into
a persistent storage.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidabort()Close the stream without necessarily flushing any pending data.abstract voidclose()Close the journal.abstract voidcreate(int layoutVersion) Create and initialize underlying persistent edits log storage.voidflush()Flush data to persistent store.voidflush(boolean durable) protected abstract voidflushAndSync(boolean durable) Flush and sync all data that is ready to be flushsetReadyToFlush()into underlying persistent store.intlongGet the last txId journalled in the stream.protected longReturn number of calls toflushAndSync(boolean)voidsetCurrentLogVersion(int logVersion) abstract voidAll data that has been written to the stream so far will be flushed.booleanImplement 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 voidwrite(FSEditLogOp op) Write edits log operation to the stream.abstract voidwriteRaw(byte[] bytes, int offset, int length) Write raw data to an edit log.
-
Constructor Details
-
EditLogOutputStream
- 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
Write edits log operation to the stream.- Parameters:
op- operation- Throws:
IOException
-
writeRaw
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 fromlength- number of bytes to write- Throws:
IOException
-
create
Create and initialize underlying persistent edits log storage.- Parameters:
layoutVersion- The LayoutVersion of the journal- Throws:
IOException
-
close
Close the journal.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if the journal can't be closed, or if there are unflushed edits
-
abort
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
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
Flush and sync all data that is ready to be flushsetReadyToFlush()into underlying persistent store.- Parameters:
durable- if true, the edits should be made truly durable before returning- Throws:
IOException
-
flush
Flush data to persistent store. Collect sync metrics.- Throws:
IOException
-
flush
- 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 toflushAndSync(boolean) -
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
-