@InterfaceAudience.Private public abstract class AbstractWALProvider extends Object implements WALProvider, PeerActionListener
We will put some common logic here, especially for sync replication implementation, as it must do some hacks before the normal wal creation operation.
All WALProvider
implementations should extends this class instead of implement
WALProvider
directly, except DisabledWALProvider
.
WALProvider.AsyncWriter, WALProvider.Writer, WALProvider.WriterBase
Modifier and Type | Field and Description |
---|---|
protected Abortable |
abortable |
protected org.apache.hadoop.conf.Configuration |
conf |
private KeyLocker<String> |
createLock |
protected WALFactory |
factory |
protected AtomicBoolean |
initialized |
protected List<WALActionsListener> |
listeners |
private static org.slf4j.Logger |
LOG |
private static Pattern |
LOG_PREFIX_PATTERN |
protected String |
logPrefix |
private Condition |
noRemoteWALUnderCreationCond |
private int |
numRemoteWALUnderCreation |
private Lock |
numRemoteWALUnderCreationLock |
private ConcurrentMap<String,Optional<WAL>> |
peerId2WAL |
private SyncReplicationPeerInfoProvider |
peerInfoProvider |
protected String |
providerId |
static String |
WAL_FILE_NAME_DELIMITER |
DUMMY
Constructor and Description |
---|
AbstractWALProvider() |
Modifier and Type | Method and Description |
---|---|
void |
addWALActionsListener(WALActionsListener listener)
Add a
WALActionsListener . |
private void |
cleanup(IOExceptionConsumer<WAL> cleanupWAL,
IOExceptionRunnable finalCleanup) |
void |
close()
shutdown utstanding WALs and clean up any persisted state.
|
protected abstract void |
close0() |
protected abstract WAL |
createRemoteWAL(RegionInfo region,
org.apache.hadoop.fs.FileSystem remoteFs,
org.apache.hadoop.fs.Path remoteWALDir,
String prefix,
String suffix) |
protected abstract void |
doInit(WALFactory factory,
org.apache.hadoop.conf.Configuration conf,
String providerId) |
long |
getLogFileSize()
Get size of the log files this provider is managing
|
protected abstract long |
getLogFileSize0() |
long |
getNumLogFiles()
Get number of the log files this provider is managing
|
protected abstract long |
getNumLogFiles0() |
PeerActionListener |
getPeerActionListener() |
private WAL |
getRemoteWAL(RegionInfo region,
String peerId,
String remoteWALDir) |
private String |
getRemoteWALPrefix(String peerId) |
static Optional<String> |
getSyncReplicationPeerIdFromWALName(String name)
Returns the peer id if the wal file name is in the special group for a sync replication peer.
|
WAL |
getWAL(RegionInfo region) |
protected abstract WAL |
getWAL0(RegionInfo region) |
List<WAL> |
getWALs()
Returns the List of WALs that are used by this server
|
protected abstract List<WAL> |
getWALs0() |
void |
init(WALFactory factory,
org.apache.hadoop.conf.Configuration conf,
String providerId,
Abortable server)
Set up the provider to create wals.
|
protected void |
initWAL(WAL wal) |
void |
peerSyncReplicationStateChange(String peerId,
SyncReplicationState from,
SyncReplicationState to,
int stage) |
private Stream<AbstractFSWAL<?>> |
remoteWALStream() |
private static void |
safeClose(WAL wal) |
void |
setSyncReplicationPeerInfoProvider(SyncReplicationPeerInfoProvider provider) |
void |
shutdown()
persist outstanding WALs to storage and stop accepting new appends.
|
protected abstract void |
shutdown0() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getWALFileLengthProvider
private static final org.slf4j.Logger LOG
public static final String WAL_FILE_NAME_DELIMITER
protected WALFactory factory
protected org.apache.hadoop.conf.Configuration conf
protected List<WALActionsListener> listeners
protected String providerId
protected AtomicBoolean initialized
private final ConcurrentMap<String,Optional<WAL>> peerId2WAL
private final KeyLocker<String> createLock
private final Lock numRemoteWALUnderCreationLock
private final Condition noRemoteWALUnderCreationCond
private int numRemoteWALUnderCreation
private SyncReplicationPeerInfoProvider peerInfoProvider
private static final Pattern LOG_PREFIX_PATTERN
public AbstractWALProvider()
public final void init(WALFactory factory, org.apache.hadoop.conf.Configuration conf, String providerId, Abortable server) throws IOException
WALProvider
init
in interface WALProvider
factory
- factory that made us may not be nullconf
- may not be nullproviderId
- differentiate between providers from one factory. may be nullIOException
protected final void initWAL(WAL wal) throws IOException
IOException
private String getRemoteWALPrefix(String peerId)
private WAL getRemoteWAL(RegionInfo region, String peerId, String remoteWALDir) throws IOException
IOException
public final WAL getWAL(RegionInfo region) throws IOException
getWAL
in interface WALProvider
region
- the region which we want to get a WAL for it. Could be null.IOException
public final List<WAL> getWALs()
WALProvider
getWALs
in interface WALProvider
public PeerActionListener getPeerActionListener()
getPeerActionListener
in interface WALProvider
public void peerSyncReplicationStateChange(String peerId, SyncReplicationState from, SyncReplicationState to, int stage)
peerSyncReplicationStateChange
in interface PeerActionListener
public void setSyncReplicationPeerInfoProvider(SyncReplicationPeerInfoProvider provider)
setSyncReplicationPeerInfoProvider
in interface WALProvider
public void addWALActionsListener(WALActionsListener listener)
WALProvider
WALActionsListener
.
Notice that you must call this method before calling WALProvider.getWAL(RegionInfo)
as this method
will not effect the WAL
which has already been created. And as long as we can only it
when initialization, it is not thread safe.
addWALActionsListener
in interface WALProvider
private void cleanup(IOExceptionConsumer<WAL> cleanupWAL, IOExceptionRunnable finalCleanup) throws IOException
IOException
public final void shutdown() throws IOException
WALProvider
shutdown
in interface WALProvider
IOException
public final void close() throws IOException
WALProvider
close
in interface WALProvider
IOException
private Stream<AbstractFSWAL<?>> remoteWALStream()
public final long getNumLogFiles()
WALProvider
getNumLogFiles
in interface WALProvider
public final long getLogFileSize()
WALProvider
getLogFileSize
in interface WALProvider
public static Optional<String> getSyncReplicationPeerIdFromWALName(String name)
Returns the peer id if the wal file name is in the special group for a sync replication peer.
The prefix format is <factoryId>-<ts>-<peerId>.
protected abstract WAL createRemoteWAL(RegionInfo region, org.apache.hadoop.fs.FileSystem remoteFs, org.apache.hadoop.fs.Path remoteWALDir, String prefix, String suffix) throws IOException
IOException
protected abstract void doInit(WALFactory factory, org.apache.hadoop.conf.Configuration conf, String providerId) throws IOException
IOException
protected abstract WAL getWAL0(RegionInfo region) throws IOException
IOException
protected abstract void shutdown0() throws IOException
IOException
protected abstract void close0() throws IOException
IOException
protected abstract long getNumLogFiles0()
protected abstract long getLogFileSize0()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.