public class ZKRegistry extends Object implements TaskLifecycleListener, DrillbitStatusListener, Pollable
Locking strategy: Receives events from both ZK and the cluster controller, both of which must be synchronized. To prevent deadlocks, this class NEVER calls into the cluster controller while holding a lock. This prevents the following:
ClusterController --> ZKRegistry (OK)
ZK --> ZKRegistry (OK)
ZK --> ZKRegistry --> Cluster Controller (bad)
In the case of registration, ZK calls the registry which must alert the cluster controller. Cluster controller alerting is handled outside the ZK update critical section.
Because ZK events are occur relatively infrequently, any deadlock will occur once in a blue moon, which will make it very hard to reproduce. So, extreme caution is needed at design time to prevent the problem.
Modifier and Type | Class and Description |
---|---|
static class |
ZKRegistry.AckEvent |
protected static class |
ZKRegistry.DrillbitTracker
State of each Drillbit that we've discovered through ZK or launched via the
AM.
|
TaskLifecycleListener.Event
Modifier and Type | Field and Description |
---|---|
static String |
CONTROLLER_PROPERTY |
static String |
ENDPOINT_PROPERTY |
static int |
UPDATE_PERIOD_MS |
Constructor and Description |
---|
ZKRegistry(ZKClusterCoordinatorDriver zkDriver) |
Modifier and Type | Method and Description |
---|---|
void |
drillbitRegistered(Set<CoordinationProtos.DrillbitEndpoint> registeredDrillbits)
Callback from ZK to indicate that one or more drillbits have become
registered.
|
void |
drillbitUnregistered(Set<CoordinationProtos.DrillbitEndpoint> unregisteredDrillbits)
Callback from ZK to indicate that one or more drillbits have become
deregistered from ZK.
|
void |
finish(RegistryHandler handler) |
protected Map<String,ZKRegistry.DrillbitTracker> |
getRegistryForTesting()
Get the current registry for testing.
|
boolean |
isRegistered(Task task)
Report whether the given task is still registered in ZK.
|
List<String> |
listUnmanagedDrillits() |
void |
start(RegistryHandler controller)
Called during AM startup to initialize ZK.
|
void |
stateChange(TaskLifecycleListener.Event event,
EventContext context)
Listen for selected YARN task state changes.
|
void |
tick(long curTime)
Periodically check ZK status.
|
public static final String CONTROLLER_PROPERTY
public static final int UPDATE_PERIOD_MS
public static final String ENDPOINT_PROPERTY
public ZKRegistry(ZKClusterCoordinatorDriver zkDriver)
public void start(RegistryHandler controller)
public void drillbitRegistered(Set<CoordinationProtos.DrillbitEndpoint> registeredDrillbits)
drillbitRegistered
in interface DrillbitStatusListener
registeredDrillbits
- the set of newly registered drillbits. Note: the complete set of currently registered bits could be different.public void drillbitUnregistered(Set<CoordinationProtos.DrillbitEndpoint> unregisteredDrillbits)
drillbitUnregistered
in interface DrillbitStatusListener
unregisteredDrillbits
- the set of newly unregistered drillbits.public void stateChange(TaskLifecycleListener.Event event, EventContext context)
stateChange
in interface TaskLifecycleListener
public boolean isRegistered(Task task)
task
- public void tick(long curTime)
This method should not be synchronized. It checks only the ZK state, not internal state. Further, if we do reconnect to ZK, then a ZK thread may attempt to update this registry, which will acquire a synchronization lock.
public void finish(RegistryHandler handler)
protected Map<String,ZKRegistry.DrillbitTracker> getRegistryForTesting()
Copyright © 1970 The Apache Software Foundation. All rights reserved.