Package org.apache.hadoop.hbase.wal
Class AbstractFSWALProvider<T extends AbstractFSWAL<?>>
java.lang.Object
org.apache.hadoop.hbase.wal.AbstractFSWALProvider<T>
- All Implemented Interfaces:
WALProvider
- Direct Known Subclasses:
AsyncFSWALProvider
,FSHLogProvider
@Private
@Evolving
public abstract class AbstractFSWALProvider<T extends AbstractFSWAL<?>>
extends Object
implements WALProvider
Base class of a WAL Provider that returns a single thread safe WAL that writes to Hadoop FS. By
default, this implementation picks a directory in Hadoop FS based on a combination of
- the HBase root directory
- HConstants.HREGION_LOGDIR_NAME
- the given factory's factoryId (usually identifying the regionserver by host:port)
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static class
Comparator used to compare WAL files together based on their start time.Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.wal.WALProvider
WALProvider.AsyncWriter, WALProvider.Writer, WALProvider.WriterBase
-
Field Summary
Modifier and TypeFieldDescriptionprotected Abortable
protected org.apache.hadoop.conf.Configuration
(package private) static final String
static final boolean
protected WALFactory
protected AtomicBoolean
protected List<WALActionsListener>
private static final org.slf4j.Logger
protected String
static final String
The hbase:meta region's WAL filename extensionprivate static final Pattern
Pattern used to validate a WAL file name seevalidateWALFilename(String)
for description.protected String
static final String
Separate old log into different dir by regionserver namestatic final String
File Extension used while splitting an WAL into regions (HBASE-2312)protected T
static final String
private final ReadWriteLock
We use walCreateLock to prevent wal recreation in different threads, and also prevent getWALs missing the newly created WAL, see HBASE-21503 for more details. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addWALActionsListener
(WALActionsListener listener) Add aWALActionsListener
.void
close()
shutdown utstanding WALs and clean up any persisted state.protected abstract T
protected abstract void
doInit
(org.apache.hadoop.conf.Configuration conf) static long
extractFileNumFromWAL
(WAL wal) It returns the file create timestamp from the file name.static org.apache.hadoop.fs.Path
findArchivedLog
(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) Find the archived WAL file path if it is not able to locate in WALs dir.static org.apache.hadoop.fs.Path
getCurrentFileName
(WAL wal) return the current filename from the current wal.long
iff the given WALFactory is using the DefaultWALProvider for meta and/or non-meta, count the size of files (only rolled).static long
getLogFileSize
(WAL wal) returns the size of rolled WAL files.long
iff the given WALFactory is using the DefaultWALProvider for meta and/or non-meta, count the number of files (rolled and active).static int
getNumRolledLogFiles
(WAL wal) returns the number of rolled WAL files.static ServerName
getServerNameFromWALDirectoryName
(org.apache.hadoop.conf.Configuration conf, String path) Pulls a ServerName out of a Path generated according to our layout rules.static ServerName
getServerNameFromWALDirectoryName
(org.apache.hadoop.fs.Path logFile) This function returns region server name from a log file name which is in one of the following formats: hdfs://<name node>/hbase/.logs/<server name>-splitting/... hdfs://<name node>/hbase/.logs/<server name>/...getWAL
(RegionInfo region) static String
getWALArchiveDirectoryName
(org.apache.hadoop.conf.Configuration conf, String serverName) Construct the directory name for all old WALs on a given server.static String
getWALDirectoryName
(String serverName) Construct the directory name for all WALs on a given server.static String
Get prefix of the log from its name, assuming WAL name in format of log_prefix.filenumber.log_suffixgetWALs()
Returns the List of WALs that are used by this servervoid
init
(WALFactory factory, org.apache.hadoop.conf.Configuration conf, String providerId, Abortable abortable) Set up the provider to create wals.static boolean
isArchivedLogFile
(org.apache.hadoop.fs.Path p) static boolean
isMetaFile
(String p) Returns True if String ends inMETA_WAL_PROVIDER_ID
static boolean
isMetaFile
(org.apache.hadoop.fs.Path p) static void
recoverLease
(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path path) (package private) static void
requestLogRoll
(WAL wal) request a log roll, but don't actually do it.void
shutdown()
persist outstanding WALs to storage and stop accepting new appends.static boolean
validateWALFilename
(String filename) A WAL file name is of the format: <wal-name>WAL_FILE_NAME_DELIMITER
<file-creation-timestamp>[.meta].Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.hadoop.hbase.wal.WALProvider
getWALFileLengthProvider
-
Field Details
-
LOG
-
SEPARATE_OLDLOGDIR
Separate old log into different dir by regionserver name- See Also:
-
DEFAULT_SEPARATE_OLDLOGDIR
- See Also:
-
wal
-
factory
-
conf
-
listeners
-
providerId
-
initialized
-
logPrefix
-
abortable
-
walCreateLock
We use walCreateLock to prevent wal recreation in different threads, and also prevent getWALs missing the newly created WAL, see HBASE-21503 for more details. -
WAL_FILE_NAME_DELIMITER
- See Also:
-
META_WAL_PROVIDER_ID
The hbase:meta region's WAL filename extension- See Also:
-
DEFAULT_PROVIDER_ID
- See Also:
-
SPLITTING_EXT
File Extension used while splitting an WAL into regions (HBASE-2312)- See Also:
-
pattern
Pattern used to validate a WAL file name seevalidateWALFilename(String)
for description.
-
-
Constructor Details
-
AbstractFSWALProvider
public AbstractFSWALProvider()
-
-
Method Details
-
init
public void init(WALFactory factory, org.apache.hadoop.conf.Configuration conf, String providerId, Abortable abortable) throws IOException Description copied from interface:WALProvider
Set up the provider to create wals. will only be called once per instance.- Specified by:
init
in interfaceWALProvider
- Parameters:
factory
- factory that made us, identity used for FS layout. may not be nullconf
- may not be nullproviderId
- differentiate between providers from one factory, used for FS layout. may be null- Throws:
IOException
-
getWALs
Description copied from interface:WALProvider
Returns the List of WALs that are used by this server- Specified by:
getWALs
in interfaceWALProvider
-
getWAL
- Specified by:
getWAL
in interfaceWALProvider
- Parameters:
region
- the region which we want to get a WAL for it. Could be null.- Returns:
- a WAL for writing entries for the given region.
- Throws:
IOException
-
createWAL
- Throws:
IOException
-
doInit
- Throws:
IOException
-
shutdown
Description copied from interface:WALProvider
persist outstanding WALs to storage and stop accepting new appends. This method serves as shorthand for sending a sync to every WAL provided by a given implementation. Those WALs will also stop accepting new writes.- Specified by:
shutdown
in interfaceWALProvider
- Throws:
IOException
-
close
Description copied from interface:WALProvider
shutdown utstanding WALs and clean up any persisted state. Call this method only when you will not need to replay any of the edits to the WALs from this provider. After this call completes, the underlying resources should have been reclaimed.- Specified by:
close
in interfaceWALProvider
- Throws:
IOException
-
getNumLogFiles
iff the given WALFactory is using the DefaultWALProvider for meta and/or non-meta, count the number of files (rolled and active). if either of them aren't, count 0 for that provider.- Specified by:
getNumLogFiles
in interfaceWALProvider
-
getLogFileSize
iff the given WALFactory is using the DefaultWALProvider for meta and/or non-meta, count the size of files (only rolled). if either of them aren't, count 0 for that provider.- Specified by:
getLogFileSize
in interfaceWALProvider
-
getNumRolledLogFiles
returns the number of rolled WAL files. -
getLogFileSize
returns the size of rolled WAL files. -
getCurrentFileName
return the current filename from the current wal. -
requestLogRoll
request a log roll, but don't actually do it. -
extractFileNumFromWAL
It returns the file create timestamp from the file name. For name format seevalidateWALFilename(String)
public until remaining tests move to o.a.h.h.wal- Parameters:
wal
- must not be null- Returns:
- the file number that is part of the WAL file name
-
validateWALFilename
A WAL file name is of the format: <wal-name>WAL_FILE_NAME_DELIMITER
<file-creation-timestamp>[.meta]. provider-name is usually made up of a server-name and a provider-id- Parameters:
filename
- name of the file to validate- Returns:
- true if the filename matches an WAL, false otherwise
-
getWALDirectoryName
Construct the directory name for all WALs on a given server. Dir names currently look like this for WALs:hbase//WALs/kalashnikov.att.net,61634,1486865297088
.- Parameters:
serverName
- Server name formatted as described inServerName
- Returns:
- the relative WAL directory name, e.g.
.logs/1.example.org,60030,12345
ifserverName
passed is1.example.org,60030,12345
-
getWALArchiveDirectoryName
public static String getWALArchiveDirectoryName(org.apache.hadoop.conf.Configuration conf, String serverName) Construct the directory name for all old WALs on a given server. The default old WALs dir looks like:hbase/oldWALs
. If you config hbase.separate.oldlogdir.by.regionserver to true, it looks likehbase//oldWALs/kalashnikov.att.net,61634,1486865297088
.- Parameters:
serverName
- Server name formatted as described inServerName
- Returns:
- the relative WAL directory name
-
getServerNameFromWALDirectoryName
public static ServerName getServerNameFromWALDirectoryName(org.apache.hadoop.conf.Configuration conf, String path) throws IOException Pulls a ServerName out of a Path generated according to our layout rules. In the below layouts, this method ignores the format of the logfile component. Current format: [base directory for hbase]/hbase/.logs/ServerName/logfile or [base directory for hbase]/hbase/.logs/ServerName-splitting/logfile Expected to work for individual log files and server-specific directories.- Returns:
- null if it's not a log file. Returns the ServerName of the region server that created this log file otherwise.
- Throws:
IOException
-
getServerNameFromWALDirectoryName
This function returns region server name from a log file name which is in one of the following formats:- hdfs://<name node>/hbase/.logs/<server name>-splitting/...
- hdfs://<name node>/hbase/.logs/<server name>/...
- Returns:
- null if the passed in logFile isn't a valid WAL file path
-
isMetaFile
-
isMetaFile
Returns True if String ends inMETA_WAL_PROVIDER_ID
-
isArchivedLogFile
-
findArchivedLog
public static org.apache.hadoop.fs.Path findArchivedLog(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOException Find the archived WAL file path if it is not able to locate in WALs dir.- Parameters:
path
- - active WAL file pathconf
- - configuration- Returns:
- archived path if exists, null - otherwise
- Throws:
IOException
- exception
-
recoverLease
public static void recoverLease(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path path) -
addWALActionsListener
Description copied from interface:WALProvider
Add aWALActionsListener
.Notice that you must call this method before calling
WALProvider.getWAL(RegionInfo)
as this method will not effect theWAL
which has already been created. And as long as we can only it when initialization, it is not thread safe.- Specified by:
addWALActionsListener
in interfaceWALProvider
-
getWALPrefixFromWALName
Get prefix of the log from its name, assuming WAL name in format of log_prefix.filenumber.log_suffix- Parameters:
name
- Name of the WAL to parse- Returns:
- prefix of the log
- See Also:
-