public final class ZKPersStateManager
extends java.lang.Object
When a worker starts, it needs to know whether it is starting for the first time or it is restarting from failure. When starting, each worker checks whether there exists a znode for itself. If the znode exists, it means that this worker has started before.
When the job is scaled down, we delete the znodes of killed workers. This is handled by the scaler in Job Master.
Modifier and Type | Field and Description |
---|---|
static java.util.logging.Logger |
LOG |
Modifier and Type | Method and Description |
---|---|
static void |
createJobMasterPersState(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID,
java.lang.String jmAddress)
create job master persistent state at ZooKeeper server
this method must be called if isJobMasterRestarting returns false
|
static void |
createPersStateDir(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID)
Create job znode for persistent states
Assumes that there is no znode exists in the ZooKeeper
This method should be called by the submitting client
|
static void |
createWorkerPersState(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID,
WorkerInfo workerInfo)
Initialize worker persistent state at ZooKeeper server
This method must be called after making sure that
there is no pers state znode for this worker at zk
|
static java.util.LinkedList<WorkerWithState> |
getWorkers(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID)
return all registered workers
|
static WorkerWithState |
getWorkerWithState(CuratorFramework client,
java.lang.String workerFullPath) |
static WorkerWithState |
getWorkerWithState(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID,
int workerID) |
static int |
initAndGetRestartCount(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID,
WorkerInfo workerInfo)
Initialize worker persistent state at ZooKeeper server
return restart count: 0 means first start
If the worker is restarting, update restartCount and WorkerInfo
|
static void |
removeScaledDownZNodes(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID,
int minID,
int maxID)
When a job is scaled down, we must delete the znodes of killed workers.
|
static void |
updateJobMasterStatus(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID,
java.lang.String jmAddress,
JobMasterState state)
update jm status at ZK
|
static boolean |
updateWorkerStatus(CuratorFramework client,
java.lang.String rootPath,
java.lang.String jobID,
WorkerInfo workerInfo,
int restartCount,
WorkerState newStatus) |
public static void createPersStateDir(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID)
public static int initAndGetRestartCount(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID, WorkerInfo workerInfo) throws Twister2Exception
A persistent znode is created/updated for this worker on ZooKeeper server Each worker must call this method exactly once when they start
Twister2Exception
public static void createWorkerPersState(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID, WorkerInfo workerInfo) throws Twister2Exception
Twister2Exception
public static void updateJobMasterStatus(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID, java.lang.String jmAddress, JobMasterState state)
public static void createJobMasterPersState(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID, java.lang.String jmAddress)
public static void removeScaledDownZNodes(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID, int minID, int maxID) throws Twister2Exception
Twister2Exception
public static boolean updateWorkerStatus(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID, WorkerInfo workerInfo, int restartCount, WorkerState newStatus) throws Twister2Exception
Twister2Exception
public static WorkerWithState getWorkerWithState(CuratorFramework client, java.lang.String workerFullPath) throws Twister2Exception
Twister2Exception
public static WorkerWithState getWorkerWithState(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID, int workerID) throws Twister2Exception
Twister2Exception
public static java.util.LinkedList<WorkerWithState> getWorkers(CuratorFramework client, java.lang.String rootPath, java.lang.String jobID) throws Twister2Exception
Twister2Exception