public class RaftLifecycle
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
RaftLifecycle.Builder
A builder for a lifecycle.
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
allowCriticalSections
If false, throw an exception rather than entering the critical section.
|
java.util.concurrent.atomic.AtomicBoolean |
CORE_THREAD_POOLS_CLOSED
This indicates when we have closed the core thread pools, one of the last steps right before shutdown.
|
protected java.util.Map<java.lang.String,java.util.concurrent.ExecutorService> |
coreThreadPools
The set of managed thread pools, which run core system-level things (e.g., Rabbit or the DB connections).
|
protected java.util.Set<java.util.concurrent.locks.ReentrantLock> |
criticalSections
A lock we can take to prevent the system from shutting down.
|
static RaftLifecycle |
global |
java.util.concurrent.atomic.AtomicBoolean |
IS_READY
The indicator for whether our web server is accepting new requests.
|
java.util.concurrent.atomic.AtomicBoolean |
IS_SHUTTING_DOWN
This indicator gets set when we are shutting down, and should not allow new requests to proceed.
|
protected java.util.Map<java.lang.String,java.util.concurrent.ExecutorService> |
managedThreadPools
The set of managed thread pools
|
protected java.util.Optional<EloquentRaftNode> |
registeredRaft
This is the Theseus that's tied to this RaftLifecycle - if any.
|
java.util.concurrent.atomic.AtomicBoolean |
SHUTDOWN_BEGIN
This indicates when we have started a shutdown.
|
protected IdentityHashSet<java.lang.Runnable> |
shutdownHooks
The set of shutdown hooks we should run on shutdown, once we are no longer receiving traffic
|
static int |
STATUS_FAILURE_THRESHOLD
The number of readiness checks we have to fail for us to be considered dead by Kuberneters.
|
static int |
STATUS_PERIOD_SEC
The interval in which liveness and readiness checks are sent to our server.
|
static int |
STATUS_TIMEOUT_SEC
The timeout on the ready endpoint.
|
Lazy<SafeTimer> |
timer
A global timer that we can use.
|
| Constructor and Description |
|---|
RaftLifecycle(Lazy<SafeTimer> timer) |
| Modifier and Type | Method and Description |
|---|---|
java.util.concurrent.ExecutorService |
managedThreadPool(int numThreads,
java.lang.String threadPrefix) |
java.util.concurrent.ExecutorService |
managedThreadPool(int numThreads,
java.lang.String threadPrefix,
boolean core) |
java.util.concurrent.ExecutorService |
managedThreadPool(int numThreads,
java.lang.String threadPrefix,
boolean core,
int priority)
Create a thread pool that closes itself on program shutdown.
|
java.util.concurrent.ExecutorService |
managedThreadPool(int numThreads,
java.lang.String threadPrefix,
int priority) |
java.util.concurrent.ExecutorService |
managedThreadPool(java.lang.String threadPrefix)
Create a managed cached thread pool.
|
java.util.concurrent.ExecutorService |
managedThreadPool(java.lang.String threadPrefix,
boolean core) |
java.util.concurrent.ExecutorService |
managedThreadPool(java.lang.String threadPrefix,
boolean core,
int priority)
Create a managed cached thread pool.
|
java.util.concurrent.ExecutorService |
managedThreadPool(java.lang.String threadPrefix,
int priority)
Create a managed cached thread pool with a given priority.
|
static RaftLifecycle.Builder |
newBuilder()
Create a new lifecycle builder.
|
void |
registerRaft(EloquentRaftNode raft)
This registers Raft on this RaftLifecycle, so that the RaftLifecycle can shut it down when it's ready.
|
void |
shutdown(boolean allowClusterDeath)
This is called from the shutdown hooks, but also can be called from within tests to simulate a shutdown for a
single EloquentLifecycle
|
protected void |
stopPool(java.util.Collection<java.util.concurrent.ExecutorService> pool)
Shut down a thread pool collection.
|
public static RaftLifecycle global
protected final java.util.Map<java.lang.String,java.util.concurrent.ExecutorService> managedThreadPools
protected final java.util.Map<java.lang.String,java.util.concurrent.ExecutorService> coreThreadPools
protected java.util.Optional<EloquentRaftNode> registeredRaft
protected final IdentityHashSet<java.lang.Runnable> shutdownHooks
public final java.util.concurrent.atomic.AtomicBoolean IS_READY
public final java.util.concurrent.atomic.AtomicBoolean IS_SHUTTING_DOWN
IS_READY, in that Kubernetes can send new requests
between when IS_READY is marked false, and when its timeout on readiness checks
expires.
In contrast, this variable is only set once Kubernetes should no longer be sending us new requests.
Any new requests that are sent should be considered to be an error.public final java.util.concurrent.atomic.AtomicBoolean SHUTDOWN_BEGIN
IS_READY (indicating the Kubernetes readiness state),
and IS_SHUTTING_DOWN (indicating that readiness is down and we'republic final java.util.concurrent.atomic.AtomicBoolean CORE_THREAD_POOLS_CLOSED
public static final int STATUS_PERIOD_SEC
public static final int STATUS_FAILURE_THRESHOLD
public static final int STATUS_TIMEOUT_SEC
protected final java.util.Set<java.util.concurrent.locks.ReentrantLock> criticalSections
protected boolean allowCriticalSections
public static RaftLifecycle.Builder newBuilder()
public void registerRaft(EloquentRaftNode raft)
public java.util.concurrent.ExecutorService managedThreadPool(int numThreads,
java.lang.String threadPrefix,
boolean core,
int priority)
numThreads - The number of threads to allocate in the poolthreadPrefix - When naming threads, use this prefix to identify threads in this pool vs. other pools.core - If true, this is a core system thread pool. Core thread pools are shut down after Rabbit and the database close,
whereas non-core thread pools close with Rabbit and the database still open.priority - The priority of the threads scheduled on this pool.public java.util.concurrent.ExecutorService managedThreadPool(int numThreads,
java.lang.String threadPrefix,
boolean core)
public java.util.concurrent.ExecutorService managedThreadPool(int numThreads,
java.lang.String threadPrefix,
int priority)
public java.util.concurrent.ExecutorService managedThreadPool(int numThreads,
java.lang.String threadPrefix)
managedThreadPool(int, String, boolean)public java.util.concurrent.ExecutorService managedThreadPool(java.lang.String threadPrefix,
boolean core,
int priority)
threadPrefix - The prefix to apply to all the threads in the poolcore - If true, this is a core system thread pool. Core thread pools are shut down after Rabbit and the database close,
whereas non-core thread pools close with Rabbit and the database still open.priority - The priority of the threads scheduled on this pool.public java.util.concurrent.ExecutorService managedThreadPool(java.lang.String threadPrefix,
boolean core)
managedThreadPool(String, boolean, int)public java.util.concurrent.ExecutorService managedThreadPool(java.lang.String threadPrefix)
threadPrefix - The prefix to apply to all the threads in the poolpublic java.util.concurrent.ExecutorService managedThreadPool(java.lang.String threadPrefix,
int priority)
threadPrefix - The prefix to apply to all the threads in the poolpriority - The priority of the threads scheduled on this pool.public void shutdown(boolean allowClusterDeath)
allowClusterDeath - If true, allow the Raft cluster to lose state and completely shut down.
Otherwise, we wait for another live node to show up before shutting
down (the default).protected void stopPool(java.util.Collection<java.util.concurrent.ExecutorService> pool)
managedThreadPools and
coreThreadPools.pool - The thread pool collection to stop.