@InterfaceAudience.Private public class WALProcedureStore extends ProcedureStoreBase
start(int), then recoverLease(),
then ProcedureStore.load(ProcedureLoader).
In recoverLease(), we will get the lease by closing all the existing wal files(by
calling recoverFileLease), and creating a new wal writer. And we will also get the list of all
the old wal files.
FIXME: notice that the current recover lease implementation is problematic, it can not deal with
the races if there are two master both wants to acquire the lease...
In ProcedureStore.load(ProcedureLoader) method, we will load all the active procedures. See the
comments of this method for more details.
The actual logging way is a bit like our FileSystem based WAL implementation as RS side. There is
a slots, which is more like the ring buffer, and in the insert, update and delete
methods we will put thing into the slots and wait. And there is a background sync
thread(see the syncLoop() method) which get data from the slots and write them
to the FileSystem, and notify the caller that we have finished.
TODO: try using disruptor to increase performance and simplify the logic?
The storeTracker keeps track of the modified procedures in the newest wal file, which is
also the one being written currently. And the deleted bits in it are for all the procedures, not
only the ones in the newest wal file. And when rolling a log, we will first store it in the
trailer of the current wal file, and then reset its modified bits, so that it can start to track
the modified procedures for the new wal file.
The holdingCleanupTracker is used to test whether we are safe to delete the oldest wal
file. When there are log rolling and there are more than 1 wal files, we will make use of it. It
will first be initialized to the oldest file's tracker(which is stored in the trailer), using the
method ProcedureStoreTracker.resetTo(ProcedureStoreTracker, boolean), and then merge it
with the tracker of every newer wal files, using the
ProcedureStoreTracker.setDeletedIfModifiedInBoth(ProcedureStoreTracker).
If we find out
that all the modified procedures for the oldest wal file are modified or deleted in newer wal
files, then we can delete it. This is because that, every time we call
ProcedureStore.insert(Procedure[]) or ProcedureStore.update(Procedure), we will
persist the full state of a Procedure, so the earlier wal records for this procedure can all be
deleted.| Modifier and Type | Class and Description |
|---|---|
static interface |
WALProcedureStore.LeaseRecovery |
static class |
WALProcedureStore.SyncMetrics |
ProcedureStore.ProcedureIterator, ProcedureStore.ProcedureLoader, ProcedureStore.ProcedureStoreListener| Modifier and Type | Field and Description |
|---|---|
static String |
EXEC_WAL_CLEANUP_ON_LOAD_CONF_KEY |
static String |
LOG_PREFIX |
static String |
MASTER_PROCEDURE_LOGDIR
Used to construct the name of the log directory for master procedures
|
static String |
MAX_RETRIES_BEFORE_ROLL_CONF_KEY |
static String |
MAX_SYNC_FAILURE_ROLL_CONF_KEY |
static String |
PERIODIC_ROLL_CONF_KEY |
static String |
ROLL_RETRIES_CONF_KEY |
static String |
ROLL_THRESHOLD_CONF_KEY |
static String |
STORE_WAL_SYNC_STATS_COUNT |
static String |
SYNC_WAIT_MSEC_CONF_KEY |
static String |
USE_HSYNC_CONF_KEY |
static String |
WAIT_BEFORE_ROLL_CONF_KEY |
static String |
WAL_COUNT_WARN_THRESHOLD_CONF_KEY |
| Constructor and Description |
|---|
WALProcedureStore(org.apache.hadoop.conf.Configuration conf,
org.apache.hadoop.fs.Path walDir,
org.apache.hadoop.fs.Path walArchiveDir,
WALProcedureStore.LeaseRecovery leaseRecovery) |
WALProcedureStore(org.apache.hadoop.conf.Configuration conf,
WALProcedureStore.LeaseRecovery leaseRecovery) |
| Modifier and Type | Method and Description |
|---|---|
void |
delete(long procId)
The specified procId was removed from the executor,
due to completion, abort or failure.
|
void |
delete(long[] procIds,
int offset,
int count)
The specified procIds were removed from the executor,
due to completion, abort or failure.
|
void |
delete(Procedure<?> proc,
long[] subProcIds)
The parent procedure completed.
|
ArrayList<ProcedureWALFile> |
getActiveLogs() |
Set<ProcedureWALFile> |
getCorruptedLogs() |
org.apache.hadoop.fs.FileSystem |
getFileSystem() |
protected org.apache.hadoop.fs.Path |
getLogFilePath(long logId) |
long |
getMillisFromLastRoll() |
long |
getMillisToNextPeriodicRoll() |
int |
getNumThreads() |
ProcedureStoreTracker |
getStoreTracker() |
ArrayList<WALProcedureStore.SyncMetrics> |
getSyncMetrics() |
org.apache.hadoop.fs.Path |
getWALDir() |
void |
insert(Procedure<?>[] procs)
Serialize a set of new procedures.
|
void |
insert(Procedure<?> proc,
Procedure<?>[] subprocs)
When a procedure is submitted to the executor insert(proc, null) will be called.
|
void |
load(ProcedureStore.ProcedureLoader loader)
Load the Procedures in the store.
|
static void |
main(String[] args)
Parses a directory of WALs building up ProcedureState.
|
void |
recoverLease()
Acquire the lease for the procedure store.
|
boolean |
rollWriterForTesting() |
int |
setRunningProcedureCount(int count)
Set the number of procedure running.
|
void |
start(int numSlots)
Start/Open the procedure store
|
void |
stop(boolean abort)
Stop/Close the procedure store
|
protected long |
syncSlots(org.apache.hadoop.fs.FSDataOutputStream stream,
ByteSlot[] slots,
int offset,
int count) |
protected void |
syncStream(org.apache.hadoop.fs.FSDataOutputStream stream) |
void |
update(Procedure<?> proc)
The specified procedure was executed,
and the new state should be written to the store.
|
isRunning, registerListener, sendAbortProcessSignal, sendForceUpdateSignal, sendPostSyncSignal, setRunning, unregisterListenerpublic static final String LOG_PREFIX
public static final String MASTER_PROCEDURE_LOGDIR
public static final String WAL_COUNT_WARN_THRESHOLD_CONF_KEY
public static final String EXEC_WAL_CLEANUP_ON_LOAD_CONF_KEY
public static final String MAX_RETRIES_BEFORE_ROLL_CONF_KEY
public static final String WAIT_BEFORE_ROLL_CONF_KEY
public static final String ROLL_RETRIES_CONF_KEY
public static final String MAX_SYNC_FAILURE_ROLL_CONF_KEY
public static final String PERIODIC_ROLL_CONF_KEY
public static final String SYNC_WAIT_MSEC_CONF_KEY
public static final String USE_HSYNC_CONF_KEY
public static final String ROLL_THRESHOLD_CONF_KEY
public static final String STORE_WAL_SYNC_STATS_COUNT
public WALProcedureStore(org.apache.hadoop.conf.Configuration conf,
WALProcedureStore.LeaseRecovery leaseRecovery)
throws IOException
IOExceptionpublic WALProcedureStore(org.apache.hadoop.conf.Configuration conf,
org.apache.hadoop.fs.Path walDir,
org.apache.hadoop.fs.Path walArchiveDir,
WALProcedureStore.LeaseRecovery leaseRecovery)
throws IOException
IOExceptionpublic void start(int numSlots)
throws IOException
ProcedureStorenumSlots - number of threads to be used by the procedure storeIOExceptionpublic void stop(boolean abort)
ProcedureStoreabort - true if the stop is an abortpublic int getNumThreads()
public int setRunningProcedureCount(int count)
ProcedureStorecount).public ProcedureStoreTracker getStoreTracker()
public ArrayList<ProcedureWALFile> getActiveLogs()
public Set<ProcedureWALFile> getCorruptedLogs()
public void recoverLease()
throws IOException
ProcedureStoreIOExceptionpublic void load(ProcedureStore.ProcedureLoader loader) throws IOException
ProcedureStoreloader - the ProcedureLoader that will handle the store-load eventsIOExceptionpublic void insert(Procedure<?> proc, Procedure<?>[] subprocs)
ProcedureStoreproc - the procedure to serialize and write to the store.subprocs - the newly created child of the proc.public void insert(Procedure<?>[] procs)
ProcedureStoreprocs - the procedures to serialize and write to the store.public void update(Procedure<?> proc)
ProcedureStoreproc - the procedure to serialize and write to the store.public void delete(long procId)
ProcedureStoreprocId - the ID of the procedure to remove.public void delete(Procedure<?> proc, long[] subProcIds)
ProcedureStoreproc - the parent procedure to serialize and write to the store.subProcIds - the IDs of the sub-procedure to remove.public void delete(long[] procIds,
int offset,
int count)
ProcedureStoreprocIds - the IDs of the procedures to remove.offset - the array offset from where to start to deletecount - the number of IDs to deletepublic ArrayList<WALProcedureStore.SyncMetrics> getSyncMetrics()
protected long syncSlots(org.apache.hadoop.fs.FSDataOutputStream stream,
ByteSlot[] slots,
int offset,
int count)
throws IOException
IOExceptionprotected void syncStream(org.apache.hadoop.fs.FSDataOutputStream stream)
throws IOException
IOExceptionpublic long getMillisToNextPeriodicRoll()
public long getMillisFromLastRoll()
public boolean rollWriterForTesting()
throws IOException
IOExceptionpublic org.apache.hadoop.fs.Path getWALDir()
public org.apache.hadoop.fs.FileSystem getFileSystem()
protected org.apache.hadoop.fs.Path getLogFilePath(long logId)
throws IOException
IOExceptionpublic static void main(String[] args) throws IOException
args - Include pointer to directory of WAL files for a store instance to parse & load.IOExceptionCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.