@InterfaceAudience.Private public class FSHLog extends Object implements WAL
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.createReader(org.apache.hadoop.fs.FileSystem,
org.apache.hadoop.fs.Path)
.
WAL.Entry, WAL.Reader
Modifier and Type | Field and Description |
---|---|
protected org.apache.hadoop.conf.Configuration |
conf
conf object
|
static long |
FIXED_OVERHEAD |
protected org.apache.hadoop.fs.FileSystem |
fs
file system instance
|
Constructor and Description |
---|
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,
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 given
dir location. |
Modifier and Type | Method and Description |
---|---|
void |
abortCacheFlush(byte[] encodedRegionName)
Abort a cache flush.
|
protected void |
afterCreatingZigZagLatch()
Used to manufacture race condition reliably.
|
long |
append(HTableDescriptor htd,
HRegionInfo hri,
WALKey key,
WALEdit edits,
boolean inMemstore)
Append a set of edits to the WAL.
|
protected void |
beforeWaitOnSafePoint() |
void |
checkLogRoll()
Schedule a log roll if needed.
|
void |
close()
Caller no longer needs any edits from this WAL.
|
void |
completeCacheFlush(byte[] encodedRegionName)
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.
|
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().
|
WALCoprocessorHost |
getCoprocessorHost() |
org.apache.hadoop.fs.Path |
getCurrentFileName()
This is a convenience method that computes a new filename with a given
using the current WAL file-number
|
long |
getEarliestMemstoreSeqNum(byte[] encodedRegionName)
Gets the earliest unflushed sequence id in the memstore for the region.
|
long |
getEarliestMemstoreSeqNum(byte[] encodedRegionName,
byte[] familyName)
Gets the earliest unflushed sequence id in the memstore for the store.
|
long |
getFilenum() |
protected long |
getFileNumFromFileName(org.apache.hadoop.fs.Path fileName)
A log file has a creation timestamp (in ms) in its file name (
filenum . |
protected org.apache.hadoop.fs.FileStatus[] |
getFiles()
Get the backing files associated with this WAL.
|
long |
getLastTimeCheckLowReplication() |
long |
getLogFileSize() |
int |
getNumLogFiles() |
int |
getNumRolledLogFiles() |
static org.apache.hadoop.fs.Path |
getWALArchivePath(org.apache.hadoop.fs.Path archiveDir,
org.apache.hadoop.fs.Path p) |
static void |
main(String[] args)
Pass one or more log file names and it will either dump out a text version
on
stdout or split the specified log files. |
void |
registerWALActionsListener(WALActionsListener listener)
Registers WALActionsListener
|
void |
requestLogRoll() |
byte[][] |
rollWriter()
Roll the log writer.
|
byte[][] |
rollWriter(boolean force)
Roll the log writer.
|
void |
shutdown()
Stop accepting new writes.
|
Long |
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.
|
void |
sync()
Sync what we have in the WAL.
|
void |
sync(long txid)
Sync the WAL if the txId was not already sync'd.
|
String |
toString()
Human readable identifying information about the state of this WAL.
|
boolean |
unregisterWALActionsListener(WALActionsListener listener)
Unregisters WALActionsListener
|
protected final org.apache.hadoop.fs.FileSystem fs
protected final org.apache.hadoop.conf.Configuration conf
public static final long FIXED_OVERHEAD
public FSHLog(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path root, String logDir, org.apache.hadoop.conf.Configuration conf) throws IOException
fs
- filesystem handleroot
- path for stored and archived walslogDir
- dir where wals are storedconf
- configuration to useIOException
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
dir
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.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
Constructor 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 with
DefaultWALProvider.WAL_FILE_NAME_DELIMITER
IOException
public void registerWALActionsListener(WALActionsListener listener)
WAL
registerWALActionsListener
in interface WAL
public boolean unregisterWALActionsListener(WALActionsListener listener)
WAL
unregisterWALActionsListener
in interface WAL
public WALCoprocessorHost getCoprocessorHost()
getCoprocessorHost
in interface WAL
protected org.apache.hadoop.fs.FileStatus[] getFiles() throws IOException
IOException
public byte[][] rollWriter() throws FailedLogCloseException, IOException
WAL
The implementation is synchronized in order to make sure there's one rollWriter running at any given time.
rollWriter
in interface WAL
HRegionInfo.getEncodedName()
FailedLogCloseException
IOException
public byte[][] rollWriter(boolean force) throws FailedLogCloseException, IOException
WAL
The implementation is synchronized in order to make sure there's one rollWriter running at any given time.
rollWriter
in interface WAL
force
- If true, force creation of a new writer even if no entries have
been written to the current writerHRegionInfo.getEncodedName()
FailedLogCloseException
IOException
protected WALProvider.Writer createWriterInstance(org.apache.hadoop.fs.Path path) throws IOException
IOException
protected void afterCreatingZigZagLatch()
beforeWaitOnSafePoint()
protected void beforeWaitOnSafePoint()
afterCreatingZigZagLatch()
public static org.apache.hadoop.fs.Path getWALArchivePath(org.apache.hadoop.fs.Path archiveDir, org.apache.hadoop.fs.Path p)
protected org.apache.hadoop.fs.Path computeFilename(long filenum)
filenum
- to usepublic org.apache.hadoop.fs.Path getCurrentFileName()
public long getFilenum()
public String toString()
WAL
protected long getFileNumFromFileName(org.apache.hadoop.fs.Path fileName)
filenum
.
This helper method returns the creation timestamp from a given log file.
It extracts the timestamp assuming the filename is created with the
computeFilename(long filenum)
method.fileName
- public void close() throws IOException
WAL
close
in interface Closeable
close
in interface AutoCloseable
close
in interface WAL
IOException
public void shutdown() throws IOException
WAL
shutdown
in interface WAL
IOException
public long append(HTableDescriptor htd, HRegionInfo hri, WALKey key, WALEdit edits, boolean inMemstore) throws IOException
WAL
key
will
have the region edit/sequence id filled in.append
in interface WAL
htd
- used to give scope for replication TODO refactor out in favor of table name and
infokey
- 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 compaction completion
record into the WAL; in this case the entry is just so we can finish an unfinished compaction
-- it is not an edit for memstore.key
will have the region edit/sequence id
in it.IOException
public void checkLogRoll()
public void sync() throws IOException
WAL
sync
in interface WAL
IOException
public void sync(long txid) throws IOException
WAL
sync
in interface WAL
txid
- Transaction id to sync to.IOException
public void requestLogRoll()
public int getNumRolledLogFiles()
public int getNumLogFiles()
public long getLogFileSize()
public Long startCacheFlush(byte[] encodedRegionName, Set<byte[]> families)
WAL
Currently, it is expected that the update lock is held for the region; i.e. no concurrent appends while we set up cache flush.
startCacheFlush
in interface WAL
families
- Families to flush. May be a subset of all families in the region.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.WAL.completeCacheFlush(byte[])
,
WAL.abortCacheFlush(byte[])
public void completeCacheFlush(byte[] encodedRegionName)
WAL
completeCacheFlush
in interface WAL
encodedRegionName
- Encoded region name.WAL.startCacheFlush(byte[], Set)
,
WAL.abortCacheFlush(byte[])
public void abortCacheFlush(byte[] encodedRegionName)
WAL
abortCacheFlush
in interface WAL
encodedRegionName
- Encoded region name.public long getEarliestMemstoreSeqNum(byte[] encodedRegionName)
WAL
getEarliestMemstoreSeqNum
in interface WAL
encodedRegionName
- The region to get the number for.public long getEarliestMemstoreSeqNum(byte[] encodedRegionName, byte[] familyName)
WAL
getEarliestMemstoreSeqNum
in interface WAL
encodedRegionName
- The region to get the number for.familyName
- The family to get the number for.public static void main(String[] args) throws IOException
stdout
or split the specified log files.args
- IOException
public long getLastTimeCheckLowReplication()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.