Class FSEditLog
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.FSEditLog
FSEditLog maintains a log of the namespace modifications.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final FSEditLogOp.OpInstanceCachestatic final org.slf4j.Logger -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbooleancanRollBackSharedLog(StorageInfo prevStorage, int targetLayoutVersion) voiddiscardSegments(long markerTxid) voidvoidvoidvoidvoidendCurrentLogSegment(boolean writeEndTxn) Finalize the current log segment.longgetEditLogManifest(long fromTxId) Return a manifest of what finalized edit logs are availableUsed only by tests.longReturn the transaction ID of the last transaction written to the log.longlongReturn the txid of the last synced transaction.longReturn total number of syncs happened on this edit log.voidvoidbooleanvoidjournal(long firstTxId, int numTxns, byte[] data) Write the batch of edits to edit log.voidlogAddBlock(String path, INodeFile file) voidlogAppendFile(String path, INodeFile file, boolean newBlock, boolean toLogRpcIds) voidlogCloseFile(String path, INodeFile newNode) Add close lease record to edit log.voidAdd create directory record to edit logvoidlogOpenFile(String path, INodeFile newNode, boolean overwrite, boolean toLogRpcIds) Add open lease record to edit log.voidlogSync()Sync all modifications done by this thread.protected voidlogSync(long mytxid) voidlogUpdateBlocks(String path, INodeFile file, boolean toLogRpcIds) voidpurgeLogsOlderThan(long minTxIdToKeep) Archive any log files that are older than the given txid.voidrestart()selectInputStreams(long fromTxId, long toAtLeastTxId) selectInputStreams(long fromTxId, long toAtLeastTxId, MetaRecoveryContext recovery, boolean inProgressOK) selectInputStreams(long fromTxId, long toAtLeastTxId, MetaRecoveryContext recovery, boolean inProgressOk, boolean onlyDurableTxns) Select a list of input streams.voidselectInputStreams(Collection<EditLogInputStream> streams, long fromTxId, boolean inProgressOk, boolean onlyDurableTxns) voidstartLogSegment(long txid, boolean abortCurrentLogSegment, int layoutVersion) Remote namenode just has started a log segment, start log segment locally.
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG -
cache
-
-
Method Details
-
initJournalsForWrite
public void initJournalsForWrite() -
isOpenForRead
public boolean isOpenForRead()- Returns:
- true if the log is open in read mode.
-
beginTransaction
-
getLastWrittenTxId
public long getLastWrittenTxId()Return the transaction ID of the last transaction written to the log. -
getCurSegmentTxId
@VisibleForTesting public long getCurSegmentTxId()- Returns:
- the first transaction ID in the current log segment
-
logSync
public void logSync()Sync all modifications done by this thread. The internal concurrency design of this class is as follows: - Log items are written synchronized into an in-memory buffer, and each assigned a transaction ID. - When a thread (client) would like to sync all of its edits, logSync() uses a ThreadLocal transaction ID to determine what edit number must be synced to. - The isSyncRunning volatile boolean tracks whether a sync is currently under progress. The data is double-buffered within each edit log implementation so that in-memory writing can occur in parallel with the on-disk writing. Each sync occurs in three steps: 1. synchronized, it swaps the double buffer and sets the isSyncRunning flag. 2. unsynchronized, it flushes the data to storage 3. synchronized, it resets the flag and notifies anyone waiting on the sync. The lack of synchronization on step 2 allows other threads to continue to write into the memory buffer while the sync is in progress. Because this step is unsynchronized, actions that need to avoid concurrency with sync() should be synchronized and also call waitForSyncToFinish() before assuming they are running alone. -
logSync
protected void logSync(long mytxid) -
logAppendFile
-
logOpenFile
Add open lease record to edit log. Records the block locations of the last block. -
logCloseFile
Add close lease record to edit log. -
logAddBlock
-
logUpdateBlocks
-
logMkDir
Add create directory record to edit log -
getJournalSet
Used only by tests. -
getEditLogManifest
Return a manifest of what finalized edit logs are available- Throws:
IOException
-
startLogSegment
public void startLogSegment(long txid, boolean abortCurrentLogSegment, int layoutVersion) throws IOException Remote namenode just has started a log segment, start log segment locally.- Throws:
IOException
-
endCurrentLogSegment
public void endCurrentLogSegment(boolean writeEndTxn) Finalize the current log segment. Transitions from IN_SEGMENT state to BETWEEN_LOG_SEGMENTS state. -
purgeLogsOlderThan
public void purgeLogsOlderThan(long minTxIdToKeep) Archive any log files that are older than the given txid. If the edit log is not open for write, then this call returns with no effect. -
getSyncTxId
public long getSyncTxId()Return the txid of the last synced transaction. -
journal
public void journal(long firstTxId, int numTxns, byte[] data) Write the batch of edits to edit log. -
doRollback
- Throws:
IOException
-
discardSegments
- Throws:
IOException
-
selectInputStreams
public void selectInputStreams(Collection<EditLogInputStream> streams, long fromTxId, boolean inProgressOk, boolean onlyDurableTxns) throws IOException - Throws:
IOException
-
selectInputStreams
public Collection<EditLogInputStream> selectInputStreams(long fromTxId, long toAtLeastTxId) throws IOException - Throws:
IOException
-
selectInputStreams
public Collection<EditLogInputStream> selectInputStreams(long fromTxId, long toAtLeastTxId, MetaRecoveryContext recovery, boolean inProgressOK) throws IOException - Throws:
IOException
-
selectInputStreams
public Collection<EditLogInputStream> selectInputStreams(long fromTxId, long toAtLeastTxId, MetaRecoveryContext recovery, boolean inProgressOk, boolean onlyDurableTxns) throws IOException Select a list of input streams.- Parameters:
fromTxId- first transaction in the selected streamstoAtLeastTxId- the selected streams must contain this transactionrecovery- recovery contextinProgressOk- set to true if in-progress streams are OKonlyDurableTxns- set to true if streams are bounded by the durable TxId- Throws:
IOException
-
restart
@VisibleForTesting public void restart() -
getTotalSyncCount
public long getTotalSyncCount()Return total number of syncs happened on this edit log.- Returns:
- long - count
-