Class EditLogFileOutputStream
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.EditLogOutputStream
org.apache.hadoop.hdfs.server.namenode.EditLogFileOutputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
An implementation of the abstract class
EditLogOutputStream, which
stores edits in a local file.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEditLogFileOutputStream(org.apache.hadoop.conf.Configuration conf, File name, int size) Creates output buffers and file object. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Close the stream without necessarily flushing any pending data.voidclose()Close the journal.voidcreate(int layoutVersion) Create empty edits logs file.voidflushAndSync(boolean durable) Flush ready buffer to persistent store. currentBuffer is not flushed as it accumulates new log records while readyBuffer will be flushed and synced.booleanisOpen()voidvoidAll data that has been written to the stream so far will be flushed.static voidsetShouldSkipFsyncForTesting(boolean skip) For the purposes of unit tests, we don't need to actually write durably to disk.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.toString()voidwrite(FSEditLogOp op) Write edits log operation to the stream.static voidwriteHeader(int layoutVersion, DataOutputStream out) Write header information for this EditLogFileOutputStream to the provided DataOutputSream.voidwriteRaw(byte[] bytes, int offset, int length) Write a transaction to the stream.Methods inherited from class org.apache.hadoop.hdfs.server.namenode.EditLogOutputStream
flush, flush, generateReport, getCurrentLogVersion, getLastJournalledTxId, getNumSync, setCurrentLogVersion
-
Field Details
-
MIN_PREALLOCATION_LENGTH
public static final int MIN_PREALLOCATION_LENGTH- See Also:
-
-
Constructor Details
-
EditLogFileOutputStream
public EditLogFileOutputStream(org.apache.hadoop.conf.Configuration conf, File name, int size) throws IOException Creates output buffers and file object.- Parameters:
conf- Configuration objectname- File name to store edit logsize- Size of flush buffer- Throws:
IOException
-
-
Method Details
-
write
Description copied from class:EditLogOutputStreamWrite edits log operation to the stream.- Specified by:
writein classEditLogOutputStream- Parameters:
op- operation- Throws:
IOException
-
writeRaw
Write a transaction to the stream. The serialization format is:- the opcode (byte)
- the transaction id (long)
- the actual Writables for the transaction
- Specified by:
writeRawin classEditLogOutputStream- Parameters:
bytes- the bytes to write.offset- offset in the bytes to write fromlength- number of bytes to write- Throws:
IOException
-
create
Create empty edits logs file.- Specified by:
createin classEditLogOutputStream- Parameters:
layoutVersion- The LayoutVersion of the journal- Throws:
IOException
-
writeHeader
@VisibleForTesting public static void writeHeader(int layoutVersion, DataOutputStream out) throws IOException Write header information for this EditLogFileOutputStream to the provided DataOutputSream.- Parameters:
layoutVersion- the LayoutVersion of the EditLogout- the output stream to write the header to.- Throws:
IOException- in the event of error writing to the stream.
-
close
Description copied from class:EditLogOutputStreamClose the journal.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classEditLogOutputStream- Throws:
IOException- if the journal can't be closed, or if there are unflushed edits
-
abort
Description copied from class:EditLogOutputStreamClose the stream without necessarily flushing any pending data. This may be called after a previous write or close threw an exception.- Specified by:
abortin classEditLogOutputStream- 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.- Specified by:
setReadyToFlushin classEditLogOutputStream- Throws:
IOException
-
flushAndSync
Flush ready buffer to persistent store. currentBuffer is not flushed as it accumulates new log records while readyBuffer will be flushed and synced.- Specified by:
flushAndSyncin classEditLogOutputStream- Parameters:
durable- if true, the edits should be made truly durable before returning- Throws:
IOException
-
shouldForceSync
public boolean shouldForceSync()Description copied from class:EditLogOutputStreamImplement 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.- Overrides:
shouldForceSyncin classEditLogOutputStream- Returns:
- true if the number of buffered data exceeds the intial buffer size
-
toString
-
isOpen
public boolean isOpen()- Returns:
- true if this stream is currently open.
-
setFileChannelForTesting
-
getFileChannelForTesting
-
setShouldSkipFsyncForTesting
@VisibleForTesting public static void setShouldSkipFsyncForTesting(boolean skip) For the purposes of unit tests, we don't need to actually write durably to disk. So, we can skip the fsync() calls for a speed improvement.- Parameters:
skip- true if fsync should not be called
-