Class AbstractFSWAL<W extends WALProvider.WriterBase>
- All Implemented Interfaces:
Closeable
,AutoCloseable
,WALFileLengthProvider
,WAL
- Direct Known Subclasses:
AsyncFSWAL
,FSHLog
WAL
to go against FileSystem
; i.e. keep WALs in HDFS. Only one
WAL is ever being written at a time. When a WAL hits a configured maximum size, it is rolled.
This is done internal to the implementation.
As data is flushed from the MemStore to other on-disk structures (files sorted by key, hfiles), a WAL becomes obsolete. We can let go of all the log edits/entries for a given HRegion-sequence id. A bunch of work in the below is done keeping account of these region sequence ids -- what is flushed out to hfiles, and what is yet in WAL and in memory only.
It is only practical to delete entire files. Thus, we delete an entire on-disk file
F
when all of the edits in F
have a log-sequence-id that's older
(smaller) than the most-recent flush.
To read an WAL, call WALFactory.createStreamReader(FileSystem, Path)
for one way read,
call WALFactory.createTailingReader(FileSystem, Path, Configuration, long)
for
replication where we may want to tail the active WAL file.
Failure Semantic
If an exception on append or sync, roll the WAL because the current WAL is now a lame duck; any more appends or syncs will fail also with the same original exception. If we have made successful appends to the WAL and we then are unable to sync them, our current semantic is to return error to the client that the appends failed but also to abort the current context, usually the hosting server. We need to replay the WALs.TODO: Change this semantic. A roll of WAL may be sufficient as long as we have flagged client that the append failed.
TODO: replication may pick up these last edits though they have been marked as failed append (Need to keep our own file lengths, not rely on HDFS).
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Abortable
private final int
private final long
protected final long
Block size to use writing files.protected boolean
protected final ExecutorService
protected final org.apache.hadoop.conf.Configuration
conf objectprotected ExecutorService
private final Lock
protected final Runnable
private final AtomicBoolean
protected final WALCoprocessorHost
protected static final int
protected static final int
protected static final int
protected static final int
static final long
static final int
protected static final int
private int
private long
protected final AtomicLong
protected final org.apache.hadoop.fs.FileSystem
file system instanceprotected long
private long
protected final AtomicLong
Updated to the transaction id of the last successful sync call.protected long
The highest known outstanding unsync'd WALEdit transaction id.protected final String
The class name of the runtime implementation, used as prefix for logging/tracing.Tracks the logs in the process of being closed.private long
private long
protected final List<WALActionsListener>
Listeners that are called on WAL events.private static final org.slf4j.Logger
(package private) final Comparator<org.apache.hadoop.fs.Path>
WAL Comparator; it compares the timestamp (log filenum), present in the log file name.private final ExecutorService
protected final long
private boolean
private static final int
static final String
protected final int
private long
protected final AtomicInteger
protected final org.apache.hadoop.fs.PathFilter
Matches just those wal files that belong to this wal instance.protected final String
Prefix used when checking for wal membership.private boolean
private final Condition
private final org.apache.hadoop.fs.FileSystem
private final org.apache.hadoop.fs.Path
static final String
protected static final String
protected final long
The slow sync will be logged; the very slow sync will cause the WAL to be rolled.protected final AtomicBoolean
protected final ReentrantLock
This lock makes sure only one log roll runs at a time.private static final Comparator<SyncFuture>
protected final SequenceIdAccounting
Class that does accounting of sequenceids in WAL subsystem.protected boolean
protected final AtomicBoolean
private boolean
protected static final String
protected static final String
protected static final String
protected final int
protected final AtomicInteger
protected final long
The slow sync will be logged; the very slow sync will cause the WAL to be rolled.protected final int
private static final long
Don't log blocking regions more frequently than this.private static final int
private static final String
protected final SyncFutureCache
A cache of sync futures reused by threads.protected final SortedSet<SyncFuture>
protected final AtomicLong
The total size of walprotected final Deque<FSWALEntry>
protected final Deque<FSWALEntry>
protected final boolean
private final com.lmax.disruptor.RingBuffer<RingBufferTruck>
private final com.lmax.disruptor.Sequence
private int
private String
static final boolean
static final String
static final String
static final String
static final String
static final String
protected final org.apache.hadoop.fs.Path
dir path where old logs are kept.protected final org.apache.hadoop.fs.Path
WAL directory, where all WAL files would be placed.protected final ConcurrentNavigableMap<org.apache.hadoop.fs.Path,
AbstractFSWAL.WALProps> Map of WAL log file to properties.protected final String
Prefix of a WAL file, usually the region server name it is hosted on.protected final String
Suffix included on generated wal file namesprotected final long
private final long
private final long
(package private) W
Current log file. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractFSWAL
(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, org.apache.hadoop.fs.FileSystem remoteFs, org.apache.hadoop.fs.Path remoteWALDir) -
Method Summary
Modifier and TypeMethodDescriptionvoid
abortCacheFlush
(byte[] encodedRegionName) Abort a cache flush.protected long
append
(RegionInfo hri, WALKeyImpl key, WALEdit edits, boolean inMemstore) Append a set of edits to the WAL.private void
long
appendData
(RegionInfo info, WALKeyImpl key, WALEdit edits) Append a set of data edits to the WAL.protected final boolean
appendEntry
(W writer, FSWALEntry entry) long
appendMarker
(RegionInfo info, WALKeyImpl key, WALEdit edits) Append an operational 'meta' event marker edit to the WAL.protected void
protected void
archiveLogFile
(org.apache.hadoop.fs.Path p) protected void
Exposed for testing only.protected final void
blockOnSync
(SyncFuture syncFuture) private int
calculateMaxLogFiles
(org.apache.hadoop.conf.Configuration conf, long logRollSize) void
checkLogLowReplication
(long checkInterval) protected void
private void
Archive old logs.void
close()
Caller no longer needs any edits from this WAL.protected final void
closeWriter
(W writer, org.apache.hadoop.fs.Path path) void
completeCacheFlush
(byte[] encodedRegionName, long maxFlushedSeqId) Complete the cache flush.protected org.apache.hadoop.fs.Path
computeFilename
(long filenum) This is a convenience method that computes a new filename with a given file-number.private void
consume()
private IOException
private W
createCombinedWriter
(W localWriter, org.apache.hadoop.fs.Path localPath) protected abstract W
createCombinedWriter
(W localWriter, W remoteWriter) protected final void
createSingleThreadPoolConsumeExecutor
(String walType, org.apache.hadoop.fs.Path rootDir, String prefix) private io.opentelemetry.api.trace.Span
createSpan
(String name) protected abstract W
createWriterInstance
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) protected abstract void
doAppend
(W writer, FSWALEntry entry) protected abstract boolean
protected boolean
Returns true if we exceeded the slow sync roll threshold over the last check intervalprotected void
protected void
doReplaceWriter
(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath, W nextWriter) Notice that you need to clear therollRequested
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) protected abstract CompletableFuture<Long>
doWriterSync
(W writer, boolean shouldUseHsync, long txidWhenSyn) private void
private static IOException
private static int
epoch
(int epochAndState) If the number of un-archived WAL files ('live' WALs) is greater than maximum allowed, check the first (oldest) WAL, and return those regions which should be flushed so that it can be let-go/'archived'.private int
private int
finishSyncLowerThanTxid
(long txid) Returns Coprocessor host.org.apache.hadoop.fs.Path
This is a convenience method that computes a new filename with a given using the current WAL file-numberlong
getEarliestMemStoreSeqNum
(byte[] encodedRegionName, byte[] familyName) Gets the earliest unflushed sequence id in the memstore for the store.long
protected long
getFileNumFromFileName
(org.apache.hadoop.fs.Path fileName) A log file has a creation timestamp (in ms) in its file name (filenum
.(package private) org.apache.hadoop.fs.FileStatus[]
getFiles()
Get the backing files associated with this WAL.int
Returns number of WALs currently in the process of closing.private static long
getLastTxid
(Deque<FSWALEntry> queue) long
Returns the size of log files in usegetLogFileSizeIfBeingWritten
(org.apache.hadoop.fs.Path path) if the givenpath
is being written currently, then return its length.(package private) abstract int
This method gets the datanode replication count for the current WAL.private org.apache.hadoop.fs.Path
retrieve the next path to use for writing.int
Returns the number of log files in useint
Returns the number of rolled log filesorg.apache.hadoop.fs.Path
(package private) abstract org.apache.hadoop.hdfs.protocol.DatanodeInfo[]
This method gets the pipeline for the current WAL.protected final int
protected long
getSyncedTxid
(long processedTxid, long completableFutureResult) This method is to adaptFSHLog
andAsyncFSWAL
.protected final SyncFuture
getSyncFuture
(long sequence, boolean forceSync) (package private) long
static org.apache.hadoop.fs.Path
getWALArchivePath
(org.apache.hadoop.fs.Path archiveDir, org.apache.hadoop.fs.Path p) (package private) W
void
init()
Used to initialize the WAL.private boolean
isHsync
(long beginTxid, long endTxid) protected boolean
(package private) boolean
protected boolean
protected final void
logRollAndSetupWalProps
(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath, long oldFileLen) static void
Pass one or more log file names, and it will either dump out a text version onstdout
or split the specified log files.private void
markClosedAndClean
(org.apache.hadoop.fs.Path path) Mark this WAL file as closed and call cleanOldLogs to see if we can archive this file.protected void
markFutureDoneAndOffer
(SyncFuture future, long txid, Throwable t) Helper that marks the future as DONE and offers it back to the cache.private void
onAppendEntryFailed
(IOException exception) private void
onException
(long epochWhenSync, Throwable error) protected abstract void
onWriterReplaced
(W nextWriter) private long
postAppend
(WAL.Entry e, long elapsedTime) protected final void
postSync
(long timeInNanos, int handlerSyncs) private void
recoverLease
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path p, org.apache.hadoop.conf.Configuration conf) void
registerWALActionsListener
(WALActionsListener listener) Registers WALActionsListener(package private) org.apache.hadoop.fs.Path
replaceWriter
(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath, W nextWriter) Cleans up current writer closing it and then puts in place the passed innextWriter
.void
protected final void
Roll the log writer.rollWriter
(boolean force) Roll the log writer.rollWriterInternal
(boolean force) protected final void
setWaitOnShutdownInSeconds
(int waitOnShutdownInSeconds, String waitOnShutdownInSecondsConfigKey) private boolean
void
shutdown()
Stop accepting new writes.void
skipRemoteWAL
(boolean markerEditOnly) Tell the WAL that when creating new writer you can skip creating the remote writer.private static void
split
(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path p) protected final long
stampSequenceIdAndPublishToRingBuffer
(RegionInfo hri, WALKeyImpl key, WALEdit edits, boolean inMemstore, com.lmax.disruptor.RingBuffer<RingBufferTruck> ringBuffer) startCacheFlush
(byte[] encodedRegionName, Map<byte[], Long> familyToSeq) startCacheFlush
(byte[] encodedRegionName, Set<byte[]> families) WAL keeps track of the sequence numbers that are as yet not flushed im memstores in order to be able to do accounting to figure which WALs can be let go.final void
sync()
Sync what we have in the WAL.final void
sync
(boolean forceSync) final void
sync
(long txid) Sync the WAL if the txId was not already sync'd.final void
sync
(long txid, boolean forceSync) private void
private void
syncCompleted
(long epochWhenSync, W writer, long processedTxid, long startTimeNs) private void
syncFailed
(long epochWhenSync, Throwable error) private void
tellListenersAboutPostLogRoll
(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath) Tell listeners about post log roll.private void
tellListenersAboutPreLogRoll
(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath) Tell listeners about pre log roll.toString()
Human readable identifying information about the state of this WAL.private boolean
boolean
Unregisters WALActionsListenervoid
updateStore
(byte[] encodedRegionName, byte[] familyName, Long sequenceid, boolean onlyIfGreater) updates the sequence number of a specific store.private static void
usage()
protected final void
private static boolean
waitingRoll
(int epochAndState) private static boolean
writerBroken
(int epochAndState)
-
Field Details
-
LOG
-
SEQ_COMPARATOR
-
SURVIVED_TOO_LONG_SEC_KEY
- See Also:
-
SURVIVED_TOO_LONG_SEC_DEFAULT
- See Also:
-
SURVIVED_TOO_LONG_LOG_INTERVAL_NS
Don't log blocking regions more frequently than this. -
SLOW_SYNC_TIME_MS
- See Also:
-
DEFAULT_SLOW_SYNC_TIME_MS
- See Also:
-
ROLL_ON_SYNC_TIME_MS
- See Also:
-
DEFAULT_ROLL_ON_SYNC_TIME_MS
- See Also:
-
SLOW_SYNC_ROLL_THRESHOLD
- See Also:
-
DEFAULT_SLOW_SYNC_ROLL_THRESHOLD
- See Also:
-
SLOW_SYNC_ROLL_INTERVAL_MS
- See Also:
-
DEFAULT_SLOW_SYNC_ROLL_INTERVAL_MS
- See Also:
-
WAL_SYNC_TIMEOUT_MS
- See Also:
-
DEFAULT_WAL_SYNC_TIMEOUT_MS
- See Also:
-
WAL_ROLL_MULTIPLIER
- See Also:
-
MAX_LOGS
- See Also:
-
RING_BUFFER_SLOT_COUNT
- See Also:
-
WAL_SHUTDOWN_WAIT_TIMEOUT_MS
- See Also:
-
DEFAULT_WAL_SHUTDOWN_WAIT_TIMEOUT_MS
- See Also:
-
WAL_BATCH_SIZE
- See Also:
-
DEFAULT_WAL_BATCH_SIZE
- See Also:
-
WAL_AVOID_LOCAL_WRITES_KEY
- See Also:
-
WAL_AVOID_LOCAL_WRITES_DEFAULT
- See Also:
-
fs
file system instance -
walDir
WAL directory, where all WAL files would be placed. -
remoteFs
-
remoteWALDir
-
walArchiveDir
dir path where old logs are kept. -
ourFiles
Matches just those wal files that belong to this wal instance. -
walFilePrefix
Prefix of a WAL file, usually the region server name it is hosted on. -
walFileSuffix
Suffix included on generated wal file names -
prefixPathStr
Prefix used when checking for wal membership. -
coprocessorHost
-
conf
conf object -
abortable
-
listeners
Listeners that are called on WAL events. -
inflightWALClosures
Tracks the logs in the process of being closed. -
sequenceIdAccounting
Class that does accounting of sequenceids in WAL subsystem. Holds oldest outstanding sequence id as yet not flushed as well as the most recent edit sequence id appended to the WAL. Has facility for answering questions such as "Is it safe to GC a WAL?". -
slowSyncNs
The slow sync will be logged; the very slow sync will cause the WAL to be rolled. -
rollOnSyncNs
The slow sync will be logged; the very slow sync will cause the WAL to be rolled. -
slowSyncRollThreshold
-
slowSyncCheckInterval
-
slowSyncCount
-
walSyncTimeoutNs
-
walTooOldNs
-
logrollsize
-
blocksize
Block size to use writing files. -
maxLogs
-
useHsync
-
rollWriterLock
This lock makes sure only one log roll runs at a time. Should not be taken while any other lock is held. We don't just use synchronized because that results in bogus and tedious findbugs warning when it thinks synchronized controls writer thread safety. It is held when we are actually rolling the log. It is checked when we are looking to see if we should roll the log or not. -
filenum
-
numEntries
-
highestUnsyncedTxid
The highest known outstanding unsync'd WALEdit transaction id. Usually, we use a queue to pass WALEdit to background consumer thread, and the transaction id is the sequence number of the corresponding entry in queue. -
highestSyncedTxid
Updated to the transaction id of the last successful sync call. This can be less thanhighestUnsyncedTxid
for case where we have an append where a sync has not yet come in for it. -
totalLogSize
The total size of wal -
writer
Current log file. -
lastTimeCheckLowReplication
-
lastTimeCheckSlowSync
-
closed
-
shutdown
-
walShutdownTimeout
-
nextLogTooOldNs
-
LOG_NAME_COMPARATOR
WAL Comparator; it compares the timestamp (log filenum), present in the log file name. Throws an IllegalArgumentException if used to compare paths from different wals. -
walFile2Props
protected final ConcurrentNavigableMap<org.apache.hadoop.fs.Path,AbstractFSWAL.WALProps> walFile2PropsMap of WAL log file to properties. The map is sorted by the log file creation timestamp (contained in the log file name). -
syncFutureCache
A cache of sync futures reused by threads. -
implClassName
The class name of the runtime implementation, used as prefix for logging/tracing.Performance testing shows getClass().getSimpleName() might be a bottleneck so we store it here, refer to HBASE-17676 for more details
-
rollRequested
-
closeExecutor
-
logArchiveExecutor
-
archiveRetries
-
consumeExecutor
-
consumeLock
-
consumer
-
hasConsumerTask
-
MAX_EPOCH
- See Also:
-
epochAndState
-
readyForRolling
-
readyForRollingCond
-
waitingConsumePayloads
-
waitingConsumePayloadsGatingSequence
-
consumerScheduled
-
batchSize
-
toWriteAppends
-
unackedAppends
-
syncFutures
-
highestProcessedAppendTxid
-
fileLengthAtLastSync
-
highestProcessedAppendTxidAtLastSync
-
waitOnShutdownInSeconds
-
waitOnShutdownInSecondsConfigKey
-
shouldShutDownConsumeExecutorWhenClose
-
skipRemoteWAL
-
markerEditOnly
-
-
Constructor Details
-
AbstractFSWAL
protected AbstractFSWAL(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, org.apache.hadoop.fs.FileSystem remoteFs, org.apache.hadoop.fs.Path remoteWALDir) throws FailedLogCloseException, IOException - Throws:
FailedLogCloseException
IOException
-
-
Method Details
-
getFilenum
-
getFileNumFromFileName
A log file has a creation timestamp (in ms) in its file name (filenum
. This helper method returns the creation timestamp from a given log file. It extracts the timestamp assuming the filename is created with thecomputeFilename(long filenum)
method.- Returns:
- timestamp, as in the log file name.
-
calculateMaxLogFiles
-
getPreallocatedEventCount
-
setWaitOnShutdownInSeconds
protected final void setWaitOnShutdownInSeconds(int waitOnShutdownInSeconds, String waitOnShutdownInSecondsConfigKey) -
createSingleThreadPoolConsumeExecutor
protected final void createSingleThreadPoolConsumeExecutor(String walType, org.apache.hadoop.fs.Path rootDir, String prefix) -
init
Used to initialize the WAL. Usually just call rollWriter to create the first log writer.- Specified by:
init
in interfaceWAL
- Throws:
IOException
-
registerWALActionsListener
Description copied from interface:WAL
Registers WALActionsListener- Specified by:
registerWALActionsListener
in interfaceWAL
-
unregisterWALActionsListener
Description copied from interface:WAL
Unregisters WALActionsListener- Specified by:
unregisterWALActionsListener
in interfaceWAL
-
getCoprocessorHost
Description copied from interface:WAL
Returns Coprocessor host.- Specified by:
getCoprocessorHost
in interfaceWAL
-
startCacheFlush
Description copied from interface:WAL
WAL keeps track of the sequence numbers that are as yet not flushed im memstores in order to be able to do accounting to figure which WALs can be let go. This method tells WAL that some region is about to flush. The flush can be the whole region or for a column family of the region only.Currently, it is expected that the update lock is held for the region; i.e. no concurrent appends while we set up cache flush.
- Specified by:
startCacheFlush
in interfaceWAL
families
- Families to flush. May be a subset of all families in the region.- Returns:
- Returns
HConstants.NO_SEQNUM
if we are flushing the whole region OR if we are flushing a subset of all families but there are no edits in those families not being flushed; in other words, this is effectively same as a flush of all of the region though we were passed a subset of regions. Otherwise, it returns the sequence id of the oldest/lowest outstanding edit. - See Also:
-
startCacheFlush
- Specified by:
startCacheFlush
in interfaceWAL
-
completeCacheFlush
Description copied from interface:WAL
Complete the cache flush.- Specified by:
completeCacheFlush
in interfaceWAL
- Parameters:
encodedRegionName
- Encoded region name.maxFlushedSeqId
- The maxFlushedSeqId for this flush. There is no edit in memory that is less that this sequence id.- See Also:
-
abortCacheFlush
Description copied from interface:WAL
Abort a cache flush. Call if the flush fails. Note that the only recovery for an aborted flush currently is a restart of the regionserver so the snapshot content dropped by the failure gets restored to the memstore.- Specified by:
abortCacheFlush
in interfaceWAL
- Parameters:
encodedRegionName
- Encoded region name.
-
getEarliestMemStoreSeqNum
Description copied from interface:WAL
Gets the earliest unflushed sequence id in the memstore for the store.- Specified by:
getEarliestMemStoreSeqNum
in interfaceWAL
- Parameters:
encodedRegionName
- The region to get the number for.familyName
- The family to get the number for.- Returns:
- The earliest/lowest/oldest sequence id if present, HConstants.NO_SEQNUM if absent.
-
rollWriter
Description copied from interface:WAL
Roll the log writer. That is, start writing log messages to a new file. The implementation is synchronized in order to make sure there's one rollWriter running at any given time.- Specified by:
rollWriter
in interfaceWAL
- Returns:
- If lots of logs, flush the stores of returned regions so next time through we can clean
logs. Returns null if nothing to flush. Names are actual region names as returned by
RegionInfo.getEncodedName()
- Throws:
FailedLogCloseException
IOException
-
sync
Description copied from interface:WAL
Sync what we have in the WAL.- Specified by:
sync
in interfaceWAL
- Throws:
IOException
-
sync
Description copied from interface:WAL
Sync the WAL if the txId was not already sync'd.- Specified by:
sync
in interfaceWAL
- Parameters:
txid
- Transaction id to sync to.- Throws:
IOException
-
sync
- Specified by:
sync
in interfaceWAL
- Parameters:
forceSync
- Flag to force sync rather than flushing to the buffer. Example - Hadoop hflush vs hsync.- Throws:
IOException
-
sync
- Specified by:
sync
in interfaceWAL
- Parameters:
txid
- Transaction id to sync to.forceSync
- Flag to force sync rather than flushing to the buffer. Example - Hadoop hflush vs hsync.- Throws:
IOException
-
getSequenceIdAccounting
-
computeFilename
This is a convenience method that computes a new filename with a given file-number.- Parameters:
filenum
- to use
-
getCurrentFileName
This is a convenience method that computes a new filename with a given using the current WAL file-number -
getNewPath
retrieve the next path to use for writing. Increments the internal filenum.- Throws:
IOException
-
getOldPath
-
tellListenersAboutPreLogRoll
private void tellListenersAboutPreLogRoll(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath) throws IOException Tell listeners about pre log roll.- Throws:
IOException
-
tellListenersAboutPostLogRoll
private void tellListenersAboutPostLogRoll(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath) throws IOException Tell listeners about post log roll.- Throws:
IOException
-
getNumRolledLogFiles
Returns the number of rolled log files -
getNumLogFiles
Returns the number of log files in use -
findRegionsToForceFlush
If the number of un-archived WAL files ('live' WALs) is greater than maximum allowed, check the first (oldest) WAL, and return those regions which should be flushed so that it can be let-go/'archived'.- Returns:
- stores of regions (encodedRegionNames) to flush in order to archive the oldest WAL file
- Throws:
IOException
-
markClosedAndClean
Mark this WAL file as closed and call cleanOldLogs to see if we can archive this file. -
cleanOldLogs
Archive old logs. A WAL is eligible for archiving if all its WALEdits have been flushed. Use synchronized because we may call this method in different threads, normally when replacing writer, and since now close writer may be asynchronous, we will also call this method in the closeExecutor, right after we actually close a WAL writer. -
archive
-
getWALArchivePath
public static org.apache.hadoop.fs.Path getWALArchivePath(org.apache.hadoop.fs.Path archiveDir, org.apache.hadoop.fs.Path p) -
archiveLogFile
- Throws:
IOException
-
logRollAndSetupWalProps
protected final void logRollAndSetupWalProps(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath, long oldFileLen) -
createSpan
-
replaceWriter
org.apache.hadoop.fs.Path replaceWriter(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath, W nextWriter) throws IOException Cleans up current writer closing it and then puts in place the passed innextWriter
.- In the case of creating a new WAL, oldPath will be null.
- In the case of rolling over from one file to the next, none of the parameters will be null.
- In the case of closing out this FSHLog with no further use newPath and nextWriter will be null.
- Parameters:
oldPath
- may be nullnewPath
- may be nullnextWriter
- may be null- Returns:
- the passed in
newPath
- Throws:
IOException
- if there is a problem flushing or closing the underlying FS
-
blockOnSync
- Throws:
IOException
-
ensureIOException
-
convertInterruptedExceptionToIOException
-
createCombinedWriter
private W createCombinedWriter(W localWriter, org.apache.hadoop.fs.Path localPath) throws IOException, CommonFSUtils.StreamLacksCapabilityException -
rollWriterInternal
- Throws:
IOException
-
rollWriter
Description copied from interface:WAL
Roll the log writer. That is, start writing log messages to a new file. The implementation is synchronized in order to make sure there's one rollWriter running at any given time. If true, force creation of a new writer even if no entries have been written to the current writer- Specified by:
rollWriter
in interfaceWAL
- Returns:
- If lots of logs, flush the stores of returned regions so next time through we can clean
logs. Returns null if nothing to flush. Names are actual region names as returned by
RegionInfo.getEncodedName()
- Throws:
IOException
-
getLogFileSize
Returns the size of log files in use -
requestLogRoll
-
getFiles
Get the backing files associated with this WAL.- Returns:
- may be null if there are no files.
- Throws:
IOException
-
shutdown
Description copied from interface:WAL
Stop accepting new writes. If we have unsynced writes still in buffer, sync them. Extant edits are left in place in backing storage to be replayed later.- Specified by:
shutdown
in interfaceWAL
- Throws:
IOException
-
close
Description copied from interface:WAL
Caller no longer needs any edits from this WAL. Implementers are free to reclaim underlying resources after this call; i.e. filesystem based WALs can archive or delete files.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceWAL
- Throws:
IOException
-
getInflightWALCloseCount
Returns number of WALs currently in the process of closing. -
updateStore
public void updateStore(byte[] encodedRegionName, byte[] familyName, Long sequenceid, boolean onlyIfGreater) updates the sequence number of a specific store. depending on the flag: replaces current seq number if the given seq id is bigger, or even if it is lower than existing one- Specified by:
updateStore
in interfaceWAL
-
getSyncFuture
-
isLogRollRequested
-
requestLogRoll
-
getUnflushedEntriesCount
long getUnflushedEntriesCount() -
isUnflushedEntries
boolean isUnflushedEntries() -
atHeadOfRingBufferEventHandlerAppend
Exposed for testing only. Use to tricks like halt the ring buffer appending. -
appendEntry
- Throws:
IOException
-
postAppend
- Throws:
IOException
-
postSync
-
stampSequenceIdAndPublishToRingBuffer
protected final long stampSequenceIdAndPublishToRingBuffer(RegionInfo hri, WALKeyImpl key, WALEdit edits, boolean inMemstore, com.lmax.disruptor.RingBuffer<RingBufferTruck> ringBuffer) throws IOException - Throws:
IOException
-
toString
Description copied from interface:WAL
Human readable identifying information about the state of this WAL. Implementors are encouraged to include information appropriate for debugging. Consumers are advised not to rely on the details of the returned String; it does not have a defined structure. -
getLogFileSizeIfBeingWritten
if the givenpath
is being written currently, then return its length.This is used by replication to prevent replicating unacked log entries. See https://issues.apache.org/jira/browse/HBASE-14004 for more details.
- Specified by:
getLogFileSizeIfBeingWritten
in interfaceWALFileLengthProvider
-
appendData
Description copied from interface:WAL
Append a set of data edits to the WAL. 'Data' here means that the content in the edits will also have transitioned through the memstore. 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.- Specified by:
appendData
in interfaceWAL
- Parameters:
info
- 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.- Returns:
- Returns a 'transaction id' and
key
will have the region edit/sequence id in it. - Throws:
IOException
- See Also:
-
appendMarker
Description copied from interface:WAL
Append an operational 'meta' event marker edit to the WAL. A marker meta edit could be a FlushDescriptor, a compaction marker, or a region event marker; e.g. region open or region close. The difference between a 'marker' append and a 'data' append as inWAL.appendData(RegionInfo, WALKeyImpl, WALEdit)
is that a marker will not have transitioned through the memstore. 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.- Specified by:
appendMarker
in interfaceWAL
- Parameters:
info
- 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.- Returns:
- Returns a 'transaction id' and
key
will have the region edit/sequence id in it. - Throws:
IOException
- See Also:
-
markFutureDoneAndOffer
Helper that marks the future as DONE and offers it back to the cache. -
waitingRoll
-
writerBroken
-
epoch
-
trySetReadyForRolling
-
syncFailed
-
onException
-
syncCompleted
-
isHsync
-
sync
-
getSyncedTxid
This method is to adaptFSHLog
andAsyncFSWAL
. ForAsyncFSWAL
, we usehighestProcessedAppendTxid
at the point we callingAsyncFSWAL.doWriterSync(org.apache.hadoop.hbase.wal.WALProvider.AsyncWriter, boolean, long)
method as successful syncedTxid. ForFSHLog
, because we use multi-threadSyncRunner
s, we used the result ofCompletableFuture
as successful syncedTxid. -
doWriterSync
protected abstract CompletableFuture<Long> doWriterSync(W writer, boolean shouldUseHsync, long txidWhenSyn) -
finishSyncLowerThanTxid
-
finishSync
-
getLastTxid
-
appendAndSync
- Throws:
IOException
-
consume
-
shouldScheduleConsumer
-
append
protected long append(RegionInfo hri, WALKeyImpl key, WALEdit edits, boolean inMemstore) throws IOException 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.- 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
-
doSync
- Throws:
IOException
-
doSync
- Throws:
IOException
-
drainNonMarkerEditsAndFailSyncs
-
createWriterInstance
protected abstract W createWriterInstance(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException, CommonFSUtils.StreamLacksCapabilityException -
createCombinedWriter
-
waitForSafePoint
-
recoverLease
private void recoverLease(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path p, org.apache.hadoop.conf.Configuration conf) -
closeWriter
-
doReplaceWriter
protected void doReplaceWriter(org.apache.hadoop.fs.Path oldPath, org.apache.hadoop.fs.Path newPath, W nextWriter) throws IOException Notice that you need to clear therollRequested
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 therollRequested
flag, so we do not miss a roll request, typically before you start writing to the new writer.- Throws:
IOException
-
onWriterReplaced
-
doShutdown
- Throws:
IOException
-
doCleanUpResources
-
doAppend
- Throws:
IOException
-
getPipeline
This method gets the pipeline for the current WAL. -
getLogReplication
This method gets the datanode replication count for the current WAL. -
doCheckLogLowReplication
-
isWriterBroken
-
onAppendEntryFailed
-
checkSlowSyncCount
-
doCheckSlowSync
Returns true if we exceeded the slow sync roll threshold over the last check interval -
checkLogLowReplication
-
skipRemoteWAL
Description copied from interface:WAL
Tell the WAL that when creating new writer you can skip creating the remote writer.Used by sync replication for switching states from ACTIVE, where the remote cluster is broken.
- Specified by:
skipRemoteWAL
in interfaceWAL
-
split
private static void split(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path p) throws IOException - Throws:
IOException
-
getWriter
-
usage
-
main
Pass one or more log file names, and it will either dump out a text version onstdout
or split the specified log files.- Throws:
IOException
-