Class FSHLog
java.lang.Object
org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL<WALProvider.Writer>
org.apache.hadoop.hbase.regionserver.wal.FSHLog
- All Implemented Interfaces:
Closeable
,AutoCloseable
,WALFileLengthProvider
,WAL
The original implementation of FSWAL.
-
Nested Class Summary
Modifier and TypeClassDescription(package private) class
Handler that is run by the disruptor ringbuffer consumer.(package private) static class
Exception handler to pass the disruptor ringbuffer.(package private) static class
This class is used coordinating two threads holding one thread at a 'safe point' while the orchestrating thread does some work that requires the first thread paused: e.g.private class
Thread to runs the hdfs sync call. -
Field Summary
Modifier and TypeFieldDescriptionprivate final AtomicInteger
private final int
Number of log close errors tolerated before we abortprivate final AtomicInteger
private static final int
private static final int
private static final int
private static final int
private static final int
private final com.lmax.disruptor.dsl.Disruptor<RingBufferTruck>
The nexus at which all incoming handlers meet.static final long
private static final String
private org.apache.hadoop.fs.FSDataOutputStream
FSDataOutputStream associated with the current SequenceFile.writerprivate static final org.slf4j.Logger
private static final String
private boolean
private final int
private static final String
private final int
private final FSHLog.RingBufferEventHandler
This fellow is run by the above appendExecutor service but it is all about batching up appends and syncs; it may shutdown without cleaning out the last few appends or syncs.private static final String
private static final String
private static final String
private final int
Fields inherited from class org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL
abortable, blocksize, closed, closeExecutor, conf, coprocessorHost, DEFAULT_ROLL_ON_SYNC_TIME_MS, DEFAULT_SLOW_SYNC_ROLL_INTERVAL_MS, DEFAULT_SLOW_SYNC_ROLL_THRESHOLD, DEFAULT_SLOW_SYNC_TIME_MS, DEFAULT_WAL_SHUTDOWN_WAIT_TIMEOUT_MS, DEFAULT_WAL_SYNC_TIMEOUT_MS, filenum, fs, highestSyncedTxid, highestUnsyncedTxid, implClassName, inflightWALClosures, listeners, LOG_NAME_COMPARATOR, logrollsize, MAX_LOGS, maxLogs, numEntries, ourFiles, prefixPathStr, RING_BUFFER_SLOT_COUNT, ROLL_ON_SYNC_TIME_MS, rollOnSyncNs, rollRequested, rollWriterLock, sequenceIdAccounting, shutdown, SLOW_SYNC_ROLL_INTERVAL_MS, SLOW_SYNC_ROLL_THRESHOLD, SLOW_SYNC_TIME_MS, slowSyncCheckInterval, slowSyncCount, slowSyncNs, slowSyncRollThreshold, syncFutureCache, totalLogSize, useHsync, WAL_AVOID_LOCAL_WRITES_DEFAULT, WAL_AVOID_LOCAL_WRITES_KEY, WAL_ROLL_MULTIPLIER, WAL_SHUTDOWN_WAIT_TIMEOUT_MS, WAL_SYNC_TIMEOUT_MS, walArchiveDir, walDir, walFile2Props, walFilePrefix, walFileSuffix, walShutdownTimeout, writer
-
Constructor Summary
ConstructorDescriptionFSHLog
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, String logDir, String archiveDir, org.apache.hadoop.conf.Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists, String prefix, String suffix) FSHLog
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path root, String logDir, org.apache.hadoop.conf.Configuration conf) Constructor.FSHLog
(org.apache.hadoop.fs.FileSystem fs, Abortable abortable, org.apache.hadoop.fs.Path rootDir, String logDir, String archiveDir, org.apache.hadoop.conf.Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists, String prefix, String suffix) Create an edit log at the givendir
location.FSHLog
(org.apache.hadoop.fs.FileSystem fs, Abortable abortable, org.apache.hadoop.fs.Path root, String logDir, org.apache.hadoop.conf.Configuration conf) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Used to manufacture race condition reliably.protected long
append
(RegionInfo hri, WALKeyImpl key, WALEdit edits, boolean inMemstore) Append a set of edits to the WAL.protected void
private void
Schedule a log roll if needed.private void
closeWriter
(WALProvider.Writer writer, org.apache.hadoop.fs.Path path, boolean syncCloseCall) protected WALProvider.Writer
createWriterInstance
(org.apache.hadoop.fs.Path path) This method allows subclasses to inject different writers without having to extend other methods like rollWriter().protected void
doAppend
(WALProvider.Writer writer, FSWALEntry entry) protected boolean
Returns true if number of replicas for the WAL is lower than thresholdprotected void
doReplaceWriter
(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath, WALProvider.Writer nextWriter) Notice that you need to clear theAbstractFSWAL.rollRequested
flag in this method, as the new writer will begin to work before returning from this method.protected void
protected void
doSync
(boolean forceSync) protected void
doSync
(long txid, boolean forceSync) (package private) int
This method gets the datanode replication count for the current WAL.(package private) OutputStream
Currently, we need to expose the writer's OutputStream to tests so that they can manipulate the default behavior (such as setting the maxRecoveryErrorCount value).(package private) org.apache.hadoop.hdfs.protocol.DatanodeInfo[]
This method gets the pipeline for the current WAL.protected long
(package private) boolean
private void
preemptiveSync
(ProtobufLogWriter nextWriter) Run a sync after opening to set up the pipeline.private SyncFuture
publishSyncOnRingBuffer
(boolean forceSync) protected SyncFuture
publishSyncOnRingBuffer
(long sequence, boolean forceSync) private void
publishSyncThenBlockOnCompletion
(boolean forceSync) Methods inherited from class org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL
abortCacheFlush, appendData, appendEntry, appendMarker, archive, archiveLogFile, atHeadOfRingBufferEventHandlerAppend, blockOnSync, checkLogLowReplication, close, completeCacheFlush, computeFilename, doCheckSlowSync, findRegionsToForceFlush, getCoprocessorHost, getCurrentFileName, getEarliestMemStoreSeqNum, getEarliestMemStoreSeqNum, getFilenum, getFileNumFromFileName, getFiles, getInflightWALCloseCount, getLogFileSize, getLogFileSizeIfBeingWritten, getNumLogFiles, getNumRolledLogFiles, getOldPath, getPreallocatedEventCount, getSyncFuture, getUnflushedEntriesCount, getWALArchivePath, getWriter, init, isLogRollRequested, isUnflushedEntries, logRollAndSetupWalProps, main, markClosedAndClean, postSync, registerWALActionsListener, replaceWriter, requestLogRoll, requestLogRoll, rollWriter, rollWriter, shutdown, stampSequenceIdAndPublishToRingBuffer, startCacheFlush, startCacheFlush, sync, sync, sync, sync, toString, unregisterWALActionsListener, updateStore
-
Field Details
-
LOG
-
TOLERABLE_LOW_REPLICATION
- See Also:
-
LOW_REPLICATION_ROLL_LIMIT
- See Also:
-
DEFAULT_LOW_REPLICATION_ROLL_LIMIT
- See Also:
-
ROLL_ERRORS_TOLERATED
- See Also:
-
DEFAULT_ROLL_ERRORS_TOLERATED
- See Also:
-
SYNCER_COUNT
- See Also:
-
DEFAULT_SYNCER_COUNT
- See Also:
-
MAX_BATCH_COUNT
- See Also:
-
DEFAULT_MAX_BATCH_COUNT
- See Also:
-
FSHLOG_WAIT_ON_SHUTDOWN_IN_SECONDS
- See Also:
-
DEFAULT_FSHLOG_WAIT_ON_SHUTDOWN_IN_SECONDS
- See Also:
-
disruptor
The nexus at which all incoming handlers meet. Does appends and sync with an ordering. Appends and syncs are each put on the ring which means handlers need to smash up against the ring twice (can we make it once only? ... maybe not since time to append is so different from time to sync and sometimes we don't want to sync or we want to async the sync). The ring is where we make sure of our ordering and it is also where we do batching up of handler sync calls. -
ringBufferEventHandler
This fellow is run by the above appendExecutor service but it is all about batching up appends and syncs; it may shutdown without cleaning out the last few appends or syncs. To guard against this, keep a reference to this handler and do explicit close on way out to make sure all flushed out before we exit. -
hdfs_out
FSDataOutputStream associated with the current SequenceFile.writer -
minTolerableReplication
-
consecutiveLogRolls
-
lowReplicationRollLimit
-
lowReplicationRollEnabled
-
closeErrorsTolerated
Number of log close errors tolerated before we abort -
closeErrorCount
-
waitOnShutdownInSeconds
-
FIXED_OVERHEAD
-
-
Constructor Details
-
FSHLog
public FSHLog(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path root, String logDir, org.apache.hadoop.conf.Configuration conf) throws IOException Constructor.- Parameters:
fs
- filesystem handleroot
- path for stored and archived walslogDir
- dir where wals are storedconf
- configuration to use- Throws:
IOException
-
FSHLog
public FSHLog(org.apache.hadoop.fs.FileSystem fs, Abortable abortable, org.apache.hadoop.fs.Path root, String logDir, org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
FSHLog
public FSHLog(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, String logDir, String archiveDir, org.apache.hadoop.conf.Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists, String prefix, String suffix) throws IOException - Throws:
IOException
-
FSHLog
public FSHLog(org.apache.hadoop.fs.FileSystem fs, Abortable abortable, org.apache.hadoop.fs.Path rootDir, String logDir, String archiveDir, org.apache.hadoop.conf.Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists, String prefix, String suffix) throws IOException Create an edit log at the givendir
location. You should never have to load an existing log. If there is a log at startup, it should have already been processed and deleted by the time the WAL object is started up.- Parameters:
fs
- filesystem handlerootDir
- path to where logs and oldlogslogDir
- dir where wals are storedarchiveDir
- dir where wals are archivedconf
- configuration to uselisteners
- Listeners on WAL events. Listeners passed here will be registered before we do anything else; e.g. the ConstructorAbstractFSWAL.rollWriter()
.failIfWALExists
- If true IOException will be thrown if files related to this wal already exist.prefix
- should always be hostname and port in distributed env and it will be URL encoded before being used. If prefix is null, "wal" will be usedsuffix
- will be url encoded. null is treated as empty. non-empty must start withAbstractFSWALProvider.WAL_FILE_NAME_DELIMITER
- Throws:
IOException
-
-
Method Details
-
getOutputStream
Currently, we need to expose the writer's OutputStream to tests so that they can manipulate the default behavior (such as setting the maxRecoveryErrorCount value). This is done using reflection on the underlying HDFS OutputStream. NOTE: This could be removed once Hadoop1 support is removed.- Returns:
- null if underlying stream is not ready.
-
preemptiveSync
Run a sync after opening to set up the pipeline. -
createWriterInstance
protected WALProvider.Writer createWriterInstance(org.apache.hadoop.fs.Path path) throws IOException This method allows subclasses to inject different writers without having to extend other methods like rollWriter().- Specified by:
createWriterInstance
in classAbstractFSWAL<WALProvider.Writer>
- Returns:
- Writer instance
- Throws:
IOException
-
afterCreatingZigZagLatch
Used to manufacture race condition reliably. For testing only.- See Also:
-
beforeWaitOnSafePoint
- See Also:
-
doAppend
- Specified by:
doAppend
in classAbstractFSWAL<WALProvider.Writer>
- Throws:
IOException
-
doReplaceWriter
protected void doReplaceWriter(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath, WALProvider.Writer nextWriter) throws IOException Description copied from class:AbstractFSWAL
Notice that you need to clear theAbstractFSWAL.rollRequested
flag in this method, as the new writer will begin to work before returning from this method. If we clear the flag after returning from this call, we may miss a roll request. The implementation class should choose a proper place to clear theAbstractFSWAL.rollRequested
flag, so we do not miss a roll request, typically before you start writing to the new writer.- Specified by:
doReplaceWriter
in classAbstractFSWAL<WALProvider.Writer>
- Throws:
IOException
-
closeWriter
private void closeWriter(WALProvider.Writer writer, org.apache.hadoop.fs.Path path, boolean syncCloseCall) throws IOException - Throws:
IOException
-
doShutdown
- Specified by:
doShutdown
in classAbstractFSWAL<WALProvider.Writer>
- Throws:
IOException
-
append
protected long append(RegionInfo hri, WALKeyImpl key, WALEdit edits, boolean inMemstore) throws IOException Description copied from class:AbstractFSWAL
Append a set of edits to the WAL. The WAL is not flushed/sync'd after this transaction completes BUT on return this edit must have its region edit/sequence id assigned else it messes up our unification of mvcc and sequenceid. On returnkey
will have the region edit/sequence id filled in. NOTE: This appends, at a time that is usually after this call returns, starts a mvcc transaction by calling 'begin' wherein which we assign this update a sequenceid. At assignment time, we stamp all the passed in Cells inside WALEdit with their sequenceId. You must 'complete' the transaction this mvcc transaction by calling MultiVersionConcurrencyControl#complete(...) or a variant otherwise mvcc will get stuck. Do it in the finally of a try/finally block within which this appends lives and any subsequent operations like sync or update of memstore, etc. Get the WriteEntry to pass mvcc out of the passed in WALKeywalKey
parameter. Be warned that the WriteEntry is not immediately available on return from this method. It WILL be available subsequent to a sync of this append; otherwise, you will just have to wait on the WriteEntry to get filled in.- Specified by:
append
in classAbstractFSWAL<WALProvider.Writer>
- Parameters:
hri
- the regioninfo associated with appendkey
- Modified by this call; we add to it this edits region edit/sequence id.edits
- Edits to append. MAY CONTAIN NO EDITS for case where we want to get an edit sequence id that is after all currently appended edits.inMemstore
- Always true except for case where we are writing a region event meta marker edit, for example, a compaction completion record into the WAL or noting a Region Open event. In these cases the entry is just so we can finish an unfinished compaction after a crash when the new Server reads the WAL on recovery, etc. These transition event 'Markers' do not go via the memstore. When memstore is false, we presume a Marker event edit.- Returns:
- Returns a 'transaction id' and
key
will have the region edit/sequence id in it. - Throws:
IOException
-
checkLogRoll
Schedule a log roll if needed. -
doCheckLogLowReplication
Returns true if number of replicas for the WAL is lower than threshold- Specified by:
doCheckLogLowReplication
in classAbstractFSWAL<WALProvider.Writer>
-
getSequenceOnRingBuffer
-
publishSyncOnRingBuffer
-
publishSyncOnRingBuffer
-
publishSyncThenBlockOnCompletion
- Throws:
IOException
-
getLogReplication
int getLogReplication()This method gets the datanode replication count for the current WAL.If the pipeline isn't started yet or is empty, you will get the default replication factor. Therefore, if this function returns 0, it means you are not properly running with the HDFS-826 patch.
- Specified by:
getLogReplication
in classAbstractFSWAL<WALProvider.Writer>
-
doSync
- Specified by:
doSync
in classAbstractFSWAL<WALProvider.Writer>
- Throws:
IOException
-
doSync
- Specified by:
doSync
in classAbstractFSWAL<WALProvider.Writer>
- Throws:
IOException
-
isLowReplicationRollEnabled
boolean isLowReplicationRollEnabled() -
getPipeline
org.apache.hadoop.hdfs.protocol.DatanodeInfo[] getPipeline()This method gets the pipeline for the current WAL.- Specified by:
getPipeline
in classAbstractFSWAL<WALProvider.Writer>
-