Class FileJournalManager
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.FileJournalManager
- All Implemented Interfaces:
Closeable,AutoCloseable,Storage.FormatConfirmable,JournalManager
Journal manager for the common case of edits files being written
to a storage directory.
Note: this class is not thread-safe and should be externally
synchronized.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRecord of an edit log that has been located and had its filename parsed.Nested classes/interfaces inherited from interface org.apache.hadoop.hdfs.server.namenode.JournalManager
JournalManager.CorruptionException -
Constructor Summary
ConstructorsConstructorDescriptionFileJournalManager(org.apache.hadoop.conf.Configuration conf, Storage.StorageDirectory sd, StorageErrorReporter errorReporter) -
Method Summary
Modifier and TypeMethodDescriptionbooleancanRollBack(StorageInfo storage, StorageInfo prevStorage, int targetLayoutVersion) Return true if this JM can roll back to the previous storage state, false otherwise.voidclose()Close the journal manager, freeing any resources it may hold.voiddiscardSegments(long startTxid) Discard the segments whose first txid is >= the given txid.voidFinalize the upgrade.voidPerform any steps that must succeed across all JournalManagers involved in an upgrade before proceeding onto the actual upgrade stage.voidPerform the rollback to the previous FS state.voidThis method assumes that the fields of theStorageobject have already been updated to the appropriate new values for the upgrade.voidfinalizeLogSegment(long firstTxId, long lastTxId) Mark the log segment that spans from firstTxId to lastTxId as finalized and complete.voidformat(NamespaceInfo ns, boolean force) Format the underlying storage, removing any previously stored data.longlonggetLogFile(long startTxId) getLogFile(long startTxId, boolean inProgressOk) getLogFile(File dir, long startTxId) getLogFile(File dir, long startTxId, boolean inProgressOk) getLogFiles(long fromTxId) getRemoteEditLogs(long firstTxId, boolean inProgressOk) Find all editlog segments starting at or above the given txid.booleanstatic List<FileJournalManager.EditLogFile>matchEditLogs(File logDir) returns matching edit logs via the log directory.voidpurgeLogsOlderThan(long minTxIdToKeep) Purges the unnecessary edits and edits_inprogress files.voidRecover segments which have not been finalized.voidselectInputStreams(Collection<EditLogInputStream> streams, long fromTxnId, boolean inProgressOk) voidselectInputStreams(Collection<EditLogInputStream> streams, long fromTxId, boolean inProgressOk, boolean onlyDurableTxns) voidsetLastReadableTxId(long id) voidsetOutputBufferCapacity(int size) Set the amount of memory that this stream should use to buffer editsstartLogSegment(long txid, int layoutVersion) Begin writing to a new segment of the log stream, which starts at the given transaction ID.toString()
-
Constructor Details
-
FileJournalManager
public FileJournalManager(org.apache.hadoop.conf.Configuration conf, Storage.StorageDirectory sd, StorageErrorReporter errorReporter)
-
-
Method Details
-
close
Description copied from interface:JournalManagerClose the journal manager, freeing any resources it may hold.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceJournalManager- Throws:
IOException
-
format
Description copied from interface:JournalManagerFormat the underlying storage, removing any previously stored data.- Specified by:
formatin interfaceJournalManager- Throws:
IOException
-
hasSomeData
public boolean hasSomeData()- Specified by:
hasSomeDatain interfaceStorage.FormatConfirmable- Returns:
- true if the storage seems to have some valid data in it, and the user should be required to confirm the format. Otherwise, false.
-
startLogSegment
Description copied from interface:JournalManagerBegin writing to a new segment of the log stream, which starts at the given transaction ID.- Specified by:
startLogSegmentin interfaceJournalManager- Throws:
IOException
-
finalizeLogSegment
Description copied from interface:JournalManagerMark the log segment that spans from firstTxId to lastTxId as finalized and complete.- Specified by:
finalizeLogSegmentin interfaceJournalManager- Throws:
IOException
-
getStorageDirectory
-
setOutputBufferCapacity
public void setOutputBufferCapacity(int size) Description copied from interface:JournalManagerSet the amount of memory that this stream should use to buffer edits- Specified by:
setOutputBufferCapacityin interfaceJournalManager
-
getLastReadableTxId
public long getLastReadableTxId() -
setLastReadableTxId
public void setLastReadableTxId(long id) -
purgeLogsOlderThan
Purges the unnecessary edits and edits_inprogress files. Edits files that are ending before the minTxIdToKeep are purged. Edits in progress files that are starting before minTxIdToKeep are purged. Edits in progress files that are marked as empty, trash, corrupted or stale by file extension and starting before minTxIdToKeep are purged. Edits in progress files that are after minTxIdToKeep, but before the current edits in progress files are marked as stale for clarity. In case file removal or rename is failing a warning is logged, but that does not fail the operation.- Parameters:
minTxIdToKeep- the lowest transaction ID that should be retained- Throws:
IOException- if listing the storage directory fails.
-
getRemoteEditLogs
public List<RemoteEditLog> getRemoteEditLogs(long firstTxId, boolean inProgressOk) throws IOException Find all editlog segments starting at or above the given txid.- Parameters:
firstTxId- the txnid which to start lookinginProgressOk- whether or not to include the in-progress edit log segment- Returns:
- a list of remote edit logs
- Throws:
IOException- if edit logs cannot be listed.
-
matchEditLogs
returns matching edit logs via the log directory. Simple helper function that lists the files in the logDir and calls matchEditLogs(File[])- Parameters:
logDir- directory to match edit logs in- Returns:
- matched edit logs
- Throws:
IOException- IOException thrown for invalid logDir
-
selectInputStreams
public void selectInputStreams(Collection<EditLogInputStream> streams, long fromTxnId, boolean inProgressOk) throws IOException - Throws:
IOException
-
selectInputStreams
public void selectInputStreams(Collection<EditLogInputStream> streams, long fromTxId, boolean inProgressOk, boolean onlyDurableTxns) throws IOException - Throws:
IOException
-
recoverUnfinalizedSegments
Description copied from interface:JournalManagerRecover segments which have not been finalized.- Specified by:
recoverUnfinalizedSegmentsin interfaceJournalManager- Throws:
IOException
-
getLogFiles
- Throws:
IOException
-
getLogFile
- Throws:
IOException
-
getLogFile
public FileJournalManager.EditLogFile getLogFile(long startTxId, boolean inProgressOk) throws IOException - Throws:
IOException
-
getLogFile
public static FileJournalManager.EditLogFile getLogFile(File dir, long startTxId) throws IOException - Throws:
IOException
-
getLogFile
public static FileJournalManager.EditLogFile getLogFile(File dir, long startTxId, boolean inProgressOk) throws IOException - Throws:
IOException
-
toString
- Specified by:
toStringin interfaceStorage.FormatConfirmable- Overrides:
toStringin classObject- Returns:
- a string representation of the formattable item, suitable for display to the user inside a prompt
-
doPreUpgrade
Description copied from interface:JournalManagerPerform any steps that must succeed across all JournalManagers involved in an upgrade before proceeding onto the actual upgrade stage. If a call to any JM's doPreUpgrade method fails, then doUpgrade will not be called for any JM.- Specified by:
doPreUpgradein interfaceJournalManager- Throws:
IOException
-
doUpgrade
This method assumes that the fields of theStorageobject have already been updated to the appropriate new values for the upgrade.- Specified by:
doUpgradein interfaceJournalManager- Parameters:
storage- info about the new upgraded versions.- Throws:
IOException
-
doFinalize
Description copied from interface:JournalManagerFinalize the upgrade. JMs should purge any state that they had been keeping around during the upgrade process. After this is completed, rollback is no longer allowed.- Specified by:
doFinalizein interfaceJournalManager- Throws:
IOException
-
canRollBack
public boolean canRollBack(StorageInfo storage, StorageInfo prevStorage, int targetLayoutVersion) throws IOException Description copied from interface:JournalManagerReturn true if this JM can roll back to the previous storage state, false otherwise. The NN will refuse to run the rollback operation unless at least one JM or fsimage storage directory can roll back.- Specified by:
canRollBackin interfaceJournalManager- Parameters:
storage- the storage info for the current stateprevStorage- the storage info for the previous (unupgraded) statetargetLayoutVersion- the layout version we intend to roll back to- Returns:
- true if this JM can roll back, false otherwise.
- Throws:
IOException
-
doRollback
Description copied from interface:JournalManagerPerform the rollback to the previous FS state. JMs which do not need to roll back their state should just return without error.- Specified by:
doRollbackin interfaceJournalManager- Throws:
IOException
-
discardSegments
Description copied from interface:JournalManagerDiscard the segments whose first txid is >= the given txid.- Specified by:
discardSegmentsin interfaceJournalManager- Parameters:
startTxid- The given txid should be right at the segment boundary, i.e., it should be the first txid of some segment, if segment corresponding to the txid exists.- Throws:
IOException
-
getJournalCTime
- Specified by:
getJournalCTimein interfaceJournalManager- Returns:
- the CTime of the journal manager.
- Throws:
IOException
-