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
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic classComparator 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
FieldsModifier and TypeFieldDescriptionprotected Abortableprotected org.apache.hadoop.conf.Configuration(package private) static final Stringstatic final booleanprotected WALFactoryprotected AtomicBooleanprotected List<WALActionsListener>private static final org.slf4j.Loggerprotected Stringstatic final StringThe hbase:meta region's WAL filename extensionprivate static final PatternPattern used to validate a WAL file name seevalidateWALFilename(String)for description.protected Stringstatic final StringSeparate old log into different dir by regionserver namestatic final StringFile Extension used while splitting an WAL into regions (HBASE-2312)protected Tstatic final Stringprivate final ReadWriteLockWe 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddWALActionsListener(WALActionsListener listener) Add aWALActionsListener.voidclose()shutdown utstanding WALs and clean up any persisted state.protected abstract Tprotected abstract voiddoInit(org.apache.hadoop.conf.Configuration conf) static longextractFileNumFromWAL(WAL wal) It returns the file create timestamp from the file name.static org.apache.hadoop.fs.PathfindArchivedLog(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.PathgetCurrentFileName(WAL wal) return the current filename from the current wal.longiff the given WALFactory is using the DefaultWALProvider for meta and/or non-meta, count the size of files (only rolled).static longgetLogFileSize(WAL wal) returns the size of rolled WAL files.longiff the given WALFactory is using the DefaultWALProvider for meta and/or non-meta, count the number of files (rolled and active).static intgetNumRolledLogFiles(WAL wal) returns the number of rolled WAL files.static ServerNamegetServerNameFromWALDirectoryName(org.apache.hadoop.conf.Configuration conf, String path) Pulls a ServerName out of a Path generated according to our layout rules.static ServerNamegetServerNameFromWALDirectoryName(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 StringgetWALArchiveDirectoryName(org.apache.hadoop.conf.Configuration conf, String serverName) Construct the directory name for all old WALs on a given server.static StringgetWALDirectoryName(String serverName) Construct the directory name for all WALs on a given server.static StringGet 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 servervoidinit(WALFactory factory, org.apache.hadoop.conf.Configuration conf, String providerId, Abortable abortable) Set up the provider to create wals.static booleanisArchivedLogFile(org.apache.hadoop.fs.Path p) static booleanisMetaFile(String p) Returns True if String ends inMETA_WAL_PROVIDER_IDstatic booleanisMetaFile(org.apache.hadoop.fs.Path p) static voidrecoverLease(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path path) (package private) static voidrequestLogRoll(WAL wal) request a log roll, but don't actually do it.voidshutdown()persist outstanding WALs to storage and stop accepting new appends.static booleanvalidateWALFilename(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, waitMethods 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:WALProviderSet up the provider to create wals. will only be called once per instance.- Specified by:
initin 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:WALProviderReturns the List of WALs that are used by this server- Specified by:
getWALsin interfaceWALProvider
-
getWAL
- Specified by:
getWALin 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:WALProviderpersist 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:
shutdownin interfaceWALProvider- Throws:
IOException
-
close
Description copied from interface:WALProvidershutdown 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:
closein 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:
getNumLogFilesin 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:
getLogFileSizein 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,12345ifserverNamepassed 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:WALProviderAdd aWALActionsListener.Notice that you must call this method before calling
WALProvider.getWAL(RegionInfo)as this method will not effect theWALwhich has already been created. And as long as we can only it when initialization, it is not thread safe.- Specified by:
addWALActionsListenerin 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:
-